terminal: handle set application keypad mode (both ESC and modes)

This commit is contained in:
Mitchell Hashimoto
2023-08-12 22:01:38 -07:00
parent c0736676ce
commit d94474463b
5 changed files with 21 additions and 1 deletions

View File

@ -1114,6 +1114,7 @@ pub fn keyCallback(
// We'll need to know these values here on.
self.renderer_state.mutex.lock();
const cursor_key_application = self.io.terminal.modes.cursor_keys;
const keypad_key_application = self.io.terminal.modes.keypad_keys;
self.renderer_state.mutex.unlock();
// Check if we're processing a function key.
@ -1126,7 +1127,8 @@ pub fn keyCallback(
switch (entry.keypad) {
.any => {},
else => {}, // TODO
.normal => if (keypad_key_application) continue,
.application => if (!keypad_key_application) continue,
}
switch (entry.modify_other_keys) {

View File

@ -90,6 +90,7 @@ modes: packed struct {
deccolm: bool = false, // 3,
deccolm_supported: bool = false, // 40
keypad_keys: bool = false, // 66
focus_event: bool = false, // 1004
mouse_alternate_scroll: bool = true, // 1007

View File

@ -88,6 +88,9 @@ pub const Mode = enum(u16) {
/// mode ?3 is set or unset.
enable_mode_3 = 40,
/// DECNKM. Sets application keypad mode if enabled.
keypad_keys = 66,
/// "Normal" mouse events: click/release, scroll
mouse_event_normal = 1000,

View File

@ -765,6 +765,16 @@ pub fn Stream(comptime Handler: type) type {
},
} else log.warn("unimplemented invokeCharset: {}", .{action}),
// Set application keypad mode
'=' => if (@hasDecl(T, "setMode")) {
try self.handler.setMode(.keypad_keys, true);
} else log.warn("unimplemented setMode: {}", .{action}),
// Reset application keypad mode
'>' => if (@hasDecl(T, "setMode")) {
try self.handler.setMode(.keypad_keys, false);
} else log.warn("unimplemented setMode: {}", .{action}),
else => if (@hasDecl(T, "escUnimplemented"))
try self.handler.escUnimplemented(action)
else

View File

@ -1193,6 +1193,10 @@ const StreamHandler = struct {
self.terminal.modes.cursor_keys = enabled;
},
.keypad_keys => {
self.terminal.modes.keypad_keys = enabled;
},
.insert => {
self.terminal.modes.insert = enabled;
},