inspector: support cell pinning again

This commit is contained in:
Mitchell Hashimoto
2024-03-14 10:00:50 -07:00
parent a59d4286c7
commit 9015b7548f
4 changed files with 52 additions and 16 deletions

View File

@ -2143,19 +2143,19 @@ pub fn mouseButtonCallback(
{ {
const pos = try self.rt_surface.getCursorPos(); const pos = try self.rt_surface.getCursorPos();
const point = self.posToViewport(pos.x, pos.y); const point = self.posToViewport(pos.x, pos.y);
// TODO(paged-terminal) const screen = &self.renderer_state.terminal.screen;
// const cell = self.renderer_state.terminal.screen.getCell( const p = screen.pages.pin(.{ .active = point }) orelse {
// .viewport, log.warn("failed to get pin for clicked point", .{});
// point.y, return;
// point.x, };
// );
insp.cell = .{ insp.cell.select(
.selected = .{ self.alloc,
.row = point.y, p,
.col = point.x, point.x,
//.cell = cell, point.y,
}, ) catch |err| {
log.warn("error selecting cell for inspector err={}", .{err});
}; };
return; return;
} }

View File

@ -4,6 +4,7 @@
const Inspector = @This(); const Inspector = @This();
const std = @import("std"); const std = @import("std");
const assert = std.debug.assert;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const builtin = @import("builtin"); const builtin = @import("builtin");
const cimgui = @import("cimgui"); const cimgui = @import("cimgui");
@ -62,18 +63,47 @@ const CellInspect = union(enum) {
selected: Selected, selected: Selected,
const Selected = struct { const Selected = struct {
alloc: Allocator,
row: usize, row: usize,
col: usize, col: usize,
// TODO(paged-terminal) cell: inspector.Cell,
//cell: terminal.Screen.Cell,
}; };
pub fn deinit(self: *CellInspect) void {
switch (self.*) {
.idle, .requested => {},
.selected => |*v| v.cell.deinit(v.alloc),
}
}
pub fn request(self: *CellInspect) void { pub fn request(self: *CellInspect) void {
switch (self.*) { switch (self.*) {
.idle, .selected => self.* = .requested, .idle => self.* = .requested,
.selected => |*v| {
v.cell.deinit(v.alloc);
self.* = .requested;
},
.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. /// 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 { pub fn deinit(self: *Inspector) void {
self.cell.deinit();
{ {
var it = self.key_events.iterator(.forward); var it = self.key_events.iterator(.forward);
while (it.next()) |v| v.deinit(self.surface.alloc); while (it.next()) |v| v.deinit(self.surface.alloc);

View File

@ -1,7 +1,10 @@
const std = @import("std"); const std = @import("std");
pub const cell = @import("cell.zig");
pub const cursor = @import("cursor.zig"); pub const cursor = @import("cursor.zig");
pub const key = @import("key.zig"); pub const key = @import("key.zig");
pub const termio = @import("termio.zig"); pub const termio = @import("termio.zig");
pub const Cell = cell.Cell;
pub const Inspector = @import("Inspector.zig"); pub const Inspector = @import("Inspector.zig");
test { test {

View File

@ -7,6 +7,7 @@ const stream = @import("stream.zig");
const ansi = @import("ansi.zig"); const ansi = @import("ansi.zig");
const csi = @import("csi.zig"); const csi = @import("csi.zig");
const sgr = @import("sgr.zig"); const sgr = @import("sgr.zig");
const style = @import("style.zig");
pub const apc = @import("apc.zig"); pub const apc = @import("apc.zig");
pub const dcs = @import("dcs.zig"); pub const dcs = @import("dcs.zig");
pub const osc = @import("osc.zig"); pub const osc = @import("osc.zig");
@ -34,6 +35,7 @@ pub const Pin = PageList.Pin;
pub const Screen = @import("Screen.zig"); pub const Screen = @import("Screen.zig");
pub const ScreenType = Terminal.ScreenType; pub const ScreenType = Terminal.ScreenType;
pub const Selection = @import("Selection.zig"); pub const Selection = @import("Selection.zig");
pub const Style = style.Style;
pub const Terminal = @import("Terminal.zig"); pub const Terminal = @import("Terminal.zig");
pub const Stream = stream.Stream; pub const Stream = stream.Stream;
pub const Cursor = Screen.Cursor; pub const Cursor = Screen.Cursor;
@ -57,5 +59,4 @@ test {
_ = @import("bitmap_allocator.zig"); _ = @import("bitmap_allocator.zig");
_ = @import("hash_map.zig"); _ = @import("hash_map.zig");
_ = @import("size.zig"); _ = @import("size.zig");
_ = @import("style.zig");
} }