From c1469eb7b212f4663d90c155983d527d4b3d7c3c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 24 Oct 2023 21:56:38 -0700 Subject: [PATCH] inspector: track lots of metadata for vt events --- src/inspector/Inspector.zig | 131 ++++++++++++------------------------ src/inspector/main.zig | 1 + src/inspector/termio.zig | 19 +++++- src/terminal/Terminal.zig | 2 +- 4 files changed, 62 insertions(+), 91 deletions(-) diff --git a/src/inspector/Inspector.zig b/src/inspector/Inspector.zig index 432a56428..3ec57874d 100644 --- a/src/inspector/Inspector.zig +++ b/src/inspector/Inspector.zig @@ -299,94 +299,7 @@ fn renderScreenWindow(self: *Inspector) void { ); defer cimgui.c.igEndTable(); - { - cimgui.c.igTableNextRow(cimgui.c.ImGuiTableRowFlags_None, 0); - { - _ = cimgui.c.igTableSetColumnIndex(0); - cimgui.c.igText("Position (x, y)"); - } - { - _ = cimgui.c.igTableSetColumnIndex(1); - cimgui.c.igText("(%d, %d)", screen.cursor.x, screen.cursor.y); - } - } - - { - cimgui.c.igTableNextRow(cimgui.c.ImGuiTableRowFlags_None, 0); - { - _ = cimgui.c.igTableSetColumnIndex(0); - cimgui.c.igText("Pending Wrap"); - } - { - _ = cimgui.c.igTableSetColumnIndex(1); - cimgui.c.igText("%s", if (screen.cursor.pending_wrap) "true".ptr else "false".ptr); - } - } - - // If we have a color then we show the color - color: { - cimgui.c.igTableNextRow(cimgui.c.ImGuiTableRowFlags_None, 0); - _ = cimgui.c.igTableSetColumnIndex(0); - cimgui.c.igText("Foreground Color"); - _ = cimgui.c.igTableSetColumnIndex(1); - if (!screen.cursor.pen.attrs.has_fg) { - cimgui.c.igText("default"); - break :color; - } - - var color: [3]f32 = .{ - @as(f32, @floatFromInt(screen.cursor.pen.fg.r)) / 255, - @as(f32, @floatFromInt(screen.cursor.pen.fg.g)) / 255, - @as(f32, @floatFromInt(screen.cursor.pen.fg.b)) / 255, - }; - _ = cimgui.c.igColorEdit3( - "color_fg", - &color, - cimgui.c.ImGuiColorEditFlags_NoPicker | - cimgui.c.ImGuiColorEditFlags_NoLabel, - ); - } - color: { - cimgui.c.igTableNextRow(cimgui.c.ImGuiTableRowFlags_None, 0); - _ = cimgui.c.igTableSetColumnIndex(0); - cimgui.c.igText("Background Color"); - _ = cimgui.c.igTableSetColumnIndex(1); - if (!screen.cursor.pen.attrs.has_bg) { - cimgui.c.igText("default"); - break :color; - } - - var color: [3]f32 = .{ - @as(f32, @floatFromInt(screen.cursor.pen.bg.r)) / 255, - @as(f32, @floatFromInt(screen.cursor.pen.bg.g)) / 255, - @as(f32, @floatFromInt(screen.cursor.pen.bg.b)) / 255, - }; - _ = cimgui.c.igColorEdit3( - "color_bg", - &color, - cimgui.c.ImGuiColorEditFlags_NoPicker | - cimgui.c.ImGuiColorEditFlags_NoLabel, - ); - } - - // Boolean styles - const styles = .{ - "bold", "italic", "faint", "blink", - "inverse", "invisible", "protected", "strikethrough", - }; - inline for (styles) |style| style: { - if (!@field(screen.cursor.pen.attrs, style)) break :style; - - cimgui.c.igTableNextRow(cimgui.c.ImGuiTableRowFlags_None, 0); - { - _ = cimgui.c.igTableSetColumnIndex(0); - cimgui.c.igText(style.ptr); - } - { - _ = cimgui.c.igTableSetColumnIndex(1); - cimgui.c.igText("true"); - } - } + inspector.cursor.renderInTable(&screen.cursor); } // table cimgui.c.igTextDisabled("(Any styles not shown are not currently set)"); @@ -1167,11 +1080,53 @@ fn renderTermioWindow(self: *Inspector) void { cimgui.c.igTableNextRow(cimgui.c.ImGuiTableRowFlags_None, 0); _ = cimgui.c.igTableNextColumn(); + _ = cimgui.c.igSelectable_BoolPtr( + "##select", + &ev.imgui_selected, + cimgui.c.ImGuiSelectableFlags_SpanAllColumns, + .{ .x = 0, .y = 0 }, + ); + cimgui.c.igSameLine(0, 0); cimgui.c.igText("%d", ev.seq); _ = cimgui.c.igTableNextColumn(); cimgui.c.igText("%s", @tagName(ev.kind).ptr); _ = cimgui.c.igTableNextColumn(); cimgui.c.igText("%s", ev.str.ptr); + + // If the event is selected, we render info about it. For now + // we put this in the last column because thats the widest and + // imgui has no way to make a column span. + if (ev.imgui_selected) { + { + _ = cimgui.c.igBeginTable( + "details", + 2, + cimgui.c.ImGuiTableFlags_None, + .{ .x = 0, .y = 0 }, + 0, + ); + defer cimgui.c.igEndTable(); + inspector.cursor.renderInTable(&ev.cursor); + + { + cimgui.c.igTableNextRow(cimgui.c.ImGuiTableRowFlags_None, 0); + { + _ = cimgui.c.igTableSetColumnIndex(0); + cimgui.c.igText("Scroll Region"); + } + { + _ = cimgui.c.igTableSetColumnIndex(1); + cimgui.c.igText( + "T=%d B=%d L=%d R=%d", + ev.scrolling_region.top, + ev.scrolling_region.bottom, + ev.scrolling_region.left, + ev.scrolling_region.right, + ); + } + } + } + } } } // table diff --git a/src/inspector/main.zig b/src/inspector/main.zig index db061088d..57612ddee 100644 --- a/src/inspector/main.zig +++ b/src/inspector/main.zig @@ -1,3 +1,4 @@ +pub const cursor = @import("cursor.zig"); pub const key = @import("key.zig"); pub const termio = @import("termio.zig"); pub const Inspector = @import("Inspector.zig"); diff --git a/src/inspector/termio.zig b/src/inspector/termio.zig index bd202c13d..8b6665109 100644 --- a/src/inspector/termio.zig +++ b/src/inspector/termio.zig @@ -24,10 +24,21 @@ pub const VTEvent = struct { /// store the raw event. str: [:0]const u8, + /// Various metadata at the time of the event (before processing). + cursor: terminal.Screen.Cursor, + scrolling_region: terminal.Terminal.ScrollingRegion, + + /// imgui selection state + imgui_selected: bool = false, + const Kind = enum { print, execute, csi, esc, osc, dcs, apc }; /// Initiaze the event information for the given parser action. - pub fn init(alloc: Allocator, action: terminal.Parser.Action) !VTEvent { + pub fn init( + alloc: Allocator, + surface: *Surface, + action: terminal.Parser.Action, + ) !VTEvent { var buf = std.ArrayList(u8).init(alloc); defer buf.deinit(); try encodeAction(buf.writer(), action); @@ -44,9 +55,13 @@ pub const VTEvent = struct { .apc_start, .apc_put, .apc_end => .apc, }; + const t = surface.renderer_state.terminal; + return .{ .kind = kind, .str = str, + .cursor = t.screen.cursor, + .scrolling_region = t.scrolling_region, }; } @@ -111,7 +126,7 @@ pub const VTHandler = struct { // Build our event const alloc = self.surface.alloc; - var ev = try VTEvent.init(alloc, action); + var ev = try VTEvent.init(alloc, self.surface, action); ev.seq = self.current_seq; self.current_seq +%= 1; errdefer ev.deinit(alloc); diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index ebecc1479..4b3503072 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -136,7 +136,7 @@ pub const MouseFormat = enum(u3) { /// Scrolling region is the area of the screen designated where scrolling /// occurs. Wen scrolling the screen, only this viewport is scrolled. -const ScrollingRegion = struct { +pub const ScrollingRegion = struct { // Top and bottom of the scroll region (0-indexed) // Precondition: top < bottom top: usize,