diff --git a/.gitignore b/.gitignore index cc549e044..8e7a003ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,9 @@ +*~ +.*.swp +.swp +*.log .DS_Store -.vscode +.vscode/ .direnv/ .flatpak-builder/ zig-cache/ diff --git a/src/Surface.zig b/src/Surface.zig index 31a032647..9b89f6618 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -2169,19 +2169,19 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool .reload_config => try self.app.reloadConfig(self.rt_app), - .csi => |data| { - // We need to send the CSI sequence as a single write request. + .csi, .esc => |data| { + // 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 // as two literals. 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.alloc, full_data, ), .{ .forever = {} }); try self.io_thread.wakeup.notify(); - // CSI triggers a scroll. + // CSI/ESC triggers a scroll. { self.renderer_state.mutex.lock(); defer self.renderer_state.mutex.unlock(); diff --git a/src/config/Config.zig b/src/config/Config.zig index 7f2218ef0..ba29ed6f2 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -321,6 +321,8 @@ command: ?[]const u8 = null, /// is removed, and the key will be sent through to the child command /// if it is printable. /// - "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: /// diff --git a/src/input/Binding.zig b/src/input/Binding.zig index c326b21b0..9198e2f53 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -117,6 +117,9 @@ pub const Action = union(enum) { /// without the CSI header ("ESC ]" or "\x1b]"). csi: []const u8, + /// Send an ESC sequence. + esc: []const u8, + /// Send data to the pty depending on whether cursor key mode is /// enabled ("application") or disabled ("normal"). cursor_key: CursorKey, @@ -665,6 +668,12 @@ test "parse: action with string" { try testing.expect(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" {