From bf962000b687c44ac2b1d5434de76561cbdbdca0 Mon Sep 17 00:00:00 2001 From: sunrisepeak Date: Sun, 20 Sep 2026 16:35:16 +0800 Subject: [PATCH] 0.9.0 --- the keystrokes this console keeps for itself are a position now openkal 0.14 adds KAL_TERM_PASS_CONTROL, and this implementation reads and writes it as ENABLE_PROCESSED_INPUT, inverted. This environment keeps the keystrokes it reserves --- the interrupt, and the pair that stops and starts output --- behind one flag, where the two termios environments spread the same reservation over three of their own. The position asks one question on either side: does the environment reserve anything at all. That is why it is one position and not one per class of keystroke, which this environment could not answer (clause 6.4). The rule the specification states beside set_mode --- that a position whose requested value is the one in effect is not written --- binds an implementation whose position stands for several mechanisms. Here it stands for one, and assigning it from the mode word is the same act as leaving it alone. --- README.md | 4 ++-- mcpp.toml | 4 ++-- src/terminal.cpp | 27 +++++++++++++++++++++++---- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f097e6e..5ff3568 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@ An implementation of [openkal](https://github.com/mcpplibs/openkal) for Windows. ```toml [dependencies] -openkal = "0.13.0" +openkal = "0.14.0" [target.'cfg(windows)'.dependencies] -openkal-windows = "0.8.0" +openkal-windows = "0.9.0" ``` Its purpose is as much to test the specification as to be used. openkal was diff --git a/mcpp.toml b/mcpp.toml index 46b6c24..3e31ad1 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -1,7 +1,7 @@ [package] namespace = "mcpplibs" name = "openkal-windows" -version = "0.8.0" +version = "0.9.0" description = "An implementation of openkal for Windows, written on the Win32 interfaces and the object manager beneath them, using no C runtime symbol." license = "Apache-2.0" @@ -18,7 +18,7 @@ authors = ["mcpplibs"] repo = "https://github.com/mcpplibs/openkal-windows" [dependencies] -openkal = "0.13.0" +openkal = "0.14.0" # The package contributes definitions and no modules. The interface it # implements is declared by the specification package, which this package diff --git a/src/terminal.cpp b/src/terminal.cpp index 2fb9e5c..b68fb17 100644 --- a/src/terminal.cpp +++ b/src/terminal.cpp @@ -18,8 +18,17 @@ void* handle_of(kal_stream s) { return reinterpret_cast(s.h); } bool valid(void* h) { return h != nullptr && h != INVALID_HANDLE_VALUE; } // This environment's console input flags. -constexpr DWORD enable_line_input = 0x0002; -constexpr DWORD enable_echo_input = 0x0004; +constexpr DWORD enable_processed_input = 0x0001; +constexpr DWORD enable_line_input = 0x0002; +constexpr DWORD enable_echo_input = 0x0004; + +// KAL_TERM_PASS_CONTROL IS ENABLE_PROCESSED_INPUT, INVERTED. This environment +// keeps the keystrokes it reserves --- the interrupt, and the pair that stops +// and starts output --- behind one flag, so the position is set exactly when +// that flag is clear. The two environments this specification is otherwise +// implemented on spread the same reservation over three flags of their own; +// what the position states is that none of them reserves anything, which is one +// question on either side. } // namespace @@ -38,8 +47,9 @@ int kal_terminal_get_mode(kal_stream s, kal_uintptr* mode) { if (!GetConsoleMode(h, &m)) return kal_err_not_supported; kal_uintptr out = 0; - if ((m & enable_line_input) != 0) out |= KAL_TERM_LINE_EDIT; - if ((m & enable_echo_input) != 0) out |= KAL_TERM_ECHO; + if ((m & enable_line_input) != 0) out |= KAL_TERM_LINE_EDIT; + if ((m & enable_echo_input) != 0) out |= KAL_TERM_ECHO; + if ((m & enable_processed_input) == 0) out |= KAL_TERM_PASS_CONTROL; *mode = out; return kal_ok; } @@ -60,6 +70,15 @@ int kal_terminal_set_mode(kal_stream s, kal_uintptr mode) { else m &= ~enable_line_input; if ((mode & KAL_TERM_ECHO) != 0) m |= enable_echo_input; else m &= ~enable_echo_input; + if ((mode & KAL_TERM_PASS_CONTROL) != 0) m &= ~enable_processed_input; + else m |= enable_processed_input; + + // THE POSITION IS ONE FLAG HERE, SO WRITING IT AGAIN SETTLES NOTHING THE + // CALLER DID NOT ASK ABOUT. The rule the specification states beside + // set_mode --- that a position whose requested value is the one in effect + // is not written --- binds an implementation whose position stands for + // several mechanisms; this one stands for exactly one, and assigning it + // from the mode word is the same act as leaving it alone. // A position this implementation does not distinguish is ignored rather than // refused, which clause 6.2 requires of a word.