diff --git a/src/terminal/new/Screen.zig b/src/terminal/new/Screen.zig index 252b757fc..f4581b722 100644 --- a/src/terminal/new/Screen.zig +++ b/src/terminal/new/Screen.zig @@ -61,6 +61,11 @@ pub const Cursor = struct { x: size.CellCountInt, y: size.CellCountInt, + /// The visual style of the cursor. This defaults to block because + /// it has to default to something, but users of this struct are + /// encouraged to set their own default. + cursor_style: CursorStyle = .block, + /// The "last column flag (LCF)" as its called. If this is set then the /// next character print will force a soft-wrap. pending_wrap: bool = false, @@ -87,6 +92,11 @@ pub const Cursor = struct { page_cell: *pagepkg.Cell, }; +/// The visual style of the cursor. Whether or not it blinks +/// is determined by mode 12 (modes.zig). This mode is synchronized +/// with CSI q, the same as xterm. +pub const CursorStyle = enum { bar, block, underline }; + /// Saved cursor state. pub const SavedCursor = struct { x: size.CellCountInt, @@ -445,6 +455,11 @@ pub fn scrollClear(self: *Screen) !void { self.kitty_images.dirty = true; } +/// Returns true if the viewport is scrolled to the bottom of the screen. +pub fn viewportIsBottom(self: Screen) bool { + return self.pages.viewport == .active; +} + /// Erase the region specified by tl and br, inclusive. This will physically /// erase the rows meaning the memory will be reclaimed (if the underlying /// page is empty) and other rows will be shifted up. @@ -808,6 +823,22 @@ pub fn manualStyleUpdate(self: *Screen) !void { self.cursor.style_ref = &md.ref; } +/// Returns the raw text associated with a selection. This will unwrap +/// soft-wrapped edges. The returned slice is owned by the caller and allocated +/// using alloc, not the allocator associated with the screen (unless they match). +pub fn selectionString( + self: *Screen, + alloc: Allocator, + sel: Selection, + trim: bool, +) ![:0]const u8 { + _ = self; + _ = alloc; + _ = sel; + _ = trim; + @panic("TODO"); +} + /// Dump the screen to a string. The writer given should be buffered; /// this function does not attempt to efficiently write and generally writes /// one byte at a time. diff --git a/src/terminal/new/Terminal.zig b/src/terminal/new/Terminal.zig index 891355640..51f5ddf58 100644 --- a/src/terminal/new/Terminal.zig +++ b/src/terminal/new/Terminal.zig @@ -1885,6 +1885,21 @@ pub fn decaln(self: *Terminal) !void { } } +/// Execute a kitty graphics command. The buf is used to populate with +/// the response that should be sent as an APC sequence. The response will +/// be a full, valid APC sequence. +/// +/// If an error occurs, the caller should response to the pty that a +/// an error occurred otherwise the behavior of the graphics protocol is +/// undefined. +pub fn kittyGraphics( + self: *Terminal, + alloc: Allocator, + cmd: *kitty.graphics.Command, +) ?kitty.graphics.Response { + return kitty.graphics.execute(alloc, self, cmd); +} + /// Set a style attribute. pub fn setAttribute(self: *Terminal, attr: sgr.Attribute) !void { try self.screen.setAttribute(attr); diff --git a/src/terminal/new/main.zig b/src/terminal/new/main.zig index 312dafc16..22e66466f 100644 --- a/src/terminal/new/main.zig +++ b/src/terminal/new/main.zig @@ -1,8 +1,10 @@ const builtin = @import("builtin"); pub const page = @import("page.zig"); +pub const point = @import("point.zig"); pub const PageList = @import("PageList.zig"); pub const Terminal = @import("Terminal.zig"); +pub const Screen = @import("Screen.zig"); pub const Page = page.Page; test { @@ -11,9 +13,6 @@ test { // todo: make top-level imports _ = @import("bitmap_allocator.zig"); _ = @import("hash_map.zig"); - _ = @import("page.zig"); - _ = @import("Screen.zig"); - _ = @import("point.zig"); _ = @import("size.zig"); _ = @import("style.zig"); } diff --git a/src/terminal/new/point.zig b/src/terminal/new/point.zig index e0961e201..00350f265 100644 --- a/src/terminal/new/point.zig +++ b/src/terminal/new/point.zig @@ -2,8 +2,7 @@ const std = @import("std"); const Allocator = std.mem.Allocator; const assert = std.debug.assert; -/// The possible reference locations for a point. When someone says -/// "(42, 80)" in the context of a terminal, that could mean multiple +/// The possible reference locations for a point. When someone says "(42, 80)" in the context of a terminal, that could mean multiple /// things: it is in the current visible viewport? the current active /// area of the screen where the cursor is? the entire scrollback history? /// etc. This tag is used to differentiate those cases. @@ -69,3 +68,24 @@ pub const Point = union(Tag) { }; } }; + +/// A point in the terminal that is always in the viewport area. +pub const Viewport = struct { + x: usize = 0, + y: usize = 0, + + pub fn eql(self: Viewport, other: Viewport) bool { + return self.x == other.x and self.y == other.y; + } + + const TerminalScreen = @import("Screen.zig"); + pub fn toScreen(_: Viewport, _: *const TerminalScreen) Screen { + @panic("TODO"); + } +}; + +/// A point in the terminal that is in relation to the entire screen. +pub const Screen = struct { + x: usize = 0, + y: usize = 0, +};