-
Notifications
You must be signed in to change notification settings - Fork 3
Add Windows support #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
Windows KEY_EVENT_RECORD structure documentation - bKeyDown flag and character handling💡 Result:
Short answer
Notes / best practices
Sources
[1] Microsoft: KEY_EVENT_RECORD (Windows Console) — documentation of bKeyDown and uChar.
[2] Microsoft Q&A / ReadConsoleInput notes — uChar is nonzero only for printable characters; ReadConsoleInputA may return multi‑byte bytes for codepages.
[3] Stack Overflow — practical notes: ignore key‑up events and zero uChar, and prefer ReadConsoleInputW for Unicode.
🏁 Script executed:
Repository: gdamore/dcell
Length of output: 80
🌐 Web query:
CONSOLE_SCREEN_BUFFER_INFO structure - dwSize is buffer size, srWindow is visible window coordinates💡 Result:
dwSize: a COORD giving the console screen buffer size in character columns and rows (i.e., total buffer width/height). [1]
srWindow: a SMALL_RECT that gives the visible window’s coordinates inside that buffer — Left/Top are the upper‑left cell, Right/Bottom the lower‑right cell; coordinates are in character‑cell units with origin (0,0) at the buffer’s upper‑left. You can modify srWindow and pass it to SetConsoleWindowInfo to move/resize/scroll the visible window. [1][2][3]
Sources: Microsoft Docs — CONSOLE_SCREEN_BUFFER_INFO; SMALL_RECT; GetConsoleScreenBufferInfo. [1][2][3]
🏁 Script executed:
Repository: gdamore/dcell
Length of output: 39
🏁 Script executed:
Repository: gdamore/dcell
Length of output: 39
🏁 Script executed:
Repository: gdamore/dcell
Length of output: 39
Fix KEY_EVENT handling and window size calculation for correctness
The Windows TTY implementation has two bugs that affect functionality:
KEY_EVENT handling in
readReadConsoleInputdelivers both key-down and key-up events, and every event appendsAsciiChartoresultwithout filtering. According to Windows API documentation,bKeyDownis TRUE only on key press and FALSE on key release; additionally,uCharis typically zero for non-printable keys. The current code will emit spurious characters from key-up events and non-printable keys. Correct this by checkingif (ev.KeyEvent.bKeyDown && ev.KeyEvent.AsciiChar != 0)before appending.Window size vs buffer size in
windowSize()GetConsoleScreenBufferInfopopulatesdwSizewith the total screen buffer dimensions, not the visible window. The visible window dimensions are insrWindow(aSMALL_RECTwithLeft,Top,Right,Bottomcoordinates). ReturnCoord(oscreen.srWindow.Right - oscreen.srWindow.Left + 1, oscreen.srWindow.Bottom - oscreen.srWindow.Top + 1)to get the actual on-screen dimensions.Error handling (optional)
Win32 calls ignore return values; adding minimal checks or asserts would catch failures during development.
🤖 Prompt for AI Agents