Skip to content

refactor: deduplicate code and extract logic in widgets, enums, and context/cursor#9

Merged
surgiie merged 1 commit into
mainfrom
dry
Apr 15, 2026
Merged

refactor: deduplicate code and extract logic in widgets, enums, and context/cursor#9
surgiie merged 1 commit into
mainfrom
dry

Conversation

@surgiie

@surgiie surgiie commented Apr 15, 2026

Copy link
Copy Markdown
Owner

This pull request introduces several improvements and refactorings to the codebase, focusing on code reuse, maintainability, and UI consistency. The most significant changes include extracting tag color logic into a reusable class, introducing a trait for rendering centered dialogs, refactoring urgency option handling, and simplifying cursor management. Below are the most important changes grouped by theme:

Tag color handling and code reuse:

  • Extracted tag color palette and logic from Todo and TodoDetailWidget into a new reusable class TagColors, which provides methods for assigning consistent colors to tags by name or index. (src/Support/TagColors.php, src/Support/Todo.php, src/Widgets/TodoDetailWidget.php) [1] [2] [3] [4] [5] [6]

UI consistency and code reuse for dialogs:

  • Added a new trait RendersAsDialog to encapsulate the logic for rendering widgets as centered dialogs with horizontal margins, and refactored HelpWidget and TodoDetailWidget to use this trait for consistent dialog appearance. (src/Widgets/Concerns/RendersAsDialog.php, src/Widgets/HelpWidget.php, src/Widgets/TodoDetailWidget.php) [1] [2] [3] [4] [5]

Urgency option handling improvements:

  • Added a static method selectOptions() to the TodoUrgency enum to generate a value-to-label map for select prompts, and refactored related code to use this method for better maintainability. (src/Support/Enums/TodoUrgency.php, src/Support/DataManager.php) [1] [2] [3]

Cursor management and code simplification:

  • Added a static inactive() constructor to the Cursor class for clearer intent, and refactored usage throughout the codebase to use this method instead of manually instantiating inactive cursors. (src/Support/Cursor.php, src/Widgets/MainWidget.php) [1] [2] [3]
  • Consolidated repeated paginator update logic in MainWidget into a new helper method updatePaginatorForType(), reducing code duplication and improving maintainability. (src/Widgets/MainWidget.php) [1] [2] [3] [4] [5] [6]

Other improvements:

  • Made DATA_FILE_NAME in DataManager public and updated references to use it instead of a duplicate constant in Context. (src/Support/DataManager.php, src/Support/Context.php) [1] [2] [3]
  • Simplified container removal logic in the docker script by using docker rm -f and docker container inspect. (docker)

@surgiie surgiie merged commit 89fd0d2 into main Apr 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant