diff --git a/src/Surface.zig b/src/Surface.zig index 6ffc001e9..573f131e0 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -2143,19 +2143,19 @@ pub fn mouseButtonCallback( { const pos = try self.rt_surface.getCursorPos(); const point = self.posToViewport(pos.x, pos.y); - // TODO(paged-terminal) - // const cell = self.renderer_state.terminal.screen.getCell( - // .viewport, - // point.y, - // point.x, - // ); + const screen = &self.renderer_state.terminal.screen; + const p = screen.pages.pin(.{ .active = point }) orelse { + log.warn("failed to get pin for clicked point", .{}); + return; + }; - insp.cell = .{ - .selected = .{ - .row = point.y, - .col = point.x, - //.cell = cell, - }, + insp.cell.select( + self.alloc, + p, + point.x, + point.y, + ) catch |err| { + log.warn("error selecting cell for inspector err={}", .{err}); }; return; } diff --git a/src/inspector/Inspector.zig b/src/inspector/Inspector.zig index 4262dccb4..446dcee11 100644 --- a/src/inspector/Inspector.zig +++ b/src/inspector/Inspector.zig @@ -4,6 +4,7 @@ const Inspector = @This(); const std = @import("std"); +const assert = std.debug.assert; const Allocator = std.mem.Allocator; const builtin = @import("builtin"); const cimgui = @import("cimgui"); @@ -62,18 +63,47 @@ const CellInspect = union(enum) { selected: Selected, const Selected = struct { + alloc: Allocator, row: usize, col: usize, - // TODO(paged-terminal) - //cell: terminal.Screen.Cell, + cell: inspector.Cell, }; + pub fn deinit(self: *CellInspect) void { + switch (self.*) { + .idle, .requested => {}, + .selected => |*v| v.cell.deinit(v.alloc), + } + } + pub fn request(self: *CellInspect) void { switch (self.*) { - .idle, .selected => self.* = .requested, + .idle => self.* = .requested, + .selected => |*v| { + v.cell.deinit(v.alloc); + self.* = .requested; + }, .requested => {}, } } + + pub fn select( + self: *CellInspect, + alloc: Allocator, + pin: terminal.Pin, + x: usize, + y: usize, + ) !void { + assert(self.* == .requested); + const cell = try inspector.Cell.init(alloc, pin); + errdefer cell.deinit(alloc); + self.* = .{ .selected = .{ + .alloc = alloc, + .row = y, + .col = x, + .cell = cell, + } }; + } }; /// Setup the ImGui state. This requires an ImGui context to be set. @@ -136,6 +166,8 @@ pub fn init(surface: *Surface) !Inspector { } pub fn deinit(self: *Inspector) void { + self.cell.deinit(); + { var it = self.key_events.iterator(.forward); while (it.next()) |v| v.deinit(self.surface.alloc); diff --git a/src/inspector/main.zig b/src/inspector/main.zig index 920491dd8..c80384182 100644 --- a/src/inspector/main.zig +++ b/src/inspector/main.zig @@ -1,7 +1,10 @@ const std = @import("std"); +pub const cell = @import("cell.zig"); pub const cursor = @import("cursor.zig"); pub const key = @import("key.zig"); pub const termio = @import("termio.zig"); + +pub const Cell = cell.Cell; pub const Inspector = @import("Inspector.zig"); test { diff --git a/src/terminal/main.zig b/src/terminal/main.zig index c0863f1f4..ea2e65240 100644 --- a/src/terminal/main.zig +++ b/src/terminal/main.zig @@ -7,6 +7,7 @@ const stream = @import("stream.zig"); const ansi = @import("ansi.zig"); const csi = @import("csi.zig"); const sgr = @import("sgr.zig"); +const style = @import("style.zig"); pub const apc = @import("apc.zig"); pub const dcs = @import("dcs.zig"); pub const osc = @import("osc.zig"); @@ -34,6 +35,7 @@ pub const Pin = PageList.Pin; pub const Screen = @import("Screen.zig"); pub const ScreenType = Terminal.ScreenType; pub const Selection = @import("Selection.zig"); +pub const Style = style.Style; pub const Terminal = @import("Terminal.zig"); pub const Stream = stream.Stream; pub const Cursor = Screen.Cursor; @@ -57,5 +59,4 @@ test { _ = @import("bitmap_allocator.zig"); _ = @import("hash_map.zig"); _ = @import("size.zig"); - _ = @import("style.zig"); }