fix: pass the typed character through with each key [patch] - #189
Merged
Merged
Conversation
SpectreConsoleProvider returned only the key and modifiers from Console.ReadKey, dropping KeyChar, so no element could tell '!' from '1', see Caps Lock, or follow a non-US layout. A printable KeyChar now fills InputResult.Character alongside the key and modifiers, so key-based handlers keep working. The conversion moves into an internal ToInputResult so it can be tested without a console. Fixes #152 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XMvgrK1uK13jn4qeVXxDi1
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XMvgrK1uK13jn4qeVXxDi1
# Conflicts: # TUI.Test/SpectreConsoleProviderTests.cs
ReadInputAsync called Console.ReadKey directly, so no test could reach it. An internal constructor now takes the key reader, and a test checks that a Shift+1 read arrives as '!' end to end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XMvgrK1uK13jn4qeVXxDi1
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #152
Before:
SpectreConsoleProvider.ReadInputAsyncreturnedInputResult.FromKey(keyInfo.Key, keyInfo.Modifiers)and droppedkeyInfo.KeyChar. An element saw!asD1+ Shift and couldn't tell it from1./,?and@arrived as layout-dependentOem*keys, and Caps Lock was lost.After: when
KeyCharis printable (not'\0'and not a control character),InputResult.Characteris filled in.Type,KeyandModifiersare unchanged, so key-based handlers such asInteractiveDemobehave exactly as before. Escape and Ctrl+C still produceExit.How:
ConsoleKeyInfo→InputResultconversion moves intointernal static SpectreConsoleProvider.ToInputResult, so it can be tested without a real console.ReadInputAsyncreads through a key-reader delegate. The public constructor still usesConsole.ReadKey(true). A new internal constructor accepts another reader, so tests can driveReadInputAsyncitself.Tests in
SpectreConsoleProviderTests:ToInputResultKeepsThePrintableCharactercovers Shift+D1 →'!',1,A/a, Shift+Oem2 →'?'and a non-ASCIIé. All 6 cases fail onmainand pass with the fix.ReadInputAsyncReturnsTheTypedCharacterdrives a Shift+1 key throughReadInputAsyncand checks that it arrives as'!'.ToInputResultLeavesTheCharacterUnsetForNonPrintableKeys(arrow, Enter, Tab, Backspace)ToInputResultTreatsEscapeAsExitandToInputResultTreatsControlCAsExitToInputResultTreatsPlainCAsACharacterTUI.Testsuite: 240/240. SonarCloud reports 100% coverage on new code.Main (with #187 and #188) is merged in.
🤖 Generated with Claude Code
https://claude.ai/code/session_01XMvgrK1uK13jn4qeVXxDi1