inspector: track lots of metadata for vt events

This commit is contained in:
Mitchell Hashimoto
2023-10-24 21:56:38 -07:00
parent ecbd52015b
commit c1469eb7b2
4 changed files with 62 additions and 91 deletions

View File

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

View File

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

View File

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

View File

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