Panes/src/main.zig

74 lines
2.2 KiB
Zig
Raw Normal View History

2024-07-24 04:13:42 +00:00
const std = @import("std");
2024-07-25 19:48:17 +00:00
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");
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);
}
2024-07-24 04:13:42 +00:00
pub fn main() !void {
2024-07-25 19:48:17 +00:00
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
defer {
if (gpa.deinit() == .leak) {
std.debug.print("Memory was leaked D:\n", .{});
}
}
2024-07-24 04:13:42 +00:00
2024-07-25 19:48:17 +00:00
term_io = try term.getTermIO();
2024-07-24 04:13:42 +00:00
2024-07-25 19:48:17 +00:00
try pane.init(&term_io);
defer pane.cleanup(&term_io);
2024-07-24 04:13:42 +00:00
2024-07-25 19:48:17 +00:00
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 = null,
.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),
};
pane.top_pane = ⊤
try top.children.?.append(&child);
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);
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();
}
key = term_io.getKey(false);
}
2024-07-24 04:13:42 +00:00
2024-07-25 19:48:17 +00:00
top.children.?.deinit();
2024-07-24 04:13:42 +00:00
}