forked from pqwy/notty
-
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
Open
lukstafi
wants to merge
6
commits into
ocaml-community:master
Choose a base branch
from
lukstafi:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a26a9f6
Add Windows support for terminal size detection
lukstafi 5577df8
Missing homepage
lukstafi 9777a9e
Fix Invalid_argument exception on Windows for tcgetattr
lukstafi 25479b8
Enable Windows 10+ ANSI escape sequence support for full TUI function…
lukstafi 11713b8
Fix Enter key recognition on Windows
lukstafi 708e36b
Fix C23 unused macro causing implicit-int error on newer GCC
lukstafi 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #include <caml/mlvalues.h> | ||
|
|
||
| #ifdef _WIN32 | ||
| #define WIN32_LEAN_AND_MEAN | ||
| #include <windows.h> | ||
|
|
||
| /* Some older MinGW/CYGWIN distributions don't define these */ | ||
| #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING | ||
| #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 | ||
| #endif | ||
|
|
||
| #ifndef ENABLE_VIRTUAL_TERMINAL_INPUT | ||
| #define ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200 | ||
| #endif | ||
|
|
||
| #ifndef DISABLE_NEWLINE_AUTO_RETURN | ||
| #define DISABLE_NEWLINE_AUTO_RETURN 0x0008 | ||
| #endif | ||
|
|
||
| /* Enable ANSI escape sequence processing on Windows 10+ console | ||
| Returns 1 on success, 0 on failure */ | ||
| CAMLprim value caml_notty_setup_windows_console(value vunit) { | ||
| (void) vunit; | ||
|
|
||
| HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); | ||
| HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE); | ||
|
|
||
| if (hOut == INVALID_HANDLE_VALUE || hIn == INVALID_HANDLE_VALUE) { | ||
| return Val_int(0); | ||
| } | ||
|
|
||
| DWORD outMode = 0, inMode = 0; | ||
|
|
||
| /* Enable VT processing for output (colors, cursor control, etc.) */ | ||
| if (GetConsoleMode(hOut, &outMode)) { | ||
| outMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; | ||
| /* Disable wrapping at end of line to avoid scrolling issues */ | ||
| outMode |= DISABLE_NEWLINE_AUTO_RETURN; | ||
| if (!SetConsoleMode(hOut, outMode)) { | ||
| return Val_int(0); | ||
| } | ||
| } else { | ||
| return Val_int(0); | ||
| } | ||
|
|
||
| /* Enable VT processing for input (better key handling) */ | ||
| if (GetConsoleMode(hIn, &inMode)) { | ||
| inMode |= ENABLE_VIRTUAL_TERMINAL_INPUT; | ||
| /* Disable line input and echo for raw input */ | ||
| inMode &= ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT); | ||
| /* Enable window input for resize events */ | ||
| inMode |= ENABLE_WINDOW_INPUT; | ||
| if (!SetConsoleMode(hIn, inMode)) { | ||
| /* Input mode failure is not critical, continue */ | ||
| } | ||
| } | ||
|
|
||
| return Val_int(1); | ||
| } | ||
|
|
||
| #else | ||
|
|
||
| /* Non-Windows platforms: no-op, always return success */ | ||
| CAMLprim value caml_notty_setup_windows_console(value vunit) { | ||
| (void) vunit; | ||
| return Val_int(1); | ||
| } | ||
|
|
||
| #endif |
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.
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.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.
@MisterDA This is pattern alternative of characters, not string matching. Is there an actionable item here for me? It feels innocent to map
'\r'to the Enter key but I could make it awhen Sys.os_type = "Win32".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.
Right, my mistake!
Not sure. Have you observed the
\rbehavior on Windows?In any case yes, you could restrict it to Windows and/or Cygwin.
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.
Why do we need to generate such keypresses for carriage returns in the first place? Shouldn't the new line be enough?