terminal: KAM (mode 2)

This has an associated config `vt-kam-allowed` which defaults to "false"
since this mode can cause the terminal to become mostly unusable. We
include this mode for completions sake however.
This commit is contained in:
Mitchell Hashimoto
2023-10-12 17:07:47 -07:00
parent f5a80f6b98
commit 6a065540dd
5 changed files with 64 additions and 0 deletions

View File

@ -145,6 +145,7 @@ const DerivedConfig = struct {
mouse_shift_capture: configpkg.MouseShiftCapture, mouse_shift_capture: configpkg.MouseShiftCapture,
macos_non_native_fullscreen: configpkg.NonNativeFullscreen, macos_non_native_fullscreen: configpkg.NonNativeFullscreen,
macos_option_as_alt: configpkg.OptionAsAlt, macos_option_as_alt: configpkg.OptionAsAlt,
vt_kam_allowed: bool,
window_padding_x: u32, window_padding_x: u32,
window_padding_y: u32, window_padding_y: u32,
@ -166,6 +167,7 @@ const DerivedConfig = struct {
.mouse_shift_capture = config.@"mouse-shift-capture", .mouse_shift_capture = config.@"mouse-shift-capture",
.macos_non_native_fullscreen = config.@"macos-non-native-fullscreen", .macos_non_native_fullscreen = config.@"macos-non-native-fullscreen",
.macos_option_as_alt = config.@"macos-option-as-alt", .macos_option_as_alt = config.@"macos-option-as-alt",
.vt_kam_allowed = config.@"vt-kam-allowed",
.window_padding_x = config.@"window-padding-x", .window_padding_x = config.@"window-padding-x",
.window_padding_y = config.@"window-padding-y", .window_padding_y = config.@"window-padding-y",
@ -985,6 +987,13 @@ pub fn keyCallback(
if (consumed and performed) return true; if (consumed and performed) return true;
} }
// If we allow KAM and KAM is enabled then we do nothing.
if (self.config.vt_kam_allowed) {
self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock();
if (self.io.terminal.modes.get(.disable_keyboard)) return true;
}
// If this input event has text, then we hide the mouse if configured. // If this input event has text, then we hide the mouse if configured.
if (self.config.mouse_hide_while_typing and if (self.config.mouse_hide_while_typing and
!self.mouse.hidden and !self.mouse.hidden and

View File

@ -461,6 +461,14 @@ keybind: Keybinds = .{},
/// The default value is "16-bit". /// The default value is "16-bit".
@"osc-color-report-format": OSCColorReportFormat = .@"16-bit", @"osc-color-report-format": OSCColorReportFormat = .@"16-bit",
/// If true, allows the "KAM" mode (ANSI mode 2) to be used within
/// the terminal. KAM disables keyboard input at the request of the
/// application. This is not a common feature and is not recommended
/// to be enabled. This will not be documented further because
/// if you know you need KAM, you know. If you don't know if you
/// need KAM, you don't need it.
@"vt-kam-allowed": bool = false,
/// If anything other than false, fullscreen mode on macOS will not use the /// If anything other than false, fullscreen mode on macOS will not use the
/// native fullscreen, but make the window fullscreen without animations and /// native fullscreen, but make the window fullscreen without animations and
/// using a new space. It's faster than the native fullscreen mode since it /// using a new space. It's faster than the native fullscreen mode since it

View File

@ -170,6 +170,7 @@ const ModeEntry = struct {
/// valuable to redocument them all here. /// valuable to redocument them all here.
const entries: []const ModeEntry = &.{ const entries: []const ModeEntry = &.{
// ANSI // ANSI
.{ .name = "disable_keyboard", .value = 2, .ansi = true }, // KAM
.{ .name = "insert", .value = 4, .ansi = true }, .{ .name = "insert", .value = 4, .ansi = true },
// DEC // DEC

View File

@ -0,0 +1,28 @@
import VTMode from "@/components/VTMode";
# Keyboard Action Mode (KAM)
<VTMode value={2} ansi={true} />
Disable all keyboard input.
This mode is unset as part of both [full reset (RIS)](/vt/ris)
and [soft reset (DECSTR)](/vt/decstr).
A poorly behaved terminal program can lock the terminal emulator
using this command. Terminal emulators should provide a mechanism
to reset this or outright disable it.
## Validation
### KAM V-1: Disable Keyboard Input
```bash
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "Keyboard input is now disabled.\n"
printf "\033[2h"
sleep 5
printf "\033[2l"
printf "Keyboard input is re-enabled.\n"
```

View File

@ -0,0 +1,18 @@
export default function VTMode({
value,
ansi = false,
}: {
value: number;
ansi: boolean;
}) {
return (
<div className="flex my-2.5">
<div className="border px-1 grid grid-rows-2 grid-cols-1 text-center">
<div>
{ansi ? "?" : ""}
{value}
</div>
</div>
</div>
);
}