Skip to content

Refactor key-binding architecture: ConsoleKeyBinding struct, simplified handlers, ESC cancellation, fixed driver lifetime#331

Merged
shibayan merged 6 commits intomasterfrom
copilot/refactor-overall-architecture
Mar 5, 2026
Merged

Refactor key-binding architecture: ConsoleKeyBinding struct, simplified handlers, ESC cancellation, fixed driver lifetime#331
shibayan merged 6 commits intomasterfrom
copilot/refactor-overall-architecture

Conversation

Copy link
Contributor

Copilot AI commented Mar 5, 2026

  • Create ConsoleKeyBinding value type combining ConsoleKey + ConsoleModifiers for type-safe key binding
  • Change FormBase.KeyHandlerMaps to use ConsoleKeyBinding as key and Func<bool> as handler
  • Update TextFormBase to register separate handlers for plain vs Ctrl+key combinations
  • Update SelectFormBase, SelectForm, MultiSelectForm to use the new binding style
  • Update PasswordForm and ListForm to use new binding style
  • Fix driver lifecycle: FormBase.Dispose() owns IConsoleDriver, OffscreenBuffer is not IDisposable
  • Add ESC key support in FormBase as an alternative cancellation key
  • Add ConsoleKeyBindingTests (10 tests)
  • Integrate with master's PromptConfiguration refactor (Refactor prompt options and forms to use PromptConfiguration for improved extensibility #332): SelectFormBase, PromptConfiguration, PromptOptions, updated constructors
  • All 291 tests pass
Original prompt

全体的なアーキテクチャの抜本的な見直しを行ってください

Created from VS Code.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits March 5, 2026 05:37
Co-authored-by: shibayan <1356444+shibayan@users.noreply.github.com>
…, ESC key, fixed lifecycle

Co-authored-by: shibayan <1356444+shibayan@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor overall architecture for improvements Refactor key-binding architecture: ConsoleKeyBinding struct, simplified handlers, ESC cancellation, fixed driver lifetime Mar 5, 2026
@shibayan
Copy link
Owner

shibayan commented Mar 5, 2026

@copilot Please resolve conflicts

…#332) with ConsoleKeyBinding architecture

Co-authored-by: shibayan <1356444+shibayan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 5, 2026

@copilot Please resolve conflicts

Conflicts resolved in 2b00ec9. Integrated master's PromptConfiguration refactor (#332) — updated all form constructors to accept PromptConfiguration, adopted SelectFormBase<TItem,TResult>, and applied ConsoleKeyBinding pattern across all forms including the new base class. All 291 tests pass.

@shibayan shibayan marked this pull request as ready for review March 5, 2026 07:12
@shibayan shibayan requested a review from Copilot March 5, 2026 07:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors Sharprompt’s form key-handling to use a (ConsoleKey, ConsoleModifiers) value type for bindings, simplifying handler signatures and adding Esc as an additional cancellation key while aligning with the newer PromptConfiguration-based form architecture.

Changes:

  • Introduces ConsoleKeyBinding and migrates form key-handler maps to Dictionary<ConsoleKeyBinding, Func<bool>>.
  • Splits plain vs Ctrl+key behaviors into separate handlers (notably for text-editing/navigation).
  • Adds unit tests validating ConsoleKeyBinding equality semantics and dictionary usability.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Sharprompt/Internal/ConsoleKeyBinding.cs Adds a value type representing a key + modifiers pair for dictionary-based key bindings.
Sharprompt/Forms/FormBase.cs Switches dispatch to binding-based lookup and adds Esc cancellation handler.
Sharprompt/Forms/TextFormBase.cs Registers discrete bindings/handlers for plain vs Ctrl navigation/editing keys.
Sharprompt/Forms/SelectFormBase.cs Updates paginator navigation bindings to use ConsoleKeyBinding.
Sharprompt/Forms/PasswordForm.cs Updates backspace handler registration to new binding/handler signature.
Sharprompt/Forms/MultiSelectForm.cs Updates selection toggle and Ctrl-shortcut bindings to new binding style.
Sharprompt/Forms/ListForm.cs Adjusts delete behavior override to the new Ctrl-specific handler.
Sharprompt.Tests/ConsoleKeyBindingTests.cs Adds tests for ConsoleKeyBinding equality/hash/dictionary behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@shibayan shibayan merged commit f34f8fa into master Mar 5, 2026
9 checks passed
@shibayan shibayan deleted the copilot/refactor-overall-architecture branch March 5, 2026 07:45
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.

3 participants