mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 00:36:07 +03:00
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:
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,5 +1,9 @@
|
||||
*~
|
||||
.*.swp
|
||||
.swp
|
||||
*.log
|
||||
.DS_Store
|
||||
.vscode
|
||||
.vscode/
|
||||
.direnv/
|
||||
.flatpak-builder/
|
||||
zig-cache/
|
||||
|
@ -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();
|
||||
|
@ -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:
|
||||
///
|
||||
|
@ -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" {
|
||||
|
Reference in New Issue
Block a user