# Changelog

Format from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/);
and we use [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] - YYYY-MM-DD

### Added

### Changed

### Deprecated

### Removed

### Fixed

### Security

## [0.2.0] - 2024-07-24

### Added

- Initial release of Raxol
- Terminal UI framework with web interface capabilities
- Core components library
- Visualization plugins
- Internationalization support
- Theme system

### Changed

- **Dependencies:** Updated `rrex_termbox` from v1.1.5 to v2.0.1, migrating from Port-based to NIF-based architecture for improved performance and reliability.
- **Terminal Subsystem:** Refactored all terminal code to use the new RrexTermbox 2.0.1 API with GenServer-based event delivery.
  - Updated `lib/raxol/terminal/driver.ex` to use the NIF-based interface instead of Port-based communication
  - Updated `lib/raxol/terminal/terminal_utils.ex` for NIF-based terminal dimension detection
  - Redesigned `lib/raxol/terminal/constants.ex` to directly map to NIF constants
  - Rewritten `lib/raxol/core/events/termbox_converter.ex` to handle NIF event format
  - Updated `lib/raxol/test/mock_termbox.ex` to match the NIF-based interface for testing
- **Terminal Documentation:** Updated all documentation to reflect the NIF-based architecture:
  - Updated `docs/development/planning/terminal/terminal_dimensions.md`
  - Updated `docs/development/planning/handoff_prompt.md`
  - Updated `docs/guides/components/visualization/testing-guide.md`
  - Updated `docs/guides/terminal_emulator.md`
- **Tests:** Rewritten `test/raxol/terminal/driver_test.exs` to test NIF events instead of Port-based IO communication
- **Event Handling:** Updated the event handling system to work with the new termbox NIF architecture.

### Known Issues

- Various compiler warnings as documented in the CI logs
- **Runtime Hang:** Examples launched via `Raxol.start_link/1` (e.g., using `bin/demo.exs`) currently hang after compilation, indicating a blocking issue in the core runtime initialization or render loop.

### Added

- **Project Foundation:** Initial structure, config, docs, CI/CD, dev env, quality tools, test framework.
- **Core Systems:**
  - Terminal emulation layer with ANSI processing and feature detection.
  - Buffer management (double buffering, damage tracking, scrolling, cursor).
  - Plugin system (core API, config, dependencies, loading, command registry).
  - Component system (View DSL, layout components, widgets, testing framework).
  - Runtime logic (Dispatcher, Manager, Driver, Supervisor, event loop).
  - Core features (ID generation, preferences, plugin registry).
  - Terminal buffer operations (scrollback, selection).
  - Color system module for theme/accessibility aware color retrieval.
  - User preferences persistence module.
- **UI Components:** Added `Table` and `SelectList`.
- **Terminal Capabilities:** Enhanced ANSI processing, input parsing (mouse, special keys, bracketed paste).
- **VS Code Extension Integration:** Communication protocol, WebView panel, JSON interface.
- **Database:** Connection management, error handling, diagnostics improvements.
- **Dashboard/Visualization:** Widget layout management, responsiveness, caching. Added helpers for Chart, Treemap, Image rendering.
- **CI/CD:** Local testing (`act`), cross-platform enhancements, security scanning.
- **Theme System:** Multiple built-in themes, selection UI, customization API, persistence.
- **Testing:**
  - General testing framework improvements (mock components, performance monitoring).
  - Added tests for mouse event parsing, runtime supervisor, plugin manager (loading, reloading, dependencies), dispatcher interactions, layout measurement, `MultiLineInput` helpers.
  - Added mock plugins and test setup helpers.
- **MultiLineInput Features:** Implemented basic cursor navigation, clipboard integration, and scrolling logic.
- **Sixel Support:** Added initial modules for pattern mapping and palette handling.
- **Documentation:**
  - Added initial drafts for Plugin Development, Theming, and VS Code Extension guides.
- **Examples:** Created initial `component_showcase.exs` example.

### Changed

