╭ changed ────────╮ │src/ui/widget.zig│ ╰─────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │117 pub const back_button_width = 3; │ │118 const back_button_height = 3; │ │119 const back_kind = "back"; │ │120 + │ │121 +// draw a text box as the selected one of its group: bordered and inverted, │ │122 +// while the rest stay borderless │ │123 +pub fn markSelected(text_box: *wgt.TextBox, selected: bool) void { │ │124 + text_box.options.border_style = if (selected) .single else .hidden; │ │125 + text_box.options.inverted = selected; │ │126 +} │ │127 │ │128 pub fn addBackButton(allocator: std.mem.Allocator, box: *wgt.Box(Widget), session: *ui.Session) !void {│ │129 if (!session.is_terminal) return; │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1396 // stays legible over it │ │1397 const art_brightness = 35; // percent │ │1398 │ │1392 - // only truecolor can be dimmed; palette colors pass through │ │1393 - fn dimColor(color: ?Grid.Color) ?Grid.Color { │ │1399 + // the art parser only emits truecolor, so a palette color never occurs │ │1400 + fn artRgb(color: ?Grid.Color) ?Grid.Color.Rgb { │ │1401 const c = color orelse return null; │ │1402 return switch (c) { │ │1396 - .rgb => |v| .{ .rgb = .{ │ │1397 - .r = @intCast(@as(u16, v.r) * art_brightness / 100), │ │1398 - .g = @intCast(@as(u16, v.g) * art_brightness / 100), │ │1399 - .b = @intCast(@as(u16, v.b) * art_brightness / 100), │ │1400 - } }, │ │1401 - else => c, │ │1403 + .rgb => |v| v, │ │1404 + else => null, │ │1405 }; │ │1406 + } │ │1407 + │ │1408 + fn dimColor(color: ?Grid.Color) ?Grid.Color { │ │1409 + const v = artRgb(color) orelse return color; │ │1410 + return .{ .rgb = .{ │ │1411 + .r = @intCast(@as(u16, v.r) * art_brightness / 100), │ │1412 + .g = @intCast(@as(u16, v.g) * art_brightness / 100), │ │1413 + .b = @intCast(@as(u16, v.b) * art_brightness / 100), │ │1414 + } }; │ │1415 } │ │1416 │ │1417 fn buildArt(self: *AnsiBackground, allocator: std.mem.Allocator, size: layout.Size, root_focus: *Focus) !void {│ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────╮ │1434 // hide text there; the ≤9/255 shift is imperceptible on terminals that │ │1435 // actually render truecolor. │ │1436 fn sgrSafe(color: ?Grid.Color) ?Grid.Color { │ │1425 - const c = color orelse return null; │ │1437 + const v = artRgb(color) orelse return color; │ │1438 const snap = struct { │ │1427 - fn f(v: u8) u8 { │ │1428 - return if (v >= 1 and v <= 9) 10 else v; │ │1439 + fn f(c: u8) u8 { │ │1440 + return if (c >= 1 and c <= 9) 10 else c; │ │1441 } │ │1442 }.f; │ │1431 - return switch (c) { │ │1432 - .rgb => |v| .{ .rgb = .{ .r = snap(v.r), .g = snap(v.g), .b = snap(v.b) } },│ │1433 - else => c, │ │1434 - }; │ │1443 + return .{ .rgb = .{ .r = snap(v.r), .g = snap(v.g), .b = snap(v.b) } }; │ │1444 } │ │1445 │ │1446 fn applyArtBackground(dst: *Grid.Cell, src: Grid.Cell) void { │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────╮ │1448 dst.style.bg = background_maybe; │ │1449 // change unstyled text to contrast with the art behind it │ │1450 if (dst.style.fg == null) { │ │1442 - // the art is parsed as truecolor, so a palette bg never occurs │ │1443 - const background: ?Grid.Color.Rgb = if (background_maybe) |b| switch (b) {│ │1444 - .rgb => |v| v, │ │1445 - else => null, │ │1446 - } else null; │ │1447 - if (background) |v| { │ │1451 + if (artRgb(background_maybe)) |v| { │ │1452 // use near-black and near-white, which is easier on the eyes │ │1453 // while retaining high contrast │ │1454 const luminance = (@as(u32, v.r) * 299 + │ ╰────────────────────────────────────────────────────────────────────────────────────────────╯