a modern tui library written in zig
1const Cell = @import("../Cell.zig");
2const Window = @import("../Window.zig");
3
4const Style = Cell.Style;
5const Character = Cell.Character;
6
7const horizontal = Character{ .grapheme = "─", .width = 1 };
8const vertical = Character{ .grapheme = "│", .width = 1 };
9const top_left = Character{ .grapheme = "╭", .width = 1 };
10const top_right = Character{ .grapheme = "╮", .width = 1 };
11const bottom_right = Character{ .grapheme = "╯", .width = 1 };
12const bottom_left = Character{ .grapheme = "╰", .width = 1 };
13
14pub fn all(win: Window, style: Style) Window {
15 const h = win.height;
16 const w = win.width;
17 win.writeCell(0, 0, .{ .char = top_left, .style = style });
18 win.writeCell(0, h -| 1, .{ .char = bottom_left, .style = style });
19 win.writeCell(w -| 1, 0, .{ .char = top_right, .style = style });
20 win.writeCell(w -| 1, h -| 1, .{ .char = bottom_right, .style = style });
21 var i: usize = 1;
22 while (i < (h -| 1)) : (i += 1) {
23 win.writeCell(0, i, .{ .char = vertical, .style = style });
24 win.writeCell(w -| 1, i, .{ .char = vertical, .style = style });
25 }
26 i = 1;
27 while (i < w -| 1) : (i += 1) {
28 win.writeCell(i, 0, .{ .char = horizontal, .style = style });
29 win.writeCell(i, h -| 1, .{ .char = horizontal, .style = style });
30 }
31 return win.initChild(1, 1, .{ .limit = w -| 2 }, .{ .limit = h -| 2 });
32}
33
34pub fn right(win: Window, style: Style) Window {
35 const h = win.height;
36 const w = win.width;
37 var i: usize = 0;
38 while (i < h) : (i += 1) {
39 win.writeCell(w -| 1, i, .{ .char = vertical, .style = style });
40 }
41 return win.initChild(0, 0, .{ .limit = w -| 1 }, .expand);
42}
43
44pub fn bottom(win: Window, style: Style) Window {
45 const h = win.height;
46 const w = win.width;
47 var i: usize = 0;
48 while (i < w) : (i += 1) {
49 win.writeCell(i, h -| 1, .{ .char = horizontal, .style = style });
50 }
51 return win.initChild(0, 0, .expand, .{ .limit = h -| 1 });
52}