- **Architecture:** Updated `ARCHITECTURE.md` codebase size analysis with new thresholds and file sizes.
- **Architecture:** Completed major codebase reorganization and refactoring of core systems (Runtime, Terminal, UI, Plugins) for improved modularity, configuration, and structure. Updated `ARCHITECTURE.md`.
- **Components:** Refactored `Table` component (`lib/raxol/ui/components/display/table.ex`) to use attributes for data/columns instead of internal state and apply basic width constraints.
- **Terminal Functionality:** Improved feature detection, refined ANSI processing, optimized config/memory management. Refactored input parsing in `TerminalDriver` to use `:os.cmd("stty ...")`.
- **Plugin System:** Improved initialization, dependency resolution, API versioning. Defined `Plugin` behaviour. Refactored `PluginManager` and `CommandRegistry` (namespaces, arity, lifecycle/command helpers). Implemented basic plugin reloading infrastructure.
- **Runtime System:** Improved dual-mode operation, startup/error handling. Ensured correct command routing. Refactored `Lifecycle` module.
- **Rendering Pipeline:** Refined rendering flow, integrated theme application, implemented active theme management, updated layout engine, implemented border rendering for `:box`. Refactored `RenderingEngine`.
- **Project Structure:** Consolidated examples, improved secrets/git handling. Updated roadmap documents.
- **Terminal Configuration:** Refactored `configuration.ex` into dedicated modules. Added deep merge utility.
- **View/Layout System:** Standardized on macros in `Raxol.View.Elements`.
- **Layout Engine:** Implemented measurement logic for `:panel`, `:grid`, `:view`.
- **Terminal Parser:** Refactored `parse_loop` and CSI dispatching logic. Implemented placeholder handlers for SGR, scroll regions, cursor styles, etc.
- **Terminal Emulator:** Refactored control code handling (C0, ESC sequences).
- **Terminal Integration:** Refactored memory management and config update logic.
- **MultiLineInput Component:** Refactored core logic into helper modules. Implemented selection logic.
- **Visualization Plugin:** Refactored rendering logic into separate modules.
- **Sixel Graphics:** Partially refactored parser and rendering logic.
- **Dashboard Component:** Implemented grid-based rendering.
- **Color System Integration:** Refactored `Theme` for variants/palettes. Refactored `ThemeIntegration` for high-contrast state management.
- **User Preferences System:** Refactored `UserPreferences` GenServer to use `Persistence` module, support nested keys, and add auto-saving.
- **Various Components & Modules:** Updated numerous components (`Button`, `Checkbox`, etc.), examples, scripts, benchmarks, and cloud monitoring modules to align with refactoring and fix behaviour implementations.
- **Documentation:**
  - Reviewed and updated core documentation guides (`README.md`, components, quick start, async, runtime options, terminal emulator, development setup, architecture) post-refactoring.
  - Rewritten Component Development guide.
  - Updated `README.md` example.
