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 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;
}

View File

@ -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);

View File

@ -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 {

View File

@ -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");
}