-
Notifications
You must be signed in to change notification settings - Fork 2
MS Windows console support #12
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
base: master
Are you sure you want to change the base?
Conversation
This commit adds native Windows support to the notty-community library: - **winsize.c**: Implement Windows console API support using GetConsoleScreenBufferInfo - Use srWindow (visible area) instead of buffer size for accurate terminal dimensions - Return 0 from winch_number on Windows (no SIGWINCH signal) - Add portable unused parameter macro for C23/GNU/other compilers - Include Haiku compatibility for platforms with ioctl in unistd.h - **notty_unix.ml**: Handle winch_number returning 0 on Windows - Prevent signal registration errors when SIGWINCH is unavailable - Return no-op revert function for platforms without window resize signals - **dune**: Add compiler-specific C flags - GCC/Clang: -Wall -Wextra -O3 - MSVC: /W2 /Ox - Use ocaml-config:ccomp_type to select appropriate flags 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Signed-off-by: lukstafi <[email protected]>
On Windows, Unix.tcgetattr raises Invalid_argument instead of
Unix_error(ENOTTY) when terminal control functions are not implemented.
This caused crashes when using notty-community TUI tools on Windows.
Add exception handler for Invalid_argument to gracefully handle Windows
platforms where terminal attributes cannot be configured.
Fixes: Error: Invalid_argument("Unix.tcgetattr not implemented")
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
…ality This commit enables full terminal UI features on Windows 10 and later by activating the Virtual Terminal processing mode through the Windows Console API. **New file: win_console.c** - Implements caml_notty_setup_windows_console() to enable VT processing - Sets ENABLE_VIRTUAL_TERMINAL_PROCESSING for output (colors, cursor control) - Sets ENABLE_VIRTUAL_TERMINAL_INPUT for better keyboard input handling - Disables line input and echo for raw terminal input - Enables window input for resize event detection - Gracefully handles older Windows versions and non-console outputs **Updated: notty_unix.ml** - Calls setup_windows_console() when TERM variable is not set (typical on Windows) - Uses ANSI capabilities (Cap.ansi) when VT processing is successfully enabled - Falls back to dumb terminal mode if VT processing unavailable **Updated: dune** - Added win_console to the list of C stubs to compile **Benefits:** - ✅ Colors and text attributes now work on Windows - ✅ Cursor positioning and screen clearing work properly - ✅ Double-buffering via alternate screen buffer - ✅ Improved keyboard input handling - ✅ Window resize event detection Requires Windows 10 TH2 (v1511) or later. Older Windows versions will continue to work with degraded functionality (dumb terminal mode). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Windows terminals send carriage return '\r' (0x0D) for the Enter key, while Unix terminals send line feed '\n' (0x0A). Previously, '\r' was being misinterpreted as Ctrl+M due to the C0 control code fallback logic. Updated the Enter key pattern match to accept both '\n' and '\r', ensuring Enter key works correctly on both Windows and Unix platforms. Fixes: Enter key producing 'M' character on Windows 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
I am seeing errors in some runs in a CI suite across a wide range of targets, e.g.: https://ocaml.ci.dev/github/ahrefs/ocannl/commit/5c2fd68319a965307de8ed1eb719d98fde824116/variant/fedora-42-5.4_opam-2.4 The upside is that when this CI suite becomes green, I get more confidence in this PR. Edited to add: this is fixed now. |
Remove parentheses from the C23 [[maybe_unused]] macro expansion. The parentheses caused GCC to interpret the parameter as a type name, triggering -Wimplicit-int errors on Fedora 42/43 and openSUSE 16.0. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
I did not have the time to look at this yet. cc @MisterDA who may also want to have a look. |
| | C0 '\x1b' -> key `Escape [] | ||
| | C0 ('\b'|'\x7f') -> key `Backspace [] | ||
| | C0 '\n' -> key `Enter [] | ||
| | C0 ('\n'|'\r') -> key `Enter [] |
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.
We can probably affine the pattern matching with Sys.os_type.
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.
Isn't this reversed, too? The line ending is CRLF, \r\n.
This PR fixes #2 (winsize) drawing from the two commits mentioned there -- incorporates contributions from Antonin Décimo.
This PR also provides proper console support on the Windows OS -- courtesy of Claude. I verified the behavior via my project ppx_minidebug.
Vibe-coded using Claude Code.