From 7073fb88f421f4c5eef0223d6722043561400d97 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 27 Jan 2026 15:32:12 -0800 Subject: [PATCH] inspector: remove cursor helper, move it to screen, style helper --- src/inspector/Inspector.zig | 10 +- src/inspector/cursor.zig | 194 -------------------------------- src/inspector/main.zig | 1 - src/inspector/screen.zig | 214 ++++++++++++++---------------------- src/inspector/style.zig | 10 +- 5 files changed, 94 insertions(+), 335 deletions(-) delete mode 100644 src/inspector/cursor.zig diff --git a/src/inspector/Inspector.zig b/src/inspector/Inspector.zig index 675538491..0b9660654 100644 --- a/src/inspector/Inspector.zig +++ b/src/inspector/Inspector.zig @@ -572,17 +572,17 @@ fn renderTermioWindow(self: *Inspector) void { // imgui has no way to make a column span. if (ev.imgui_selected) { { + inspector.screen.cursorTable( + &ev.cursor, + &self.surface.renderer_state.terminal.colors.palette.current, + ); + _ = cimgui.c.ImGui_BeginTable( "details", 2, cimgui.c.ImGuiTableFlags_None, ); defer cimgui.c.ImGui_EndTable(); - inspector.cursor.renderInTable( - &self.surface.renderer_state.terminal.colors.palette, - &ev.cursor, - ); - { cimgui.c.ImGui_TableNextRow(); { diff --git a/src/inspector/cursor.zig b/src/inspector/cursor.zig deleted file mode 100644 index 222cc140d..000000000 --- a/src/inspector/cursor.zig +++ /dev/null @@ -1,194 +0,0 @@ -const cimgui = @import("dcimgui"); -const terminal = @import("../terminal/main.zig"); -const widgets = @import("widgets.zig"); - -/// Render cursor information with a table already open. -pub fn renderInTable( - color_palette: *const terminal.color.DynamicPalette, - cursor: *const terminal.Screen.Cursor, -) void { - { - cimgui.c.ImGui_TableNextRow(); - { - _ = cimgui.c.ImGui_TableSetColumnIndex(0); - cimgui.c.ImGui_Text("Position (x, y)"); - cimgui.c.ImGui_SameLine(); - widgets.helpMarker("The current cursor position in the terminal grid (0-indexed)."); - } - { - _ = cimgui.c.ImGui_TableSetColumnIndex(1); - cimgui.c.ImGui_Text("(%d, %d)", cursor.x, cursor.y); - } - } - - { - cimgui.c.ImGui_TableNextRow(); - { - _ = cimgui.c.ImGui_TableSetColumnIndex(0); - cimgui.c.ImGui_Text("Style"); - cimgui.c.ImGui_SameLine(); - widgets.helpMarker("The visual style of the cursor (block, underline, bar, etc.)."); - } - { - _ = cimgui.c.ImGui_TableSetColumnIndex(1); - cimgui.c.ImGui_Text("%s", @tagName(cursor.cursor_style).ptr); - } - } - - { - cimgui.c.ImGui_TableNextRow(); - { - _ = cimgui.c.ImGui_TableSetColumnIndex(0); - cimgui.c.ImGui_Text("Hyperlink"); - cimgui.c.ImGui_SameLine(); - widgets.helpMarker("The active OSC8 hyperlink for newly printed characters."); - } - { - _ = cimgui.c.ImGui_TableSetColumnIndex(1); - if (cursor.hyperlink) |link| { - cimgui.c.ImGui_Text("%.*s", link.uri.len, link.uri.ptr); - } else { - cimgui.c.ImGui_TextDisabled("(none)"); - } - } - } - - cimgui.c.ImGui_TableNextRow(); - _ = cimgui.c.ImGui_TableSetColumnIndex(0); - cimgui.c.ImGui_Text("Foreground Color"); - cimgui.c.ImGui_SameLine(); - widgets.helpMarker("The foreground (text) color for newly printed characters."); - _ = cimgui.c.ImGui_TableSetColumnIndex(1); - switch (cursor.style.fg_color) { - .none => cimgui.c.ImGui_Text("default"), - .palette => |idx| { - const rgb = color_palette.current[idx]; - cimgui.c.ImGui_Text("Palette %d", idx); - var color: [3]f32 = .{ - @as(f32, @floatFromInt(rgb.r)) / 255, - @as(f32, @floatFromInt(rgb.g)) / 255, - @as(f32, @floatFromInt(rgb.b)) / 255, - }; - _ = cimgui.c.ImGui_ColorEdit3( - "color_fg", - &color, - cimgui.c.ImGuiColorEditFlags_DisplayHex | - cimgui.c.ImGuiColorEditFlags_NoPicker | - cimgui.c.ImGuiColorEditFlags_NoLabel, - ); - }, - - .rgb => |rgb| { - var color: [3]f32 = .{ - @as(f32, @floatFromInt(rgb.r)) / 255, - @as(f32, @floatFromInt(rgb.g)) / 255, - @as(f32, @floatFromInt(rgb.b)) / 255, - }; - _ = cimgui.c.ImGui_ColorEdit3( - "color_fg", - &color, - cimgui.c.ImGuiColorEditFlags_DisplayHex | - cimgui.c.ImGuiColorEditFlags_NoPicker | - cimgui.c.ImGuiColorEditFlags_NoLabel, - ); - }, - } - - cimgui.c.ImGui_TableNextRow(); - _ = cimgui.c.ImGui_TableSetColumnIndex(0); - cimgui.c.ImGui_Text("Background Color"); - cimgui.c.ImGui_SameLine(); - widgets.helpMarker("The background color for newly printed characters."); - _ = cimgui.c.ImGui_TableSetColumnIndex(1); - switch (cursor.style.bg_color) { - .none => cimgui.c.ImGui_Text("default"), - .palette => |idx| { - const rgb = color_palette.current[idx]; - cimgui.c.ImGui_Text("Palette %d", idx); - var color: [3]f32 = .{ - @as(f32, @floatFromInt(rgb.r)) / 255, - @as(f32, @floatFromInt(rgb.g)) / 255, - @as(f32, @floatFromInt(rgb.b)) / 255, - }; - _ = cimgui.c.ImGui_ColorEdit3( - "color_bg", - &color, - cimgui.c.ImGuiColorEditFlags_DisplayHex | - cimgui.c.ImGuiColorEditFlags_NoPicker | - cimgui.c.ImGuiColorEditFlags_NoLabel, - ); - }, - - .rgb => |rgb| { - var color: [3]f32 = .{ - @as(f32, @floatFromInt(rgb.r)) / 255, - @as(f32, @floatFromInt(rgb.g)) / 255, - @as(f32, @floatFromInt(rgb.b)) / 255, - }; - _ = cimgui.c.ImGui_ColorEdit3( - "color_bg", - &color, - cimgui.c.ImGuiColorEditFlags_DisplayHex | - cimgui.c.ImGuiColorEditFlags_NoPicker | - cimgui.c.ImGuiColorEditFlags_NoLabel, - ); - }, - } - - const style_flags = .{ - .{ "bold", "Text will be rendered with bold weight." }, - .{ "italic", "Text will be rendered in italic style." }, - .{ "faint", "Text will be rendered with reduced intensity." }, - .{ "blink", "Text will blink (if supported by the renderer)." }, - .{ "inverse", "Foreground and background colors are swapped." }, - .{ "invisible", "Text will be invisible (hidden)." }, - .{ "strikethrough", "Text will have a line through it." }, - }; - inline for (style_flags) |entry| entry: { - const style = entry[0]; - const help = entry[1]; - if (!@field(cursor.style.flags, style)) break :entry; - - cimgui.c.ImGui_TableNextRow(); - { - _ = cimgui.c.ImGui_TableSetColumnIndex(0); - cimgui.c.ImGui_Text(style.ptr); - cimgui.c.ImGui_SameLine(); - widgets.helpMarker(help); - } - { - _ = cimgui.c.ImGui_TableSetColumnIndex(1); - cimgui.c.ImGui_Text("true"); - } - } - - { - cimgui.c.ImGui_TableNextRow(); - { - _ = cimgui.c.ImGui_TableSetColumnIndex(0); - cimgui.c.ImGui_Text("Pending Wrap"); - cimgui.c.ImGui_SameLine(); - widgets.helpMarker("The 'last column flag' (LCF). If set, the next character will force a soft-wrap to the next line."); - } - { - _ = cimgui.c.ImGui_TableSetColumnIndex(1); - var value: bool = cursor.pending_wrap; - _ = cimgui.c.ImGui_Checkbox("##pending_wrap", &value); - } - } - - { - cimgui.c.ImGui_TableNextRow(); - { - _ = cimgui.c.ImGui_TableSetColumnIndex(0); - cimgui.c.ImGui_Text("Protected"); - cimgui.c.ImGui_SameLine(); - widgets.helpMarker("If enabled, new characters will have the protected attribute set, preventing erasure by certain sequences."); - } - { - _ = cimgui.c.ImGui_TableSetColumnIndex(1); - var value: bool = cursor.protected; - _ = cimgui.c.ImGui_Checkbox("##protected", &value); - } - } -} diff --git a/src/inspector/main.zig b/src/inspector/main.zig index b26d75088..88d11ee20 100644 --- a/src/inspector/main.zig +++ b/src/inspector/main.zig @@ -1,6 +1,5 @@ const std = @import("std"); pub const cell = @import("cell.zig"); -pub const cursor = @import("cursor.zig"); pub const key = @import("key.zig"); pub const page = @import("page.zig"); pub const screen = @import("screen.zig"); diff --git a/src/inspector/screen.zig b/src/inspector/screen.zig index 4ded2a9d8..b5d43d77e 100644 --- a/src/inspector/screen.zig +++ b/src/inspector/screen.zig @@ -4,6 +4,7 @@ const terminal = @import("../terminal/main.zig"); const inspector = @import("main.zig"); const style = @import("style.zig"); const units = @import("units.zig"); +const widgets = @import("widgets.zig"); /// Window to show screen information. pub const Window = struct { @@ -64,20 +65,10 @@ pub const Window = struct { "Cursor", cimgui.c.ImGuiTreeNodeFlags_None, )) { - { - _ = cimgui.c.ImGui_BeginTable( - "table_cursor", - 2, - cimgui.c.ImGuiTableFlags_None, - ); - defer cimgui.c.ImGui_EndTable(); - inspector.cursor.renderInTable( - data.color_palette, - &screen.cursor, - ); - } // table - - cimgui.c.ImGui_TextDisabled("(Any styles not shown are not currently set)"); + cursorTable( + &screen.cursor, + &data.color_palette.current, + ); } // cursor if (cimgui.c.ImGui_CollapsingHeader( @@ -319,24 +310,30 @@ pub const Window = struct { _ = cimgui.c.ImGui_DragIntEx("y", &self.grid_pos_y, 1.0, 0, max_y, "%d", cimgui.c.ImGuiSliderFlags_None); cimgui.c.ImGui_PopItemWidth(); - // Get pin for the cell at position - const pt: terminal.point.Point = .{ .viewport = .{ - .x = @intCast(self.grid_pos_x), - .y = @intCast(self.grid_pos_y), - } }; - cimgui.c.ImGui_Separator(); - if (pages.pin(pt)) |pin| { + const pin = pages.pin(.{ .viewport = .{ + .x = @intCast(self.grid_pos_x), + .y = @intCast(self.grid_pos_y), + } }) orelse { + cimgui.c.ImGui_TextColored( + .{ .x = 1.0, .y = 0.4, .z = 0.4, .w = 1.0 }, + "Invalid position", + ); + return; + }; + + const row_and_cell = pin.rowAndCell(); + const cell = row_and_cell.cell; + const st = pin.style(cell); + + { _ = cimgui.c.ImGui_BeginTable( "##grid_cell_table", 2, cimgui.c.ImGuiTableFlags_None, ); defer cimgui.c.ImGui_EndTable(); - const row_and_cell = pin.rowAndCell(); - const cell = row_and_cell.cell; - const style = pin.style(cell); // Codepoint { @@ -373,112 +370,69 @@ pub const Window = struct { _ = cimgui.c.ImGui_TableSetColumnIndex(1); cimgui.c.ImGui_Text("%s", @tagName(cell.wide).ptr); } - - // Foreground color - { - cimgui.c.ImGui_TableNextRow(); - _ = cimgui.c.ImGui_TableSetColumnIndex(0); - cimgui.c.ImGui_Text("Foreground"); - _ = cimgui.c.ImGui_TableSetColumnIndex(1); - switch (style.fg_color) { - .none => cimgui.c.ImGui_Text("default"), - .palette => |idx| { - const rgb = data.color_palette.current[idx]; - cimgui.c.ImGui_Text("Palette %d", idx); - var color: [3]f32 = .{ - @as(f32, @floatFromInt(rgb.r)) / 255, - @as(f32, @floatFromInt(rgb.g)) / 255, - @as(f32, @floatFromInt(rgb.b)) / 255, - }; - _ = cimgui.c.ImGui_ColorEdit3( - "##fg_color", - &color, - cimgui.c.ImGuiColorEditFlags_DisplayHex | - cimgui.c.ImGuiColorEditFlags_NoPicker | - cimgui.c.ImGuiColorEditFlags_NoLabel, - ); - }, - .rgb => |rgb| { - var color: [3]f32 = .{ - @as(f32, @floatFromInt(rgb.r)) / 255, - @as(f32, @floatFromInt(rgb.g)) / 255, - @as(f32, @floatFromInt(rgb.b)) / 255, - }; - _ = cimgui.c.ImGui_ColorEdit3( - "##fg_color", - &color, - cimgui.c.ImGuiColorEditFlags_DisplayHex | - cimgui.c.ImGuiColorEditFlags_NoPicker | - cimgui.c.ImGuiColorEditFlags_NoLabel, - ); - }, - } - } - - // Background color - { - cimgui.c.ImGui_TableNextRow(); - _ = cimgui.c.ImGui_TableSetColumnIndex(0); - cimgui.c.ImGui_Text("Background"); - _ = cimgui.c.ImGui_TableSetColumnIndex(1); - switch (style.bg_color) { - .none => cimgui.c.ImGui_Text("default"), - .palette => |idx| { - const rgb = data.color_palette.current[idx]; - cimgui.c.ImGui_Text("Palette %d", idx); - var color: [3]f32 = .{ - @as(f32, @floatFromInt(rgb.r)) / 255, - @as(f32, @floatFromInt(rgb.g)) / 255, - @as(f32, @floatFromInt(rgb.b)) / 255, - }; - _ = cimgui.c.ImGui_ColorEdit3( - "##bg_color", - &color, - cimgui.c.ImGuiColorEditFlags_DisplayHex | - cimgui.c.ImGuiColorEditFlags_NoPicker | - cimgui.c.ImGuiColorEditFlags_NoLabel, - ); - }, - .rgb => |rgb| { - var color: [3]f32 = .{ - @as(f32, @floatFromInt(rgb.r)) / 255, - @as(f32, @floatFromInt(rgb.g)) / 255, - @as(f32, @floatFromInt(rgb.b)) / 255, - }; - _ = cimgui.c.ImGui_ColorEdit3( - "##bg_color", - &color, - cimgui.c.ImGuiColorEditFlags_DisplayHex | - cimgui.c.ImGuiColorEditFlags_NoPicker | - cimgui.c.ImGuiColorEditFlags_NoLabel, - ); - }, - } - } - - // Boolean styles - const styles = .{ - "bold", "italic", "faint", "blink", - "inverse", "invisible", "strikethrough", - }; - inline for (styles) |style_name| { - if (@field(style.flags, style_name)) { - cimgui.c.ImGui_TableNextRow(); - _ = cimgui.c.ImGui_TableSetColumnIndex(0); - cimgui.c.ImGui_Text(style_name.ptr); - _ = cimgui.c.ImGui_TableSetColumnIndex(1); - cimgui.c.ImGui_Text("true"); - } - } - - cimgui.c.ImGui_TextDisabled("(Any styles not shown are not currently set)"); - } else { - cimgui.c.ImGui_TableNextRow(); - _ = cimgui.c.ImGui_TableSetColumnIndex(0); - cimgui.c.ImGui_TextColored( - .{ .x = 1.0, .y = 0.4, .z = 0.4, .w = 1.0 }, - "Invalid position", - ); } + + cimgui.c.ImGui_Separator(); + style.table(st, &data.color_palette.current); } }; + +pub fn cursorTable( + cursor: *const terminal.Screen.Cursor, + palette: ?*const terminal.color.Palette, +) void { + { + _ = cimgui.c.ImGui_BeginTable( + "table_cursor", + 2, + cimgui.c.ImGuiTableFlags_None, + ); + defer cimgui.c.ImGui_EndTable(); + + cimgui.c.ImGui_TableNextRow(); + _ = cimgui.c.ImGui_TableSetColumnIndex(0); + cimgui.c.ImGui_Text("Position (x, y)"); + cimgui.c.ImGui_SameLine(); + widgets.helpMarker("The current cursor position in the terminal grid (0-indexed)."); + _ = cimgui.c.ImGui_TableSetColumnIndex(1); + cimgui.c.ImGui_Text("(%d, %d)", cursor.x, cursor.y); + + cimgui.c.ImGui_TableNextRow(); + _ = cimgui.c.ImGui_TableSetColumnIndex(0); + cimgui.c.ImGui_Text("Hyperlink"); + cimgui.c.ImGui_SameLine(); + widgets.helpMarker("The active OSC8 hyperlink for newly printed characters."); + _ = cimgui.c.ImGui_TableSetColumnIndex(1); + if (cursor.hyperlink) |link| { + cimgui.c.ImGui_Text("%.*s", link.uri.len, link.uri.ptr); + } else { + cimgui.c.ImGui_TextDisabled("(none)"); + } + + { + cimgui.c.ImGui_TableNextRow(); + _ = cimgui.c.ImGui_TableSetColumnIndex(0); + cimgui.c.ImGui_Text("Pending Wrap"); + cimgui.c.ImGui_SameLine(); + widgets.helpMarker("The 'last column flag' (LCF). If set, the next character will force a soft-wrap to the next line."); + _ = cimgui.c.ImGui_TableSetColumnIndex(1); + var value: bool = cursor.pending_wrap; + _ = cimgui.c.ImGui_Checkbox("##pending_wrap", &value); + } + + { + cimgui.c.ImGui_TableNextRow(); + _ = cimgui.c.ImGui_TableSetColumnIndex(0); + cimgui.c.ImGui_Text("Protected"); + cimgui.c.ImGui_SameLine(); + widgets.helpMarker("If enabled, new characters will have the protected attribute set, preventing erasure by certain sequences."); + _ = cimgui.c.ImGui_TableSetColumnIndex(1); + var value: bool = cursor.protected; + _ = cimgui.c.ImGui_Checkbox("##protected", &value); + } + } + + cimgui.c.ImGui_Separator(); + + style.table(cursor.style, palette); +} diff --git a/src/inspector/style.zig b/src/inspector/style.zig index a0c192f83..36884c8e0 100644 --- a/src/inspector/style.zig +++ b/src/inspector/style.zig @@ -22,7 +22,7 @@ pub fn table( cimgui.c.ImGui_SameLine(); widgets.helpMarker("The foreground (text) color"); _ = cimgui.c.ImGui_TableSetColumnIndex(1); - color(st.fg_color, palette); + color("fg", st.fg_color, palette); } { @@ -32,7 +32,7 @@ pub fn table( cimgui.c.ImGui_SameLine(); widgets.helpMarker("The background (cell) color"); _ = cimgui.c.ImGui_TableSetColumnIndex(1); - color(st.bg_color, palette); + color("bg", st.bg_color, palette); } { @@ -42,7 +42,7 @@ pub fn table( cimgui.c.ImGui_SameLine(); widgets.helpMarker("The underline color, if underlines are enabled."); _ = cimgui.c.ImGui_TableSetColumnIndex(1); - color(st.underline_color, palette); + color("underline", st.underline_color, palette); } const style_flags = .{ @@ -72,6 +72,8 @@ pub fn table( } } } + + cimgui.c.ImGui_TextDisabled("(Any styles not shown are not currently set)"); } /// Render a style color. @@ -120,6 +122,4 @@ pub fn color( ); }, } - - cimgui.c.ImGui_TextDisabled("(Any styles not shown are not currently set)"); }