- **Mixfile (`mix.exs`):** Removed obsolete `mod:` key, updated description.
- **Examples:** Refactored `component_showcase.exs` theming tab to use `Raxol.Core.ColorSystem.get/2`.
- **Documentation:** Reviewed and updated terminal subsystem documentation (`ANSIProcessing.md`, `CharacterSets.md`, `ClipboardManagement.md`, `ColorManagement.md`, `Cursor.md`) to align with current architecture (`Parser`, `Emulator`, `Driver`, `Theming`, `ColorSystem`, etc.) and remove outdated content.
- **Documentation:** Rewritten `docs/development/planning/overview.md` to align with current state and future vision.
- **Documentation:** Updated `docs/development/planning/handoff_prompt.md` to include future feature goals from overview.
- **Documentation:** Updated `docs/development/planning/roadmap/Roadmap.md` based on revised overview.
- **Documentation:** Performed major cleanup: removed obsolete files/stubs, relocated terminal detail files to `docs/development/terminal/`, updated links in root `README.md` and `docs/README.md`.
- **Documentation:** Archived outdated, large planning documents (`docs/development/planning/performance/case_studies.md`, `docs/development/planning/examples/integration_example.md`) to `docs/development/archive/planning/`.
- **Examples:** Refactored `lib/raxol/examples/integrated_accessibility_demo.ex` to remove standalone `run/0` logic and rely on the `Raxol.Core.Runtime.Application` behaviour implementation.
- **Examples:** Updated `bin/demo.exs` script to launch examples using `Raxol.start_link/1` instead of calling module-specific `run/0` functions.
- **Terminal Subsystem:** Refactored `Raxol.Terminal.Driver` to utilize the `:rrex_termbox` NIF-based interface (v2.0.1) for input event handling, removing direct stdio management and ANSI parsing logic.
- **Terminal Subsystem:** Refactored `Raxol.Terminal.TerminalUtils` to remove dependency on `:rrex_termbox` for determining terminal dimensions, relying solely on `:io` and `stty`.
- **Examples:** Enhanced `lib/raxol/examples/integrated_accessibility_demo.ex` by:
  - Integrating `Raxol.Core.UserPreferences` for loading/saving settings.
  - Integrating `Raxol.Core.I18n` for translations.
  - Improving the animation example (progress bar) and respecting reduced motion.
  - Removing unused aliases and performing general cleanup.

### Deprecated

- Old event system
- Legacy rendering approach
- Previous styling methods
- `Raxol.Terminal.CommandHistory` (Use `Raxol.Terminal.Commands.History` instead)

### Removed

- Obsolete configuration files, dependencies, documentation, and legacy code following major refactoring (including old top-level modules, `CommandHistory`, helper module component usage, redundant layout functions, unused code).
- Pruned obsolete files and directories (Note: Further investigation needed for some potentially obsolete directories).

### Fixed

- **Compiler Warnings:** Resolved remaining warnings:
  - Unused variable `_state` in `Raxol.Terminal.Driver.terminate/2`.
  - Unused variables `_current_color`, `_current_char` in `Raxol.Terminal.ANSI.SixelGraphics.generate_pixel_data/4` within specific `if` block.
  - Redefined `@doc` for `Raxol.Style.Colors.Accessibility.accessible_color_pair/2` by removing potentially conflicting comments/docs around private helper functions.
- **Compilation & Build:**
  - Resolved `:rrex_termbox` (v2.0.1) compilation failures by adapting code to its NIF-based API.
  - Fixed guard clause issues in `lib/raxol/core/events/termbox_converter.ex` by defining module attributes for key constants.
  - Updated references from `:rrex_termbox` to `ExTermbox` in multiple files:
    - `lib/raxol/terminal/constants.ex`
    - `lib/raxol/terminal/driver.ex`
    - `lib/raxol/terminal/terminal_utils.ex`
  - Fixed issues in MultiLineInput component:
    - Corrected namespace in tests from `Raxol.UI.Components.Input.MultiLineInput.State` to `Raxol.Components.Input.MultiLineInput`
    - Updated cursor position handling to use the `cursor_pos` tuple instead of separate `cursor_row` and `cursor_col` fields
    - Fixed pattern matching in navigation helper to extract coordinates from cursor position tuple
    - Implemented missing `clear_selection` and `normalize_selection` functions
    - Fixed line-wrapping behavior for cursor movement in left and right directions
  - Applied local patch to `deps/rrex_termbox/Makefile` to remove obsolete NIF build rules that prevented compilation.
  - Resolved numerous compilation errors and warnings across the codebase related to refactoring (undefined functions/variables, incorrect module paths/aliases/imports, behaviour implementations, syntax errors, type issues, argument errors, cyclic dependencies).
  - Fixed compilation errors in `lib/raxol/plugins/visualization/treemap_renderer.ex` (unused variable, incorrect function call).
  - Fixed compilation errors in `lib/raxol/style/colors/accessibility.ex` (removed duplicate `contrast_ratio/2` definition).
  - Fixed compilation error in `lib/raxol/ui/components/display/table.ex` (syntax error in `init/1`).
  - Addressed issues related to Elixir/OTP compatibility (e.g., charlist syntax, `:os.cmd` usage).
  - Addressed compiler warnings related to missing color utility functions (`HSL.darken/2`, `HSL.lighten/2`, `Accessibility.ensure_contrast/3`, `DrawingUtils.get_contrasting_text_color/1`) by commenting out calls and adding TODOs in `palette_manager.ex`, `treemap_renderer.ex`, and `accessibility.ex`.
