diff --git a/src/inspector/Inspector.zig b/src/inspector/Inspector.zig index dfe03bf50..cfe6d8771 100644 --- a/src/inspector/Inspector.zig +++ b/src/inspector/Inspector.zig @@ -579,7 +579,8 @@ fn renderTermioWindow(self: *Inspector) void { // imgui has no way to make a column span. if (ev.imgui_selected) { { - inspector.screen.cursorTable( + widgets.screen.cursorTable(&ev.cursor); + widgets.screen.cursorStyle( &ev.cursor, &self.surface.renderer_state.terminal.colors.palette.current, ); diff --git a/src/inspector/screen.zig b/src/inspector/screen.zig index a8ff1c459..63170722a 100644 --- a/src/inspector/screen.zig +++ b/src/inspector/screen.zig @@ -2,7 +2,6 @@ const std = @import("std"); const cimgui = @import("dcimgui"); const terminal = @import("../terminal/main.zig"); const inspector = @import("main.zig"); -const style = @import("widgets/style.zig"); const units = @import("units.zig"); const widgets = @import("widgets.zig"); @@ -65,7 +64,8 @@ pub const Window = struct { "Cursor", cimgui.c.ImGuiTreeNodeFlags_None, )) { - cursorTable( + widgets.screen.cursorTable(&screen.cursor); + widgets.screen.cursorStyle( &screen.cursor, &data.color_palette.current, ); @@ -373,66 +373,6 @@ pub const Window = struct { } cimgui.c.ImGui_Separator(); - style.table(st, &data.color_palette.current); + widgets.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/widgets/screen.zig b/src/inspector/widgets/screen.zig index d7b7b455c..b394872d8 100644 --- a/src/inspector/widgets/screen.zig +++ b/src/inspector/widgets/screen.zig @@ -4,6 +4,7 @@ const assert = @import("../../quirks.zig").inlineAssert; const Allocator = std.mem.Allocator; const cimgui = @import("dcimgui"); const widgets = @import("../widgets.zig"); +const units = @import("../units.zig"); const terminal = @import("../../terminal/main.zig"); /// Screen information inspector widget. @@ -42,6 +43,15 @@ pub const Info = struct { cimgui.c.ImGui_Separator(); } + if (cimgui.c.ImGui_CollapsingHeader( + "Cursor", + cimgui.c.ImGuiTreeNodeFlags_None, + )) { + cursorTable(&screen.cursor); + cimgui.c.ImGui_Separator(); + cursorStyle(&screen.cursor, &data.color_palette.current); + } + if (cimgui.c.ImGui_CollapsingHeader( "Keyboard", cimgui.c.ImGuiTreeNodeFlags_None, @@ -49,9 +59,78 @@ pub const Info = struct { screen, data.modify_other_keys_2, ); + + if (cimgui.c.ImGui_CollapsingHeader( + "Kitty Graphics", + cimgui.c.ImGuiTreeNodeFlags_None, + )) kittyGraphicsTable(&screen.kitty_images); + + if (cimgui.c.ImGui_CollapsingHeader( + "Internal Terminal State", + cimgui.c.ImGuiTreeNodeFlags_None, + )) internalStateTable(&screen.pages); } }; +/// Render cursor state with a table of cursor-specific fields. +pub fn cursorTable( + cursor: *const terminal.Screen.Cursor, +) void { + if (!cimgui.c.ImGui_BeginTable( + "table_cursor", + 2, + cimgui.c.ImGuiTableFlags_None, + )) return; + 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); + } +} + +/// Render cursor style information using the shared style table. +pub fn cursorStyle(cursor: *const terminal.Screen.Cursor, palette: ?*const terminal.color.Palette) void { + widgets.style.table(cursor.style, palette); +} + /// Render keyboard information with a table. fn keyboardTable( screen: *const terminal.Screen, @@ -116,5 +195,81 @@ fn keyboardTable( } } } // keyboard mode info - +} + +/// Render kitty graphics information table. +pub fn kittyGraphicsTable( + kitty_images: *const terminal.kitty.graphics.ImageStorage, +) void { + if (!kitty_images.enabled()) { + cimgui.c.ImGui_TextDisabled("(Kitty graphics are disabled)"); + return; + } + + if (!cimgui.c.ImGui_BeginTable( + "##kitty_graphics", + 2, + cimgui.c.ImGuiTableFlags_None, + )) return; + defer cimgui.c.ImGui_EndTable(); + + cimgui.c.ImGui_TableNextRow(); + _ = cimgui.c.ImGui_TableSetColumnIndex(0); + cimgui.c.ImGui_Text("Memory Usage"); + _ = cimgui.c.ImGui_TableSetColumnIndex(1); + cimgui.c.ImGui_Text("%d bytes (%d KiB)", kitty_images.total_bytes, units.toKibiBytes(kitty_images.total_bytes)); + + cimgui.c.ImGui_TableNextRow(); + _ = cimgui.c.ImGui_TableSetColumnIndex(0); + cimgui.c.ImGui_Text("Memory Limit"); + _ = cimgui.c.ImGui_TableSetColumnIndex(1); + cimgui.c.ImGui_Text("%d bytes (%d KiB)", kitty_images.total_limit, units.toKibiBytes(kitty_images.total_limit)); + + cimgui.c.ImGui_TableNextRow(); + _ = cimgui.c.ImGui_TableSetColumnIndex(0); + cimgui.c.ImGui_Text("Image Count"); + _ = cimgui.c.ImGui_TableSetColumnIndex(1); + cimgui.c.ImGui_Text("%d", kitty_images.images.count()); + + cimgui.c.ImGui_TableNextRow(); + _ = cimgui.c.ImGui_TableSetColumnIndex(0); + cimgui.c.ImGui_Text("Placement Count"); + _ = cimgui.c.ImGui_TableSetColumnIndex(1); + cimgui.c.ImGui_Text("%d", kitty_images.placements.count()); + + cimgui.c.ImGui_TableNextRow(); + _ = cimgui.c.ImGui_TableSetColumnIndex(0); + cimgui.c.ImGui_Text("Image Loading"); + _ = cimgui.c.ImGui_TableSetColumnIndex(1); + cimgui.c.ImGui_Text("%s", if (kitty_images.loading != null) "true".ptr else "false".ptr); +} + +/// Render internal terminal state table. +pub fn internalStateTable( + pages: *const terminal.PageList, +) void { + if (!cimgui.c.ImGui_BeginTable( + "##terminal_state", + 2, + cimgui.c.ImGuiTableFlags_None, + )) return; + defer cimgui.c.ImGui_EndTable(); + + cimgui.c.ImGui_TableNextRow(); + _ = cimgui.c.ImGui_TableSetColumnIndex(0); + cimgui.c.ImGui_Text("Memory Usage"); + _ = cimgui.c.ImGui_TableSetColumnIndex(1); + cimgui.c.ImGui_Text("%d bytes (%d KiB)", pages.page_size, units.toKibiBytes(pages.page_size)); + + cimgui.c.ImGui_TableNextRow(); + _ = cimgui.c.ImGui_TableSetColumnIndex(0); + cimgui.c.ImGui_Text("Memory Limit"); + _ = cimgui.c.ImGui_TableSetColumnIndex(1); + cimgui.c.ImGui_Text("%d bytes (%d KiB)", pages.maxSize(), units.toKibiBytes(pages.maxSize())); + + cimgui.c.ImGui_TableNextRow(); + _ = cimgui.c.ImGui_TableSetColumnIndex(0); + cimgui.c.ImGui_Text("Viewport Location"); + _ = cimgui.c.ImGui_TableSetColumnIndex(1); + cimgui.c.ImGui_Text("%s", @tagName(pages.viewport).ptr); }