add(PopupMenu): menu to enable space key binding groupings
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 32s
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 32s
Some minor layout changes of the application
This commit is contained in:
78
src/main.zig
78
src/main.zig
@@ -50,60 +50,52 @@ pub fn main() !void {
|
||||
// Optionally enter the alternate screen
|
||||
try vx.enterAltScreen(tty.anyWriter());
|
||||
|
||||
// We'll adjust the color index every keypress for the border
|
||||
var color_idx: u8 = 0;
|
||||
|
||||
// init our text input widget. The text input widget needs an allocator to
|
||||
// store the contents of the input
|
||||
var text_input = TextInput.init(alloc, &vx.unicode);
|
||||
defer text_input.deinit();
|
||||
|
||||
var header = try widget.Header.init(alloc, &vx.unicode);
|
||||
defer header.deinit();
|
||||
|
||||
var view_port = widget.ViewPort.init(alloc, &vx.unicode);
|
||||
defer view_port.deinit();
|
||||
|
||||
var active_menu = false;
|
||||
var menu = widget.PopupMenu.init(alloc, &vx.unicode);
|
||||
defer menu.deinit();
|
||||
|
||||
// Sends queries to terminal to detect certain features. This should always
|
||||
// be called after entering the alt screen, if you are using the alt screen
|
||||
try vx.queryTerminal(tty.anyWriter(), 1 * std.time.ns_per_s);
|
||||
|
||||
loop.postEvent(.{ .path = "./doc/home.md" });
|
||||
|
||||
while (true) {
|
||||
const event = loop.nextEvent();
|
||||
// update widgets
|
||||
header.update(event);
|
||||
view_port.update(event);
|
||||
if (active_menu) {
|
||||
if (menu.update(event)) |e| {
|
||||
_ = loop.tryPostEvent(e);
|
||||
active_menu = false;
|
||||
}
|
||||
}
|
||||
|
||||
switch (event) {
|
||||
.key_press => |key| {
|
||||
color_idx = switch (color_idx) {
|
||||
255 => 0,
|
||||
else => color_idx + 1,
|
||||
};
|
||||
if (active_menu) {
|
||||
if (key.matches(vaxis.Key.escape, .{})) {
|
||||
active_menu = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (key.matches('c', .{ .ctrl = true })) {
|
||||
break;
|
||||
} else if (key.matches(vaxis.Key.space, .{})) {
|
||||
active_menu = true;
|
||||
} else if (key.matches('l', .{ .ctrl = true })) {
|
||||
vx.queueRefresh();
|
||||
} else if (key.matches(vaxis.Key.enter, .{})) {
|
||||
var len: usize = 0;
|
||||
for (text_input.buf.buffer) |c| {
|
||||
if (c == 0xaa or c == 0)
|
||||
break;
|
||||
len += 1;
|
||||
}
|
||||
const path = alloc.alloc(u8, len) catch @panic("OOM");
|
||||
@memcpy(path, text_input.buf.buffer[0..len]);
|
||||
if (loop.tryPostEvent(.{ .path = path })) {
|
||||
text_input.clearAndFree();
|
||||
}
|
||||
} else {
|
||||
try text_input.update(.{ .key_press = key });
|
||||
}
|
||||
},
|
||||
.winsize => |ws| try vx.resize(alloc, tty.anyWriter(), ws),
|
||||
.path => |*path| {
|
||||
alloc.free(path.*);
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
|
||||
var root_window = vx.window();
|
||||
@@ -118,25 +110,21 @@ pub fn main() !void {
|
||||
.border = .{ .where = .all },
|
||||
}));
|
||||
|
||||
text_input.draw(root_window.child(.{
|
||||
.x_off = 20,
|
||||
view_port.draw(root_window.child(.{
|
||||
.x_off = root_window.width / 8,
|
||||
.y_off = 3,
|
||||
.width = .{ .limit = 40 },
|
||||
.height = .{ .limit = 3 },
|
||||
.border = .{
|
||||
.where = .all,
|
||||
.style = .{ .fg = .{ .index = color_idx } },
|
||||
},
|
||||
.width = .{ .limit = root_window.width / 2 + (root_window.width / 4) },
|
||||
}));
|
||||
|
||||
view_port.draw(root_window.child(.{
|
||||
.x_off = root_window.width / 4,
|
||||
.y_off = 3,
|
||||
.width = .{ .limit = root_window.width / 2 },
|
||||
.border = .{
|
||||
.where = .{ .other = .{ .right = true, .left = true } },
|
||||
},
|
||||
}));
|
||||
if (active_menu) {
|
||||
menu.draw(root_window.child(.{
|
||||
.x_off = root_window.width / 2 - 25,
|
||||
.y_off = root_window.height / 2 - 10,
|
||||
.width = .{ .limit = 50 },
|
||||
.height = .{ .limit = 20 },
|
||||
.border = .{ .where = .all },
|
||||
}));
|
||||
}
|
||||
|
||||
// Render the screen. Using a buffered writer will offer much better
|
||||
// performance, but is not required
|
||||
|
||||
Reference in New Issue
Block a user