Merge pull request #790 from mitchellh/slonik-az/keybind-esc-seq

feat: keybind escape sequence action "esc:text" similar to "csi:text"
This commit is contained in:
Mitchell Hashimoto
2023-11-02 21:30:00 -07:00
committed by GitHub
4 changed files with 20 additions and 5 deletions

6
.gitignore vendored
View File

@ -1,5 +1,9 @@
*~
.*.swp
.swp
*.log
.DS_Store .DS_Store
.vscode .vscode/
.direnv/ .direnv/
.flatpak-builder/ .flatpak-builder/
zig-cache/ zig-cache/

View File

@ -2169,19 +2169,19 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
.reload_config => try self.app.reloadConfig(self.rt_app), .reload_config => try self.app.reloadConfig(self.rt_app),
.csi => |data| { .csi, .esc => |data| {
// We need to send the CSI sequence as a single write request. // We need to send the CSI/ESC sequence as a single write request.
// If you split it across two then the shell can interpret it // If you split it across two then the shell can interpret it
// as two literals. // as two literals.
var buf: [128]u8 = undefined; var buf: [128]u8 = undefined;
const full_data = try std.fmt.bufPrint(&buf, "\x1b[{s}", .{data}); const full_data = try std.fmt.bufPrint(&buf, "\x1b{s}{s}", .{if(action==.csi)"["else"", data});
_ = self.io_thread.mailbox.push(try termio.Message.writeReq( _ = self.io_thread.mailbox.push(try termio.Message.writeReq(
self.alloc, self.alloc,
full_data, full_data,
), .{ .forever = {} }); ), .{ .forever = {} });
try self.io_thread.wakeup.notify(); try self.io_thread.wakeup.notify();
// CSI triggers a scroll. // CSI/ESC triggers a scroll.
{ {
self.renderer_state.mutex.lock(); self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock(); defer self.renderer_state.mutex.unlock();

View File

@ -321,6 +321,8 @@ command: ?[]const u8 = null,
/// is removed, and the key will be sent through to the child command /// is removed, and the key will be sent through to the child command
/// if it is printable. /// if it is printable.
/// - "csi:text" - Send a CSI sequence. i.e. "csi:A" sends "cursor up". /// - "csi:text" - Send a CSI sequence. i.e. "csi:A" sends "cursor up".
/// - "esc:text" - Send an Escape sequence. i.e. "esc:d" deletes to the
/// end of the word to the right.
/// ///
/// Some notes for the action: /// Some notes for the action:
/// ///

View File

@ -117,6 +117,9 @@ pub const Action = union(enum) {
/// without the CSI header ("ESC ]" or "\x1b]"). /// without the CSI header ("ESC ]" or "\x1b]").
csi: []const u8, csi: []const u8,
/// Send an ESC sequence.
esc: []const u8,
/// Send data to the pty depending on whether cursor key mode is /// Send data to the pty depending on whether cursor key mode is
/// enabled ("application") or disabled ("normal"). /// enabled ("application") or disabled ("normal").
cursor_key: CursorKey, cursor_key: CursorKey,
@ -665,6 +668,12 @@ test "parse: action with string" {
try testing.expect(binding.action == .csi); try testing.expect(binding.action == .csi);
try testing.expectEqualStrings("A", binding.action.csi); try testing.expectEqualStrings("A", binding.action.csi);
} }
// parameter
{
const binding = try parse("a=esc:A");
try testing.expect(binding.action == .esc);
try testing.expectEqualStrings("A", binding.action.esc);
}
} }
test "parse: action with enum" { test "parse: action with enum" {