84 lines
2.6 KiB
Zig
84 lines
2.6 KiB
Zig
const std = @import("std");
|
|
const term = @import("term.zig");
|
|
const borders = @import("borders.zig");
|
|
const pane = @import("pane.zig");
|
|
const color = @import("colors.zig");
|
|
const dim = @import("dimensions.zig");
|
|
const menu = @import("menu.zig");
|
|
|
|
var term_io: term.TermIO = undefined;
|
|
|
|
pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, ret_addr: ?usize) noreturn {
|
|
pane.cleanup(&term_io);
|
|
std.builtin.default_panic(msg, error_return_trace, ret_addr);
|
|
}
|
|
|
|
pub fn main() !void {
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
const allocator = gpa.allocator();
|
|
defer {
|
|
if (gpa.deinit() == .leak) {
|
|
std.debug.print("Memory was leaked D:\n", .{});
|
|
}
|
|
}
|
|
|
|
term_io = try term.getTermIO();
|
|
|
|
try pane.init(&term_io);
|
|
defer pane.cleanup(&term_io);
|
|
|
|
var top = pane.Pane{
|
|
.dimensions = dim.Fill,
|
|
.border = borders.BoldBorder,
|
|
.children = std.ArrayList(*pane.Pane).init(allocator),
|
|
.background = color.RGB(30, 30, 30),
|
|
.foreground = color.RGB(0, 255, 0),
|
|
};
|
|
|
|
var child = pane.Pane{
|
|
.parent = &top,
|
|
.children = std.ArrayList(*pane.Pane).init(allocator),
|
|
.dimensions = .{
|
|
.anchor = .Center,
|
|
.size_type = .Relative,
|
|
.size = .{ .width = 50, .height = 50 },
|
|
},
|
|
.border = borders.BoldBorder,
|
|
.background = color.RGB(125, 0, 125),
|
|
.foreground = color.RGB(255, 125, 10),
|
|
};
|
|
|
|
var items = [_]menu.MenuItem{ .{ .name = "Item 1", .value = 1 }, .{ .name = "Item 2", .value = 2 } };
|
|
var m = menu.Menu.init(&child, dim.Fill, "Test", &items);
|
|
|
|
pane.top_pane = ⊤
|
|
try top.children.?.append(&child);
|
|
try child.children.?.append(&m.pane);
|
|
|
|
const childWriter = child.writer(&term_io);
|
|
var key = term_io.getKey(false);
|
|
while (key.value != 113 and !pane.should_exit) {
|
|
try pane.tick(&term_io, key);
|
|
if (key.type == .ASCII and key.value == 111) {
|
|
try std.fmt.format(childWriter, "\x1b[2J", .{});
|
|
try term_io.flush();
|
|
}
|
|
if (key.type == .ASCII and key.value == 110) {
|
|
try std.fmt.format(childWriter, "Hello", .{});
|
|
try term_io.flush();
|
|
}
|
|
if (key.type == .ASCII and key.value == 109) {
|
|
try std.fmt.format(childWriter, "Hello\n", .{});
|
|
try term_io.flush();
|
|
}
|
|
if (key.type == .ASCII and key.value == 108) {
|
|
m.pane.focus(&term_io);
|
|
try term_io.flush();
|
|
}
|
|
key = term_io.getKey(false);
|
|
}
|
|
|
|
top.children.?.deinit();
|
|
child.children.?.deinit();
|
|
}
|