Merge pull request #2703 from furtidev/port-to-latest-vaxis

cli: update to latest libvaxis and fix `+list-themes` bugs
This commit is contained in:
Mitchell Hashimoto
2024-11-16 08:49:02 -08:00
committed by GitHub
5 changed files with 802 additions and 793 deletions

View File

@ -1238,8 +1238,6 @@ fn addDeps(
step.root_module.addImport("vaxis", b.dependency("vaxis", .{ step.root_module.addImport("vaxis", b.dependency("vaxis", .{
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
.libxev = false,
.images = false,
}).module("vaxis")); }).module("vaxis"));
step.root_module.addImport("wuffs", b.dependency("wuffs", .{ step.root_module.addImport("wuffs", b.dependency("wuffs", .{
.target = target, .target = target,
@ -1261,6 +1259,7 @@ fn addDeps(
step.root_module.addImport("zf", b.dependency("zf", .{ step.root_module.addImport("zf", b.dependency("zf", .{
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
.with_tui = false,
}).module("zf")); }).module("zf"));
// Mac Stuff // Mac Stuff

View File

@ -53,12 +53,12 @@
.hash = "1220217ae916146a4c598f8ba5bfff0ff940335d00572e337f20b4accf24fa2ca4fc", .hash = "1220217ae916146a4c598f8ba5bfff0ff940335d00572e337f20b4accf24fa2ca4fc",
}, },
.vaxis = .{ .vaxis = .{
.url = "https://github.com/rockorager/libvaxis/archive/refs/tags/v0.5.1.tar.gz", .url = "git+https://github.com/rockorager/libvaxis/?ref=main#6d729a2dc3b934818dffe06d2ba3ce02841ed74b",
.hash = "1220de23a3240e503397ea579de4fd85db422f537e10036ef74717c50164475813ce", .hash = "12200df4ebeaed45de26cb2c9f3b6f3746d8013b604e035dae658f86f586c8c91d2f",
}, },
.zf = .{ .zf = .{
.url = "https://github.com/natecraddock/zf/archive/refs/tags/0.10.2.tar.gz", .url = "git+https://github.com/natecraddock/zf/?ref=main#ed99ca18b02dda052e20ba467e90b623c04690dd",
.hash = "1220014ae47a57902e90aa7b4ff9751832ba1f426d7b138580db06859e0e9b51dfe5", .hash = "1220edc3b8d8bedbb50555947987e5e8e2f93871ca3c8e8d4cc8f1377c15b5dd35e8",
}, },
.z2d = .{ .z2d = .{
.url = "git+https://github.com/vancluever/z2d?ref=main#285a796eb9c25a2389f087d008f0e60faf0b8eda", .url = "git+https://github.com/vancluever/z2d?ref=main#285a796eb9c25a2389f087d008f0e60faf0b8eda",

View File

@ -1,3 +1,3 @@
# This file is auto-generated! check build-support/check-zig-cache-hash.sh for # This file is auto-generated! check build-support/check-zig-cache-hash.sh for
# more details. # more details.
"sha256-uQY8KYNPqwVH+LFXXqVGNYZdG2imeCZoamJf7bMokX4=" "sha256-D1SQIlmdP9x1PDgRVOy1qJGmu9osDbuyxGOcFj646N4="

View File

@ -111,7 +111,7 @@ fn prettyPrint(alloc: Allocator, keybinds: Config.Keybinds) !u8 {
// align things nicely // align things nicely
var iter = keybinds.set.bindings.iterator(); var iter = keybinds.set.bindings.iterator();
var bindings = std.ArrayList(Binding).init(alloc); var bindings = std.ArrayList(Binding).init(alloc);
var widest_key: usize = 0; var widest_key: u16 = 0;
var buf: [64]u8 = undefined; var buf: [64]u8 = undefined;
while (iter.next()) |bind| { while (iter.next()) |bind| {
const action = switch (bind.value_ptr.*) { const action = switch (bind.value_ptr.*) {
@ -134,7 +134,7 @@ fn prettyPrint(alloc: Allocator, keybinds: Config.Keybinds) !u8 {
const alt_style: vaxis.Style = .{ .fg = .{ .index = 3 } }; const alt_style: vaxis.Style = .{ .fg = .{ .index = 3 } };
const shift_style: vaxis.Style = .{ .fg = .{ .index = 4 } }; const shift_style: vaxis.Style = .{ .fg = .{ .index = 4 } };
var longest_col: usize = 0; var longest_col: u16 = 0;
// Print the list // Print the list
for (bindings.items) |bind| { for (bindings.items) |bind| {
@ -143,20 +143,20 @@ fn prettyPrint(alloc: Allocator, keybinds: Config.Keybinds) !u8 {
var result: vaxis.Window.PrintResult = .{ .col = 0, .row = 0, .overflow = false }; var result: vaxis.Window.PrintResult = .{ .col = 0, .row = 0, .overflow = false };
const trigger = bind.trigger; const trigger = bind.trigger;
if (trigger.mods.super) { if (trigger.mods.super) {
result = try win.printSegment(.{ .text = "super", .style = super_style }, .{ .col_offset = result.col }); result = win.printSegment(.{ .text = "super", .style = super_style }, .{ .col_offset = result.col });
result = try win.printSegment(.{ .text = " + " }, .{ .col_offset = result.col }); result = win.printSegment(.{ .text = " + " }, .{ .col_offset = result.col });
} }
if (trigger.mods.ctrl) { if (trigger.mods.ctrl) {
result = try win.printSegment(.{ .text = "ctrl ", .style = ctrl_style }, .{ .col_offset = result.col }); result = win.printSegment(.{ .text = "ctrl ", .style = ctrl_style }, .{ .col_offset = result.col });
result = try win.printSegment(.{ .text = " + " }, .{ .col_offset = result.col }); result = win.printSegment(.{ .text = " + " }, .{ .col_offset = result.col });
} }
if (trigger.mods.alt) { if (trigger.mods.alt) {
result = try win.printSegment(.{ .text = "alt ", .style = alt_style }, .{ .col_offset = result.col }); result = win.printSegment(.{ .text = "alt ", .style = alt_style }, .{ .col_offset = result.col });
result = try win.printSegment(.{ .text = " + " }, .{ .col_offset = result.col }); result = win.printSegment(.{ .text = " + " }, .{ .col_offset = result.col });
} }
if (trigger.mods.shift) { if (trigger.mods.shift) {
result = try win.printSegment(.{ .text = "shift", .style = shift_style }, .{ .col_offset = result.col }); result = win.printSegment(.{ .text = "shift", .style = shift_style }, .{ .col_offset = result.col });
result = try win.printSegment(.{ .text = " + " }, .{ .col_offset = result.col }); result = win.printSegment(.{ .text = " + " }, .{ .col_offset = result.col });
} }
const key = switch (trigger.key) { const key = switch (trigger.key) {
@ -166,20 +166,20 @@ fn prettyPrint(alloc: Allocator, keybinds: Config.Keybinds) !u8 {
}; };
// We don't track the key print because we index the action off the *widest* key so we get // We don't track the key print because we index the action off the *widest* key so we get
// nice alignment no matter what was printed for mods // nice alignment no matter what was printed for mods
_ = try win.printSegment(.{ .text = key }, .{ .col_offset = result.col }); _ = win.printSegment(.{ .text = key }, .{ .col_offset = result.col });
if (longest_col < result.col) longest_col = result.col; if (longest_col < result.col) longest_col = result.col;
const action = try std.fmt.allocPrint(alloc, "{}", .{bind.action}); const action = try std.fmt.allocPrint(alloc, "{}", .{bind.action});
// If our action has an argument, we print the argument in a different color // If our action has an argument, we print the argument in a different color
if (std.mem.indexOfScalar(u8, action, ':')) |idx| { if (std.mem.indexOfScalar(u8, action, ':')) |idx| {
_ = try win.print(&.{ _ = win.print(&.{
.{ .text = action[0..idx] }, .{ .text = action[0..idx] },
.{ .text = action[idx .. idx + 1], .style = .{ .dim = true } }, .{ .text = action[idx .. idx + 1], .style = .{ .dim = true } },
.{ .text = action[idx + 1 ..], .style = .{ .fg = .{ .index = 5 } } }, .{ .text = action[idx + 1 ..], .style = .{ .fg = .{ .index = 5 } } },
}, .{ .col_offset = longest_col + widest_key + 2 }); }, .{ .col_offset = longest_col + widest_key + 2 });
} else { } else {
_ = try win.printSegment(.{ .text = action }, .{ .col_offset = longest_col + widest_key + 2 }); _ = win.printSegment(.{ .text = action }, .{ .col_offset = longest_col + widest_key + 2 });
} }
try vx.prettyPrint(writer); try vx.prettyPrint(writer);
} }

View File

@ -256,7 +256,10 @@ const Preview = struct {
fn updateFiltered(self: *Preview) !void { fn updateFiltered(self: *Preview) !void {
const relative = self.current -| self.window; const relative = self.current -| self.window;
const selected = self.themes[self.filtered.items[self.current]].theme; var selected: []const u8 = undefined;
if (self.filtered.items.len > 0) {
selected = self.themes[self.filtered.items[self.current]].theme;
}
const hash_algorithm = std.hash.Wyhash; const hash_algorithm = std.hash.Wyhash;
@ -290,7 +293,7 @@ const Preview = struct {
for (self.themes, 0..) |*theme, i| { for (self.themes, 0..) |*theme, i| {
theme.rank = zf.rank(theme.theme, tokens.items, .{ theme.rank = zf.rank(theme.theme, tokens.items, .{
.to_lower = false, .to_lower = true,
.plain = true, .plain = true,
}); });
if (theme.rank != null) try self.filtered.append(i); if (theme.rank != null) try self.filtered.append(i);
@ -500,8 +503,8 @@ const Preview = struct {
const theme_list = win.child(.{ const theme_list = win.child(.{
.x_off = 0, .x_off = 0,
.y_off = 0, .y_off = 0,
.width = .{ .limit = 32 }, .width = 32,
.height = .{ .limit = win.height }, .height = win.height,
}); });
var highlight: ?usize = null; var highlight: ?usize = null;
@ -543,7 +546,8 @@ const Preview = struct {
theme_list.fill(.{ .style = self.ui_standard() }); theme_list.fill(.{ .style = self.ui_standard() });
for (0..theme_list.height) |row| { for (0..theme_list.height) |row_capture| {
const row: u16 = @intCast(row_capture);
const index = self.window + row; const index = self.window + row;
if (index >= self.filtered.items.len) break; if (index >= self.filtered.items.len) break;
@ -556,7 +560,7 @@ const Preview = struct {
}; };
if (style == .selected) { if (style == .selected) {
_ = try theme_list.printSegment( _ = theme_list.printSegment(
.{ .{
.text = " ", .text = " ",
.style = self.ui_selected(), .style = self.ui_selected(),
@ -567,7 +571,7 @@ const Preview = struct {
}, },
); );
} }
_ = try theme_list.printSegment( _ = theme_list.printSegment(
.{ .{
.text = theme.theme, .text = theme.theme,
.style = switch (style) { .style = switch (style) {
@ -586,8 +590,9 @@ const Preview = struct {
); );
if (style == .selected) { if (style == .selected) {
if (theme.theme.len < theme_list.width - 4) { if (theme.theme.len < theme_list.width - 4) {
for (2 + theme.theme.len..theme_list.width - 2) |i| for (2 + theme.theme.len..theme_list.width - 2) |i_capture| {
_ = try theme_list.printSegment( const i: u16 = @intCast(i_capture);
_ = theme_list.printSegment(
.{ .{
.text = " ", .text = " ",
.style = self.ui_selected(), .style = self.ui_selected(),
@ -598,7 +603,8 @@ const Preview = struct {
}, },
); );
} }
_ = try theme_list.printSegment( }
_ = theme_list.printSegment(
.{ .{
.text = " ", .text = " ",
.style = self.ui_selected(), .style = self.ui_selected(),
@ -625,12 +631,8 @@ const Preview = struct {
.{ .{
.x_off = win.width / 2 -| width / 2, .x_off = win.width / 2 -| width / 2,
.y_off = win.height / 2 -| height / 2, .y_off = win.height / 2 -| height / 2,
.width = .{ .width = width,
.limit = width, .height = height,
},
.height = .{
.limit = height,
},
.border = .{ .border = .{
.where = .all, .where = .all,
.style = self.ui_standard(), .style = self.ui_standard(),
@ -660,8 +662,9 @@ const Preview = struct {
.{ .keys = "", .help = "Close search window." }, .{ .keys = "", .help = "Close search window." },
}; };
for (key_help, 0..) |help, i| { for (key_help, 0..) |help, captured_i| {
_ = try child.printSegment( const i: u16 = @intCast(captured_i);
_ = child.printSegment(
.{ .{
.text = help.keys, .text = help.keys,
.style = self.ui_standard(), .style = self.ui_standard(),
@ -671,7 +674,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.printSegment( _ = child.printSegment(
.{ .{
.text = "", .text = "",
.style = self.ui_standard(), .style = self.ui_standard(),
@ -681,7 +684,7 @@ const Preview = struct {
.col_offset = 15, .col_offset = 15,
}, },
); );
_ = try child.printSegment( _ = child.printSegment(
.{ .{
.text = help.help, .text = help.help,
.style = self.ui_standard(), .style = self.ui_standard(),
@ -697,12 +700,8 @@ const Preview = struct {
const child = win.child(.{ const child = win.child(.{
.x_off = 20, .x_off = 20,
.y_off = win.height - 5, .y_off = win.height - 5,
.width = .{ .width = win.width - 40,
.limit = win.width - 40, .height = 3,
},
.height = .{
.limit = 3,
},
.border = .{ .border = .{
.where = .all, .where = .all,
.style = self.ui_standard(), .style = self.ui_standard(),
@ -714,44 +713,45 @@ const Preview = struct {
} }
} }
pub fn drawPreview(self: *Preview, alloc: std.mem.Allocator, win: vaxis.Window, x_off: usize) !void { pub fn drawPreview(self: *Preview, alloc: std.mem.Allocator, win: vaxis.Window, x_off_unconverted: i17) !void {
const width = win.width - x_off; const x_off: u16 = @intCast(x_off_unconverted);
const width: u16 = win.width - x_off;
if (self.filtered.items.len > 0) {
const theme = self.themes[self.filtered.items[self.current]]; const theme = self.themes[self.filtered.items[self.current]];
var config = try Config.default(alloc); var config = try Config.default(alloc);
defer config.deinit(); defer config.deinit();
config.loadFile(config._arena.?.allocator(), theme.path) catch |err| { config.loadFile(config._arena.?.allocator(), theme.path) catch |err| {
const theme_path_len: u16 = @intCast(theme.path.len);
const child = win.child( const child = win.child(
.{ .{
.x_off = x_off, .x_off = x_off,
.y_off = 0, .y_off = 0,
.width = .{ .width = width,
.limit = width, .height = win.height,
},
.height = .{
.limit = win.height,
},
}, },
); );
child.fill(.{ .style = self.ui_standard() }); child.fill(.{ .style = self.ui_standard() });
const middle = child.height / 2; const middle = child.height / 2;
{ {
const text = try std.fmt.allocPrint(alloc, "Unable to open {s} from:", .{theme.theme}); const text = try std.fmt.allocPrint(alloc, "Unable to open {s} from:", .{theme.theme});
_ = try child.printSegment( const text_len: u16 = @intCast(text.len);
_ = child.printSegment(
.{ .{
.text = text, .text = text,
.style = self.ui_err(), .style = self.ui_err(),
}, },
.{ .{
.row_offset = middle -| 1, .row_offset = middle -| 1,
.col_offset = child.width / 2 -| text.len / 2, .col_offset = child.width / 2 -| text_len / 2,
}, },
); );
} }
{ {
_ = try child.printSegment( _ = child.printSegment(
.{ .{
.text = theme.path, .text = theme.path,
.style = self.ui_err(), .style = self.ui_err(),
@ -761,27 +761,28 @@ const Preview = struct {
}, },
.{ .{
.row_offset = middle, .row_offset = middle,
.col_offset = child.width / 2 -| theme.path.len / 2, .col_offset = child.width / 2 -| theme_path_len / 2,
}, },
); );
} }
{ {
const text = try std.fmt.allocPrint(alloc, "{}", .{err}); const text = try std.fmt.allocPrint(alloc, "{}", .{err});
_ = try child.printSegment( const text_len: u16 = @intCast(text.len);
_ = child.printSegment(
.{ .{
.text = text, .text = text,
.style = self.ui_err(), .style = self.ui_err(),
}, },
.{ .{
.row_offset = middle + 1, .row_offset = middle + 1,
.col_offset = child.width / 2 -| text.len / 2, .col_offset = child.width / 2 -| text_len / 2,
}, },
); );
} }
return; return;
}; };
var next_start: usize = 0; var next_start: u16 = 0;
const fg: vaxis.Color = .{ const fg: vaxis.Color = .{
.rgb = [_]u8{ .rgb = [_]u8{
@ -844,20 +845,18 @@ const Preview = struct {
}; };
{ {
const theme_len: u16 = @intCast(theme.theme.len);
const theme_path_len: u16 = @intCast(theme.path.len);
const child = win.child( const child = win.child(
.{ .{
.x_off = x_off, .x_off = x_off,
.y_off = next_start, .y_off = next_start,
.width = .{ .width = width,
.limit = width, .height = 4,
},
.height = .{
.limit = 4,
},
}, },
); );
child.fill(.{ .style = standard }); child.fill(.{ .style = standard });
_ = try child.printSegment( _ = child.printSegment(
.{ .{
.text = theme.theme, .text = theme.theme,
.style = standard_bold_italic, .style = standard_bold_italic,
@ -867,10 +866,10 @@ const Preview = struct {
}, },
.{ .{
.row_offset = 1, .row_offset = 1,
.col_offset = child.width / 2 -| theme.theme.len / 2, .col_offset = child.width / 2 -| theme_len / 2,
}, },
); );
_ = try child.printSegment( _ = child.printSegment(
.{ .{
.text = theme.path, .text = theme.path,
.style = standard, .style = standard,
@ -880,7 +879,7 @@ const Preview = struct {
}, },
.{ .{
.row_offset = 2, .row_offset = 2,
.col_offset = child.width / 2 -| theme.path.len / 2, .col_offset = child.width / 2 -| theme_path_len / 2,
.wrap = .none, .wrap = .none,
}, },
); );
@ -888,37 +887,36 @@ const Preview = struct {
} }
if (config._diagnostics.items().len > 0) { if (config._diagnostics.items().len > 0) {
const diagnostic_items_len: u16 = @intCast(config._diagnostics.items().len);
const child = win.child( const child = win.child(
.{ .{
.x_off = x_off, .x_off = x_off,
.y_off = next_start, .y_off = next_start,
.width = .{ .width = width,
.limit = width, .height = if (config._diagnostics.items().len == 0) 0 else 2 + diagnostic_items_len,
},
.height = .{
.limit = if (config._diagnostics.items().len == 0) 0 else 2 + config._diagnostics.items().len,
},
}, },
); );
{ {
const text = "Problems were encountered trying to load the theme:"; const text = "Problems were encountered trying to load the theme:";
_ = try child.printSegment( const text_len: u16 = @intCast(text.len);
_ = child.printSegment(
.{ .{
.text = text, .text = text,
.style = self.ui_err(), .style = self.ui_err(),
}, },
.{ .{
.row_offset = 0, .row_offset = 0,
.col_offset = child.width / 2 -| (text.len / 2), .col_offset = child.width / 2 -| (text_len / 2),
}, },
); );
} }
var buf = std.ArrayList(u8).init(alloc); var buf = std.ArrayList(u8).init(alloc);
defer buf.deinit(); defer buf.deinit();
for (config._diagnostics.items(), 0..) |diag, i| { for (config._diagnostics.items(), 0..) |diag, captured_i| {
const i: u16 = @intCast(captured_i);
try diag.write(buf.writer()); try diag.write(buf.writer());
_ = try child.printSegment( _ = child.printSegment(
.{ .{
.text = buf.items, .text = buf.items,
.style = self.ui_err(), .style = self.ui_err(),
@ -936,24 +934,21 @@ const Preview = struct {
const child = win.child(.{ const child = win.child(.{
.x_off = x_off, .x_off = x_off,
.y_off = next_start, .y_off = next_start,
.width = .{ .width = width,
.limit = width, .height = 6,
},
.height = .{
.limit = 6,
},
}); });
child.fill(.{ .style = standard }); child.fill(.{ .style = standard });
for (0..16) |i| { for (0..16) |captured_i| {
const i: u16 = @intCast(captured_i);
const r = i / 8; const r = i / 8;
const c = i % 8; const c = i % 8;
const text = if (self.hex) const text = if (self.hex)
try std.fmt.allocPrint(alloc, " {x:0>2}", .{i}) try std.fmt.allocPrint(alloc, " {x:0>2}", .{i})
else else
try std.fmt.allocPrint(alloc, "{d:3}", .{i}); try std.fmt.allocPrint(alloc, "{d:3}", .{i});
_ = try child.printSegment( _ = child.printSegment(
.{ .{
.text = text, .text = text,
.style = standard, .style = standard,
@ -963,7 +958,7 @@ const Preview = struct {
.col_offset = c * 8, .col_offset = c * 8,
}, },
); );
_ = try child.printSegment( _ = child.printSegment(
.{ .{
.text = "████", .text = "████",
.style = .{ .style = .{
@ -976,7 +971,7 @@ const Preview = struct {
.col_offset = 4 + c * 8, .col_offset = 4 + c * 8,
}, },
); );
_ = try child.printSegment( _ = child.printSegment(
.{ .{
.text = "████", .text = "████",
.style = .{ .style = .{
@ -997,12 +992,8 @@ const Preview = struct {
.{ .{
.x_off = x_off, .x_off = x_off,
.y_off = next_start, .y_off = next_start,
.width = .{ .width = width,
.limit = width, .height = 24,
},
.height = .{
.limit = 24,
},
}, },
); );
const bold: vaxis.Style = .{ const bold: vaxis.Style = .{
@ -1052,7 +1043,7 @@ const Preview = struct {
.bg = bg, .bg = bg,
}; };
child.fill(.{ .style = standard }); child.fill(.{ .style = standard });
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = "", .style = color2 }, .{ .text = "", .style = color2 },
.{ .text = " ", .style = standard }, .{ .text = " ", .style = standard },
@ -1066,7 +1057,7 @@ const Preview = struct {
}, },
); );
{ {
_ = try child.print( _ = child.print(
&.{ &.{
.{ .{
.text = "───────┬", .text = "───────┬",
@ -1079,8 +1070,9 @@ const Preview = struct {
}, },
); );
if (child.width > 10) { if (child.width > 10) {
for (10..child.width) |col| { for (10..child.width) |captured_col| {
_ = try child.print( const col: u16 = @intCast(captured_col);
_ = child.print(
&.{ &.{
.{ .{
.text = "", .text = "",
@ -1095,7 +1087,7 @@ const Preview = struct {
} }
} }
} }
_ = try child.print( _ = child.print(
&.{ &.{
.{ .{
.text = "", .text = "",
@ -1118,7 +1110,7 @@ const Preview = struct {
}, },
); );
{ {
_ = try child.print( _ = child.print(
&.{ &.{
.{ .{
.text = "───────┼", .text = "───────┼",
@ -1131,8 +1123,9 @@ const Preview = struct {
}, },
); );
if (child.width > 10) { if (child.width > 10) {
for (10..child.width) |col| { for (10..child.width) |captured_col| {
_ = try child.print( const col: u16 = @intCast(captured_col);
_ = child.print(
&.{ &.{
.{ .{
.text = "", .text = "",
@ -1147,7 +1140,7 @@ const Preview = struct {
} }
} }
} }
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = " 1 │ ", .style = color238 }, .{ .text = " 1 │ ", .style = color238 },
.{ .text = "const", .style = color5 }, .{ .text = "const", .style = color5 },
@ -1162,7 +1155,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = " 2 │", .style = color238 }, .{ .text = " 2 │", .style = color238 },
}, },
@ -1171,7 +1164,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = " 3 │ ", .style = color238 }, .{ .text = " 3 │ ", .style = color238 },
.{ .text = "pub ", .style = color5 }, .{ .text = "pub ", .style = color5 },
@ -1187,7 +1180,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = " 4 │ ", .style = color238 }, .{ .text = " 4 │ ", .style = color238 },
.{ .text = "const ", .style = color5 }, .{ .text = "const ", .style = color5 },
@ -1200,7 +1193,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = " 5 │ ", .style = color238 }, .{ .text = " 5 │ ", .style = color238 },
.{ .text = "var ", .style = color5 }, .{ .text = "var ", .style = color5 },
@ -1215,7 +1208,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = " 6 │ ", .style = color238 }, .{ .text = " 6 │ ", .style = color238 },
.{ .text = "while ", .style = color5 }, .{ .text = "while ", .style = color5 },
@ -1232,7 +1225,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = " 7 │ ", .style = color238 }, .{ .text = " 7 │ ", .style = color238 },
.{ .text = "if ", .style = color5 }, .{ .text = "if ", .style = color5 },
@ -1248,7 +1241,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = " 8 │ ", .style = color238 }, .{ .text = " 8 │ ", .style = color238 },
.{ .text = "try ", .style = color5 }, .{ .text = "try ", .style = color5 },
@ -1263,7 +1256,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = " 9 │ ", .style = color238 }, .{ .text = " 9 │ ", .style = color238 },
.{ .text = "} ", .style = standard }, .{ .text = "} ", .style = standard },
@ -1280,7 +1273,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = " 10 │ ", .style = color238 }, .{ .text = " 10 │ ", .style = color238 },
.{ .text = "try ", .style = color5 }, .{ .text = "try ", .style = color5 },
@ -1295,7 +1288,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = " 11 │ ", .style = color238 }, .{ .text = " 11 │ ", .style = color238 },
.{ .text = "} ", .style = standard }, .{ .text = "} ", .style = standard },
@ -1312,7 +1305,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = " 12 │ ", .style = color238 }, .{ .text = " 12 │ ", .style = color238 },
.{ .text = "try ", .style = color5 }, .{ .text = "try ", .style = color5 },
@ -1327,7 +1320,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = " 13 │ ", .style = color238 }, .{ .text = " 13 │ ", .style = color238 },
.{ .text = "} ", .style = standard }, .{ .text = "} ", .style = standard },
@ -1339,7 +1332,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = " 14 │ ", .style = color238 }, .{ .text = " 14 │ ", .style = color238 },
.{ .text = "try ", .style = color5 }, .{ .text = "try ", .style = color5 },
@ -1354,7 +1347,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = " 15 │ ", .style = color238 }, .{ .text = " 15 │ ", .style = color238 },
.{ .text = "}", .style = standard }, .{ .text = "}", .style = standard },
@ -1364,7 +1357,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = " 16 │ ", .style = color238 }, .{ .text = " 16 │ ", .style = color238 },
.{ .text = "}", .style = standard }, .{ .text = "}", .style = standard },
@ -1374,7 +1367,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = " 17 │ ", .style = color238 }, .{ .text = " 17 │ ", .style = color238 },
.{ .text = "}", .style = standard }, .{ .text = "}", .style = standard },
@ -1385,7 +1378,7 @@ const Preview = struct {
}, },
); );
{ {
_ = try child.print( _ = child.print(
&.{ &.{
.{ .{
.text = "───────┴", .text = "───────┴",
@ -1398,8 +1391,9 @@ const Preview = struct {
}, },
); );
if (child.width > 10) { if (child.width > 10) {
for (10..child.width) |col| { for (10..child.width) |captured_col| {
_ = try child.print( const col: u16 = @intCast(captured_col);
_ = child.print(
&.{ &.{
.{ .{
.text = "", .text = "",
@ -1414,7 +1408,7 @@ const Preview = struct {
} }
} }
} }
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = "ghostty ", .style = color6 }, .{ .text = "ghostty ", .style = color6 },
.{ .text = "on ", .style = standard }, .{ .text = "on ", .style = standard },
@ -1430,7 +1424,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.print( _ = child.print(
&.{ &.{
.{ .text = "", .style = color4 }, .{ .text = "", .style = color4 },
.{ .text = "at ", .style = standard }, .{ .text = "at ", .style = standard },
@ -1449,23 +1443,20 @@ const Preview = struct {
.{ .{
.x_off = x_off, .x_off = x_off,
.y_off = next_start, .y_off = next_start,
.width = .{ .width = width,
.limit = width, .height = win.height - next_start,
},
.height = .{
.limit = win.height - next_start,
},
}, },
); );
child.fill(.{ .style = standard }); child.fill(.{ .style = standard });
var it = std.mem.splitAny(u8, lorem_ipsum, " \n"); var it = std.mem.splitAny(u8, lorem_ipsum, " \n");
var row: usize = 1; var row: u16 = 1;
var col: usize = 2; var col: u16 = 2;
while (row < child.height) { while (row < child.height) {
const word = it.next() orelse line: { const word = it.next() orelse line: {
it.reset(); it.reset();
break :line it.next() orelse unreachable; break :line it.next() orelse unreachable;
}; };
const word_len: u16 = @intCast(word.len);
if (col + word.len > child.width) { if (col + word.len > child.width) {
row += 1; row += 1;
col = 2; col = 2;
@ -1482,7 +1473,7 @@ const Preview = struct {
if (std.mem.eql(u8, "odio", word)) break :style standard_curly_underline; if (std.mem.eql(u8, "odio", word)) break :style standard_curly_underline;
break :style standard; break :style standard;
}; };
_ = try child.printSegment( _ = child.printSegment(
.{ .{
.text = word, .text = word,
.style = style, .style = style,
@ -1492,9 +1483,28 @@ const Preview = struct {
.col_offset = col, .col_offset = col,
}, },
); );
col += word.len + 1; col += word_len + 1;
} }
} }
} else {
const child = win.child(.{
.x_off = 0,
.y_off = 0,
.width = win.width,
.height = win.height,
});
child.fill(.{
.style = self.ui_standard(),
});
_ = child.printSegment(.{
.text = "No theme found!",
.style = self.ui_standard(),
}, .{
.row_offset = win.height / 2 - 1,
.col_offset = win.width / 2 - 7,
});
}
} }
}; };