- **Runtime & Core:**
  - Fixed `FunctionClauseError` in `MultiLineInput.render/2` macro usage.
  - Corrected event routing and command handling in runtime.
  - Fixed issues in `PluginManager`, `CommandRegistry`, `Dispatcher`, `TerminalDriver`, `LifecycleHelper`, `Rendering.Scheduler`.
- **Components:**
  - Fixed `KeyError` in `MultiLineInput` default theme creation.
  - Fixed `MultiLineInput` behaviour implementation arity and `TextHelper` function calls.
  - Fixed `VisualizationPlugin` behaviour implementation.
  - Addressed errors in `Table`, `Progress`, `Modal`, `HintDisplay`, `FocusRing`, `Spinner`, `Dashboard`, `WidgetContainer`, `Dropdown`, `Button`, `Terminal`, `TextInput`, `Form`.
- **Terminal & ANSI:**
  - Fixed incorrect calls to `ControlCodes` and `ScreenBuffer` functions.
  - Corrected `stty` command usage in `TerminalDriver`.
  - Fixed errors in Sixel graphics parsing logic.
  - Fixed scroll region clearing logic.
- **Styling & Theming:**
  - Fixed multiple defaults definitions in `Harmony` and `Accessibility` color modules. Defined missing contrast helper.
  - Corrected calls to `Style.new` in visualization modules.
  - Fixed function calls in `PaletteManager` to use correct `HSL` and `Accessibility` modules.
  - Restored accidentally removed `darken_until_contrast/3` function in `lib/raxol/style/colors/accessibility.ex`.
- **Utilities & Helpers:**
  - Fixed incorrect function calls (`List.fetch`, `component` usage in examples, `load_default_config`).
  - Fixed memory trimming logic in `MemoryManager`.
  - Fixed private function call error in benchmark reporting.
