From 25d84d697aa981df77fcb5f264a46e5cbcfdbca0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 8 Mar 2024 20:47:16 -0800 Subject: [PATCH] termio/exec: get compiler errors gone --- src/renderer/size.zig | 3 +- src/terminal/kitty/graphics_storage.zig | 9 ++- src/terminal/main.zig | 1 + src/termio/Exec.zig | 75 +++++++++++++++---------- src/termio/Thread.zig | 4 +- 5 files changed, 58 insertions(+), 34 deletions(-) diff --git a/src/renderer/size.zig b/src/renderer/size.zig index d3047bb86..4f6b5fc5b 100644 --- a/src/renderer/size.zig +++ b/src/renderer/size.zig @@ -1,6 +1,7 @@ const std = @import("std"); const Allocator = std.mem.Allocator; const font = @import("../font/main.zig"); +const terminal = @import("../terminal/main.zig"); const log = std.log.scoped(.renderer_size); @@ -61,7 +62,7 @@ pub const ScreenSize = struct { /// The dimensions of the grid itself, in rows/columns units. pub const GridSize = struct { - const Unit = u32; + const Unit = terminal.size.CellCountInt; columns: Unit = 0, rows: Unit = 0, diff --git a/src/terminal/kitty/graphics_storage.zig b/src/terminal/kitty/graphics_storage.zig index bde44074b..d84a0a122 100644 --- a/src/terminal/kitty/graphics_storage.zig +++ b/src/terminal/kitty/graphics_storage.zig @@ -77,10 +77,15 @@ pub const ImageStorage = struct { /// can be loaded. If this limit is lower, this will do an eviction /// if necessary. If the value is zero, then Kitty image protocol will /// be disabled. - pub fn setLimit(self: *ImageStorage, alloc: Allocator, limit: usize) !void { + pub fn setLimit( + self: *ImageStorage, + alloc: Allocator, + s: *terminal.Screen, + limit: usize, + ) !void { // Special case disabling by quickly deleting all if (limit == 0) { - self.deinit(alloc); + self.deinit(alloc, s); self.* = .{}; } diff --git a/src/terminal/main.zig b/src/terminal/main.zig index 25a97cb2e..1d9687174 100644 --- a/src/terminal/main.zig +++ b/src/terminal/main.zig @@ -17,6 +17,7 @@ pub const kitty = @import("kitty.zig"); pub const modes = @import("modes.zig"); pub const page = @import("page.zig"); pub const parse_table = @import("parse_table.zig"); +pub const size = @import("size.zig"); pub const x11_color = @import("x11_color.zig"); pub const Charset = charsets.Charset; diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 490d4cd5d..3e0ff071b 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -145,8 +145,16 @@ pub fn init(alloc: Allocator, opts: termio.Options) !Exec { } // Set the image size limits - try term.screen.kitty_images.setLimit(alloc, opts.config.image_storage_limit); - try term.secondary_screen.kitty_images.setLimit(alloc, opts.config.image_storage_limit); + try term.screen.kitty_images.setLimit( + alloc, + &term.screen, + opts.config.image_storage_limit, + ); + try term.secondary_screen.kitty_images.setLimit( + alloc, + &term.secondary_screen, + opts.config.image_storage_limit, + ); // Set default cursor blink settings term.modes.set( @@ -395,10 +403,12 @@ pub fn changeConfig(self: *Exec, config: *DerivedConfig) !void { // Set the image size limits try self.terminal.screen.kitty_images.setLimit( self.alloc, + &self.terminal.screen, config.image_storage_limit, ); try self.terminal.secondary_screen.kitty_images.setLimit( self.alloc, + &self.terminal.secondary_screen, config.image_storage_limit, ); } @@ -464,11 +474,15 @@ pub fn clearScreen(self: *Exec, history: bool) !void { if (self.terminal.active_screen == .alternate) return; // Clear our scrollback - if (history) self.terminal.eraseDisplay(self.alloc, .scrollback, false); + if (history) self.terminal.eraseDisplay(.scrollback, false); // If we're not at a prompt, we just delete above the cursor. if (!self.terminal.cursorIsAtPrompt()) { - try self.terminal.screen.clear(.above_cursor); + self.terminal.screen.clearRows( + .{ .active = .{ .y = 0 } }, + .{ .active = .{ .y = self.terminal.screen.cursor.y - 1 } }, + false, + ); return; } @@ -478,7 +492,7 @@ pub fn clearScreen(self: *Exec, history: bool) !void { // clear the full screen in the next eraseDisplay call. self.terminal.markSemanticPrompt(.command); assert(!self.terminal.cursorIsAtPrompt()); - self.terminal.eraseDisplay(self.alloc, .complete, false); + self.terminal.eraseDisplay(.complete, false); } // If we reached here it means we're at a prompt, so we send a form-feed. @@ -494,17 +508,20 @@ pub fn scrollViewport(self: *Exec, scroll: terminal.Terminal.ScrollViewport) !vo /// Jump the viewport to the prompt. pub fn jumpToPrompt(self: *Exec, delta: isize) !void { - const wakeup: bool = wakeup: { - self.renderer_state.mutex.lock(); - defer self.renderer_state.mutex.unlock(); - break :wakeup self.terminal.screen.jump(.{ - .prompt_delta = delta, - }); - }; - - if (wakeup) { - try self.renderer_wakeup.notify(); - } + _ = self; + _ = delta; + // TODO(paged-terminal) + // const wakeup: bool = wakeup: { + // self.renderer_state.mutex.lock(); + // defer self.renderer_state.mutex.unlock(); + // break :wakeup self.terminal.screen.jump(.{ + // .prompt_delta = delta, + // }); + // }; + // + // if (wakeup) { + // try self.renderer_wakeup.notify(); + // } } /// Called when the child process exited abnormally but before @@ -2007,7 +2024,7 @@ const StreamHandler = struct { try self.queueRender(); } - self.terminal.eraseDisplay(self.alloc, mode, protected); + self.terminal.eraseDisplay(mode, protected); } pub fn eraseLine(self: *StreamHandler, mode: terminal.EraseLine, protected: bool) !void { @@ -2015,7 +2032,7 @@ const StreamHandler = struct { } pub fn deleteChars(self: *StreamHandler, count: usize) !void { - try self.terminal.deleteChars(count); + self.terminal.deleteChars(count); } pub fn eraseChars(self: *StreamHandler, count: usize) !void { @@ -2023,7 +2040,7 @@ const StreamHandler = struct { } pub fn insertLines(self: *StreamHandler, count: usize) !void { - try self.terminal.insertLines(count); + self.terminal.insertLines(count); } pub fn insertBlanks(self: *StreamHandler, count: usize) !void { @@ -2031,11 +2048,11 @@ const StreamHandler = struct { } pub fn deleteLines(self: *StreamHandler, count: usize) !void { - try self.terminal.deleteLines(count); + self.terminal.deleteLines(count); } pub fn reverseIndex(self: *StreamHandler) !void { - try self.terminal.reverseIndex(); + self.terminal.reverseIndex(); } pub fn index(self: *StreamHandler) !void { @@ -2183,9 +2200,9 @@ const StreamHandler = struct { }; if (enabled) - self.terminal.alternateScreen(self.alloc, opts) + self.terminal.alternateScreen(opts) else - self.terminal.primaryScreen(self.alloc, opts); + self.terminal.primaryScreen(opts); // Schedule a render since we changed screens try self.queueRender(); @@ -2198,9 +2215,9 @@ const StreamHandler = struct { }; if (enabled) - self.terminal.alternateScreen(self.alloc, opts) + self.terminal.alternateScreen(opts) else - self.terminal.primaryScreen(self.alloc, opts); + self.terminal.primaryScreen(opts); // Schedule a render since we changed screens try self.queueRender(); @@ -2424,7 +2441,7 @@ const StreamHandler = struct { } pub fn restoreCursor(self: *StreamHandler) !void { - self.terminal.restoreCursor(); + try self.terminal.restoreCursor(); } pub fn enquiry(self: *StreamHandler) !void { @@ -2433,11 +2450,11 @@ const StreamHandler = struct { } pub fn scrollDown(self: *StreamHandler, count: usize) !void { - try self.terminal.scrollDown(count); + self.terminal.scrollDown(count); } pub fn scrollUp(self: *StreamHandler, count: usize) !void { - try self.terminal.scrollUp(count); + self.terminal.scrollUp(count); } pub fn setActiveStatusDisplay( @@ -2467,7 +2484,7 @@ const StreamHandler = struct { pub fn fullReset( self: *StreamHandler, ) !void { - self.terminal.fullReset(self.alloc); + self.terminal.fullReset(); try self.setMouseShape(.text); } diff --git a/src/termio/Thread.zig b/src/termio/Thread.zig index 450f32295..45b9fd1ae 100644 --- a/src/termio/Thread.zig +++ b/src/termio/Thread.zig @@ -177,7 +177,7 @@ pub fn threadMain(self: *Thread) void { \\Please free up some pty devices and try again. ; - t.eraseDisplay(alloc, .complete, false); + t.eraseDisplay(.complete, false); t.printString(str) catch {}; }, @@ -197,7 +197,7 @@ pub fn threadMain(self: *Thread) void { \\Out of memory. This terminal is non-functional. Please close it and try again. ; - t.eraseDisplay(alloc, .complete, false); + t.eraseDisplay(.complete, false); t.printString(str) catch {}; }, }