From 56b22bd6b9e2a70a133be2f2f09a12639884e950 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 13 Nov 2025 17:39:19 +0000 Subject: [PATCH 1/2] feat: complete repository reorganization and enhancement This is a complete rewrite and reorganization of the Elixir Stopwatch project, transforming it from a simple script into a professional, feature-rich application with proper project structure. Major Changes: - Converted from single script (stopwatch.exs) to full Mix project - Created modular architecture with separation of concerns - Added comprehensive test suite with high coverage - Enhanced functionality with pause/resume and lap timing - Implemented multiple time display formats - Created rich, color-coded CLI interface with real-time display - Added complete documentation and examples New Modules: - Stopwatch: Core module with state management, lap tracking, and history - Stopwatch.Formatter: Flexible time formatting utilities - Stopwatch.CLI: Interactive command-line interface Features Added: - High-precision timing using monotonic time - Pause/resume functionality with accurate time accounting - Lap timing with statistics (fastest, slowest, average) - Multiple display formats (short, long, compact, verbose) - Event history tracking - Comprehensive error handling - Escript configuration for standalone executable Documentation: - Detailed README with usage examples and API documentation - CHANGELOG for version tracking - CONTRIBUTING guidelines for developers - Inline documentation with @doc and @moduledoc - Type specifications for better IDE support Testing: - Comprehensive test suite for core stopwatch functionality - Formatter tests with multiple scenarios - Test helper setup Project Infrastructure: - Proper mix.exs configuration - Enhanced .gitignore for Mix projects - MIT License maintained Breaking Changes: - Replaced simple script with Mix project structure - New command-line interface (backward incompatible) - Programmatic API completely redesigned --- .gitignore | 39 +++- CHANGELOG.md | 96 +++++++++ CONTRIBUTING.md | 334 ++++++++++++++++++++++++++++++ README.md | 306 +++++++++++++++++++++++++++ lib/stopwatch.ex | 312 ++++++++++++++++++++++++++++ lib/stopwatch/cli.ex | 260 +++++++++++++++++++++++ lib/stopwatch/formatter.ex | 166 +++++++++++++++ mix.exs | 59 ++++++ stopwatch.exs | 38 ---- test/stopwatch/formatter_test.exs | 136 ++++++++++++ test/stopwatch_test.exs | 269 ++++++++++++++++++++++++ test/test_helper.exs | 1 + 12 files changed, 1973 insertions(+), 43 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md create mode 100644 README.md create mode 100644 lib/stopwatch.ex create mode 100644 lib/stopwatch/cli.ex create mode 100644 lib/stopwatch/formatter.ex create mode 100644 mix.exs delete mode 100644 stopwatch.exs create mode 100644 test/stopwatch/formatter_test.exs create mode 100644 test/stopwatch_test.exs create mode 100644 test/test_helper.exs diff --git a/.gitignore b/.gitignore index b263cd1..28f215b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,39 @@ +# Mix artifacts /_build -/cover /deps -/doc -/.fetch +/*.ez + +# Generate on crash by the VM erl_crash.dump -*.ez -*.beam + +# Static artifacts +/doc + +# Code coverage +/cover + +# Environment files /config/*.secret.exs +.env +.env.* + +# Temporary files +*.swp +*.swo +*~ +.DS_Store + +# Editor/IDE files .elixir_ls/ +.vscode/ +.idea/ +*.iml + +# Build artifacts +/stopwatch + +# Logs +*.log + +# OS generated files +Thumbs.db diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b69fc08 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,96 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.0.0] - 2025-11-13 + +### Added +- Complete rewrite and reorganization of the project structure +- Proper Mix project configuration with `mix.exs` +- Core `Stopwatch` module with comprehensive state management + - Start/stop functionality + - Pause/resume capability + - Lap timing with cumulative tracking + - Event history tracking + - High-precision timing using monotonic time +- `Stopwatch.Formatter` module for flexible time display + - Multiple format options: short, long, compact, verbose + - Lap table formatting + - Time component breakdown utilities +- `Stopwatch.CLI` module with rich interactive interface + - Color-coded status indicators + - Real-time elapsed time display + - Lap statistics (fastest, slowest, average) + - User-friendly command system +- Comprehensive test suite + - Core stopwatch functionality tests + - Formatter tests with multiple scenarios + - Test coverage for all major features +- Documentation + - Detailed README with examples and usage guide + - Inline documentation with @doc and @moduledoc + - Type specifications for better IDE support + - CHANGELOG for version tracking + - CONTRIBUTING guidelines +- Project infrastructure + - Proper `.gitignore` for Mix projects + - MIT License + - Escript configuration for standalone executable + +### Changed +- Migrated from simple script (`stopwatch.exs`) to full Mix project structure +- Improved time accuracy using monotonic time instead of system time +- Enhanced user experience with better formatting and colors + +### Technical Details +- Minimum Elixir version: 1.14 +- Uses system monotonic time for accuracy +- Modular architecture with separation of concerns +- Functional programming patterns throughout +- Comprehensive error handling with tagged tuples + +## [0.1.0] - 2025-11-13 (Initial Version) + +### Added +- Initial simple stopwatch script +- Basic start/stop functionality +- Simple command-line interface +- Time display in seconds + +--- + +## Release Notes + +### v1.0.0 - Major Enhancement Release + +This release represents a complete overhaul of the Elixir Stopwatch project, transforming it from a simple script into a professional, feature-rich application with a proper project structure. + +**Highlights:** +- Full Mix project with proper dependency management +- Comprehensive test coverage ensuring reliability +- Multiple time formatting options for different use cases +- Pause/resume functionality for flexible timing +- Lap timing with detailed statistics +- Beautiful, color-coded CLI interface +- Complete documentation and examples + +**Migration Notes:** +If upgrading from the original script version (0.1.0), you'll need to: +1. Run `mix deps.get` to install dependencies +2. Build the escript with `mix escript.build` +3. Use `./stopwatch` to run the application + +**Breaking Changes:** +- The application now requires a proper Mix project setup +- Direct script execution is replaced with escript binary +- API has been completely redesigned (for programmatic use) + +**Future Plans:** +- Add configuration file support +- Implement named timers +- Add export functionality (CSV, JSON) +- Create a web interface option +- Add sound alerts for lap/stop events diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..66f9757 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,334 @@ +# Contributing to Elixir Stopwatch + +First off, thank you for considering contributing to Elixir Stopwatch! It's people like you that make this tool better for everyone. + +## Code of Conduct + +This project and everyone participating in it is governed by mutual respect and professionalism. By participating, you are expected to uphold this standard. + +## How Can I Contribute? + +### Reporting Bugs + +Before creating bug reports, please check the existing issues to avoid duplicates. When you create a bug report, include as many details as possible: + +- **Use a clear and descriptive title** +- **Describe the exact steps to reproduce the problem** +- **Provide specific examples** - Include code samples, command-line output, or screenshots +- **Describe the behavior you observed** and what behavior you expected to see +- **Include details about your environment**: + - Elixir version (`elixir --version`) + - Erlang/OTP version + - Operating system and version + +### Suggesting Enhancements + +Enhancement suggestions are tracked as GitHub issues. When creating an enhancement suggestion, include: + +- **A clear and descriptive title** +- **A detailed description of the proposed functionality** +- **Examples of how the enhancement would be used** +- **Why this enhancement would be useful** to most users + +### Pull Requests + +1. Fork the repository and create your branch from `main` +2. If you've added code that should be tested, add tests +3. If you've changed APIs, update the documentation +4. Ensure the test suite passes +5. Make sure your code follows the existing style +6. Write a clear commit message + +## Development Setup + +### Prerequisites + +- Elixir 1.14 or higher +- Erlang/OTP 24 or higher +- Git + +### Setting Up Your Environment + +1. Fork and clone the repository: + ```bash + git clone https://github.com/your-username/elixir-stopwatch.git + cd elixir-stopwatch + ``` + +2. Install dependencies: + ```bash + mix deps.get + ``` + +3. Run tests to ensure everything works: + ```bash + mix test + ``` + +4. Build the escript: + ```bash + mix escript.build + ``` + +## Development Workflow + +### Running Tests + +```bash +# Run all tests +mix test + +# Run tests with coverage +mix test --cover + +# Run a specific test file +mix test test/stopwatch_test.exs + +# Run tests in watch mode (requires mix_test_watch) +mix test.watch +``` + +### Code Formatting + +This project uses Elixir's built-in formatter: + +```bash +# Format all files +mix format + +# Check if files are formatted +mix format --check-formatted +``` + +### Documentation + +Generate and view documentation locally: + +```bash +mix docs +open doc/index.html # or xdg-open on Linux +``` + +### Code Quality + +While not mandatory, we encourage running additional quality checks: + +```bash +# Static analysis (if using Dialyzer) +mix dialyzer + +# Linting (if using Credo) +mix credo --strict +``` + +## Code Style Guidelines + +### General Principles + +- Follow the [Elixir Style Guide](https://github.com/christopheradams/elixir_style_guide) +- Write clear, self-documenting code +- Keep functions small and focused +- Use pattern matching effectively +- Prefer functional patterns over imperative + +### Specific Guidelines + +1. **Documentation** + - Add `@moduledoc` to all modules + - Add `@doc` to all public functions + - Include examples in documentation + - Add `@spec` type specifications + +2. **Testing** + - Write tests for all new functionality + - Maintain or improve test coverage + - Use descriptive test names + - Group related tests with `describe` blocks + +3. **Error Handling** + - Use tagged tuples (`{:ok, result}`, `{:error, reason}`) + - Provide clear error messages + - Handle edge cases explicitly + +4. **Naming Conventions** + - Use descriptive variable names + - Follow Elixir naming conventions + - Use `snake_case` for functions and variables + - Use `PascalCase` for modules + +5. **Module Organization** + ```elixir + defmodule MyModule do + @moduledoc """ + Module documentation + """ + + # Module attributes + @constant_value "value" + + # Type definitions + @type t :: %__MODULE__{} + + # Struct definition + defstruct [:field1, :field2] + + # Public functions + def public_function do + # ... + end + + # Private functions + defp private_function do + # ... + end + end + ``` + +## Commit Message Guidelines + +### Format + +``` +(): + + + +