- **Examples:** Addressed compilation errors and updated usage in `component_showcase.exs`, `ux_refinement_demo.exs`.
- **Examples:** Fixed calls to deprecated `*_enabled?` accessibility functions in `keyboard_shortcuts_demo.ex` and `accessibility_demo.ex`, replacing them with `Accessibility.get_option/1`.
- **Components:** Fixed `Table` component rendering by correctly aligning attribute/data flow between `Table.render/2`, `Layout.Table.measure_and_position/3`, and `Renderer.render_table/6`. Ensured `Elements.table/1` is used and attributes (`:data`, `:columns`, `_headers`, `_data`, `_col_widths`) are passed/extracted correctly.
- **Examples:** Added missing application runner (`Raxol.start_link`) to `table_test.exs`.
- **Warnings:** Fixed undefined function calls `Raxol.Core.Logger.info/1` in `keyboard_shortcuts_demo.ex` by adding `require Logger` and using `Logger.info/1`.
- **Warnings:** Fixed undefined function call `Raxol.UI.Theming.Theme.get_variant!/1` in `theme_integration.ex` by returning the variant atom directly.
- **Warnings:** Fixed undefined function call `Raxol.Core.Accessibility.default_options/0` by removing the wrapper call in `theme_integration.ex` and adjusting usage in `Accessibility.announce/2`.
- **Warnings:** Removed numerous unused aliases across multiple modules (`Emulator`, `SixelGraphics`, `RenderHelper`, `Supervisor`, `PaletteManager`, `Parser`, `AccessibilityDemo`, `ControlCodes`, `MultiLineInput`, `MemoryManager`).
- **Warnings:** Fixed various specific warnings:
  - Undefined `ThemeIntegration.get_active_theme/0` in `accessibility_demo.ex`.
  - Type mismatch in `NavigationHelper.move_cursor/2` calls.
  - Potential nil value in `Integer.to_string/1` call in `sixel_graphics.ex`.
  - Deprecated `Logger.warn/1` replaced with `Logger.warning/1`.
  - Fixed usage of underscored variables that were actually used (`_pn`, `_color_selection_cmd`, `_final_last_char`, `_line_num_element`).
  - Removed unused functions (`format_color_for_announcement`, `ensure_contrast_or_limit`, `find_accessible_pair`, `pref_key`, `get_option`).
  - Removed duplicate `@doc` for `contrast_ratio/2`.
  - Removed `@doc` from private function `maybe_scroll/1`.
  - Reordered `update/2` clauses in `MultiLineInput`.
  - Removed unused module attributes (`@memory_check_interval_ms`, `@polling_interval_ms`).
  - Fixed undefined function calls to `UserPreferences.get/2` and `put/2` (used `get/1`, `set/2`).
  - Fixed undefined function calls in `control_codes.ex` (`Emulator.get_scroll_region/1`, commented out `:terminal_state_api.cmd_scroll/2`).
  - Added missing `Application` behaviour callbacks to `keyboard_shortcuts_demo.ex`.
  - Fixed `handle_event` signature/call in `keyboard_shortcuts_demo.ex`.
  - Refactored RLE logic in `sixel_graphics.ex` to fix scoping errors.
  - Fixed syntax error in `lib/raxol/terminal/memory_manager.ex` (removed trailing comma in `defstruct`).
  - Added missing `GenServer.init/1` implementation to `lib/raxol/terminal/memory_manager.ex`.
  - Fixed undefined function call `Color.to_hsl!` in `lib/raxol/style/colors/palette_manager.ex` (used `HSL.rgb_to_hsl/3`).
  - Fixed `if` macro syntax error in `lib/raxol/examples/keyboard_shortcuts_demo.ex`.
  - Fixed undefined function calls to `UserPreferences.get/1` in `lib/raxol/examples/keyboard_shortcuts_demo.ex` (used `Raxol.Core.UserPreferences.get/1`).
  - Fixed undefined macro call `vbox/1` in `lib/raxol/examples/keyboard_shortcuts_demo.ex` (used `box/1` and added `require Raxol.View.Elements`).
  - Added missing `Raxol.Core.Runtime.Application` behaviour implementations (`handle_event/1`, `handle_tick/1`, `subscriptions/1`) to `lib/raxol/examples/keyboard_shortcuts_demo.ex`.
  - Corrected `@impl` annotation for `handle_event/1` in `lib/raxol/examples/keyboard_shortcuts_demo.ex`.
  - _Note:_ Several compiler warnings remain and require manual fixes (duplicate `@doc` in `accessibility.ex`, unused vars in `sixel_graphics.ex` & `render_helper.ex`, incorrect `@impl` on `handle_event/2` in `keyboard_shortcuts_demo.ex`). Some automated edits failed to apply fixes for these warnings.
- **Warnings:** Fixed unused variable warnings in `lib/raxol/terminal/ansi/sixel_graphics.ex` (`_current_color`, `_current_char`) by prefixing with underscores.
- **Warnings:** Fixed unused variable warning in `lib/raxol/components/input/multi_line_input/render_helper.ex` (`_line_number_text`) by prefixing with an underscore.
- **Warnings:** Automated edits failed to remove duplicate `@doc` warning in `lib/raxol/style/colors/accessibility.ex`; requires manual removal.
- **Compilation:** Resolved compilation errors by reverting variable prefixing (`_current_color`, `_current_char`, `_line_number_text`) that caused undefined variable errors, allowing compilation without `--warnings-as-errors`. Persisted warnings for unused variables and `@doc` redefinition are noted.

### Security

Bing bong, fck ya life.
