clear_history binding, default Cmd+K

This commit is contained in:
Mitchell Hashimoto
2023-03-03 09:27:47 -08:00
parent 7595ccf18f
commit 89d07fcd83
6 changed files with 36 additions and 0 deletions

View File

@ -896,6 +896,13 @@ pub fn keyCallback(
self.setFontSize(size); self.setFontSize(size);
}, },
.clear_screen => {
_ = self.io_thread.mailbox.push(.{
.clear_screen = .{ .history = true },
}, .{ .forever = {} });
try self.io_thread.wakeup.notify();
},
.toggle_dev_mode => if (DevMode.enabled) { .toggle_dev_mode => if (DevMode.enabled) {
DevMode.instance.visible = !DevMode.instance.visible; DevMode.instance.visible = !DevMode.instance.visible;
try self.queueRender(); try self.queueRender();

View File

@ -192,6 +192,12 @@ pub const Config = struct {
.{ .paste_from_clipboard = {} }, .{ .paste_from_clipboard = {} },
); );
try result.keybind.set.put(
alloc,
.{ .key = .k, .mods = .{ .super = true } },
.{ .clear_screen = {} },
);
try result.keybind.set.put(alloc, .{ .key = .up }, .{ .cursor_key = .{ try result.keybind.set.put(alloc, .{ .key = .up }, .{ .cursor_key = .{
.normal = "\x1b[A", .normal = "\x1b[A",
.application = "\x1bOA", .application = "\x1bOA",

View File

@ -146,6 +146,9 @@ pub const Action = union(enum) {
/// Reset the font size to the original configured size /// Reset the font size to the original configured size
reset_font_size: void, reset_font_size: void,
/// Clear the screen. This also clears all scrollback.
clear_screen: void,
/// Dev mode /// Dev mode
toggle_dev_mode: void, toggle_dev_mode: void,

View File

@ -194,6 +194,19 @@ pub fn resize(
} }
} }
/// Clear the screen.
pub fn clearScreen(self: *Exec, history: bool) !void {
// Queue form-feed ASCII code to clear the visible page.
try self.queueWrite(&[_]u8{0x0C});
// Clear our scrollback
if (history) {
self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock();
self.terminal.screen.clearHistory();
}
}
pub inline fn queueWrite(self: *Exec, data: []const u8) !void { pub inline fn queueWrite(self: *Exec, data: []const u8) !void {
const ev = self.data.?; const ev = self.data.?;

View File

@ -130,6 +130,7 @@ fn drainMailbox(self: *Thread) !void {
log.debug("mailbox message={}", .{message}); log.debug("mailbox message={}", .{message});
switch (message) { switch (message) {
.resize => |v| try self.impl.resize(v.grid_size, v.screen_size, v.padding), .resize => |v| try self.impl.resize(v.grid_size, v.screen_size, v.padding),
.clear_screen => |v| try self.impl.clearScreen(v.history),
.write_small => |v| try self.impl.queueWrite(v.data[0..v.len]), .write_small => |v| try self.impl.queueWrite(v.data[0..v.len]),
.write_stable => |v| try self.impl.queueWrite(v), .write_stable => |v| try self.impl.queueWrite(v),
.write_alloc => |v| { .write_alloc => |v| {

View File

@ -29,6 +29,12 @@ pub const Message = union(enum) {
padding: renderer.Padding, padding: renderer.Padding,
}, },
/// Clear the screen.
clear_screen: struct {
/// Include clearing the history
history: bool,
},
/// Write where the data fits in the union. /// Write where the data fits in the union.
write_small: WriteReq.Small, write_small: WriteReq.Small,