diff --git a/src/Surface.zig b/src/Surface.zig index c917d07ee..2ec42f026 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -2271,7 +2271,7 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool .reload_config => try self.app.reloadConfig(self.rt_app), - .csi, .esc, .text => |data| { + .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. @@ -2279,10 +2279,6 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool const full_data = switch (action) { .csi => try std.fmt.bufPrint(&buf, "\x1b[{s}", .{data}), .esc => try std.fmt.bufPrint(&buf, "\x1b{s}", .{data}), - .text => configpkg.string.parse(&buf, data) catch |err| { - log.warn("error parsing text binding text={s} err={}", .{ data, err }); - return true; - }, else => unreachable, }; _ = self.io_thread.mailbox.push(try termio.Message.writeReq( @@ -2301,6 +2297,34 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool } }, + .text => |data| { + // For text we always allocate just because its easier to + // handle all cases that way. + var buf = try self.alloc.alloc(u8, data.len); + defer self.alloc.free(buf); + const text = configpkg.string.parse(buf, data) catch |err| { + log.warn( + "error parsing text binding text={s} err={}", + .{ data, err }, + ); + return true; + }; + _ = self.io_thread.mailbox.push(try termio.Message.writeReq( + self.alloc, + text, + ), .{ .forever = {} }); + try self.io_thread.wakeup.notify(); + + // Text triggers a scroll. + { + self.renderer_state.mutex.lock(); + defer self.renderer_state.mutex.unlock(); + self.scrollToBottom() catch |err| { + log.warn("error scrolling to bottom err={}", .{err}); + }; + } + }, + .cursor_key => |ck| { // We send a different sequence depending on if we're // in cursor keys mode. We're in "normal" mode if cursor diff --git a/src/input/Binding.zig b/src/input/Binding.zig index dba892994..460e39dfc 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -134,10 +134,10 @@ pub const Action = union(enum) { /// Send an ESC sequence. esc: []const u8, - // Send the given text. Uses Zig string literal syntax. The maximum - // length of the string is 128 bytes. This is currently not validated. - // If the text is invalid (i.e. contains an invalid escape sequence), - // the error will currently only show up in logs. + // Send the given text. Uses Zig string literal syntax. This is + // currently not validated. If the text is invalid (i.e. contains + // an invalid escape sequence), the error will currently only show + // up in logs. text: []const u8, /// Send data to the pty depending on whether cursor key mode is