Skip to content

Commit

Permalink
fix examples, update readme features
Browse files Browse the repository at this point in the history
  • Loading branch information
rockorager committed May 22, 2024
1 parent d7bc2c4 commit 1b957ec
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 33 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Vaxis uses zig `0.12.0`.
| Kitty Keyboard ||||
| Styled Underlines ||||
| Mouse Shapes (OSC 22) ||||
| System Clipboard (OSC 52) || planned ||
| System Clipboard (OSC 52) || ||
| System Notifications (OSC 9) ||||
| System Notifications (OSC 777) ||||
| Synchronized Output (DEC 2026) ||||
Expand All @@ -35,7 +35,7 @@ Vaxis uses zig `0.12.0`.
| Images (half block) || planned ||
| Images (quadrant) || planned ||
| Images (sextant) ||||
| Images (sixel) || debating ||
| Images (sixel) || ||
| Images (kitty) ||||
| Images (iterm2) ||||
| Video ||||
Expand Down
2 changes: 1 addition & 1 deletion examples/cli.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn main() !void {

var loop: vaxis.Loop(Event) = .{ .vaxis = &vx };

try loop.run(alloc);
try loop.run();
defer loop.stop();

try vx.queryTerminal();
Expand Down
2 changes: 1 addition & 1 deletion examples/image.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn main() !void {

var loop: vaxis.Loop(Event) = .{ .vaxis = &vx };

try loop.run(alloc);
try loop.run();
defer loop.stop();

try vx.enterAltScreen();
Expand Down
2 changes: 1 addition & 1 deletion examples/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn main() !void {

// Start the read loop. This puts the terminal in raw mode and begins
// reading user input
try loop.run(alloc);
try loop.run();
defer loop.stop();

// Optionally enter the alternate screen
Expand Down
2 changes: 1 addition & 1 deletion examples/nvim.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn main() !void {

var loop: vaxis.Loop(Event) = .{ .vaxis = &vx };

try loop.run(alloc);
try loop.run();
defer loop.stop();

// Optionally enter the alternate screen
Expand Down
2 changes: 1 addition & 1 deletion examples/pathological.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn main() !void {

var loop: vaxis.Loop(Event) = .{ .vaxis = &vx };

try loop.run(alloc);
try loop.run();
defer loop.stop();
try vx.enterAltScreen();
try vx.queryTerminal();
Expand Down
2 changes: 1 addition & 1 deletion examples/shell.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn main() !void {

var loop: vaxis.Loop(Event) = .{ .vaxis = &vx };

try loop.run(alloc);
try loop.run();
defer loop.stop();

try vx.queryTerminal();
Expand Down
34 changes: 14 additions & 20 deletions examples/table.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const vaxis = @import("vaxis");

const log = std.log.scoped(.main);

const ActiveSection = enum{
const ActiveSection = enum {
top,
mid,
btm,
Expand All @@ -32,7 +32,7 @@ pub fn main() !void {
winsize: vaxis.Winsize,
}) = .{ .vaxis = &vx };

try loop.run(alloc);
try loop.run();
defer loop.stop();
try vx.enterAltScreen();
try vx.queryTerminal();
Expand Down Expand Up @@ -94,10 +94,9 @@ pub fn main() !void {
break :keyEvt;
}
// Command State
if (
active != .btm and
key.matchesAny(&.{ ':', '/', 'g', 'G' }, .{})
) {
if (active != .btm and
key.matchesAny(&.{ ':', '/', 'g', 'G' }, .{}))
{
active = .btm;
for (0..cmd_input.buf.items.len) |_| _ = cmd_input.buf.orderedRemove(0);
try cmd_input.update(.{ .key_press = key });
Expand Down Expand Up @@ -127,11 +126,9 @@ pub fn main() !void {
// Run Command and Clear Command Bar
else if (key.matchExact(vaxis.Key.enter, .{})) {
const cmd = cmd_input.buf.items;
if (
mem.eql(u8, ":q", cmd) or
if (mem.eql(u8, ":q", cmd) or
mem.eql(u8, ":quit", cmd) or
mem.eql(u8, ":exit", cmd)
) return;
mem.eql(u8, ":exit", cmd)) return;
if (mem.eql(u8, "G", cmd)) {
demo_tbl.row = user_list.items.len - 1;
active = .mid;
Expand All @@ -143,8 +140,7 @@ pub fn main() !void {
}
for (0..cmd_input.buf.items.len) |_| _ = cmd_input.buf.orderedRemove(0);
cmd_input.cursor_idx = 0;
}
else try cmd_input.update(.{ .key_press = key });
} else try cmd_input.update(.{ .key_press = key });
},
}
moving = false;
Expand All @@ -168,15 +164,15 @@ pub fn main() !void {
);
for (title_segs[0..]) |*title_seg|
title_seg.*.style.bg = if (active == .top) selected_bg else other_bg;
top_bar.fill(.{
.style = .{ .bg = if (active == .top) selected_bg else other_bg, }
});
top_bar.fill(.{ .style = .{
.bg = if (active == .top) selected_bg else other_bg,
} });
const logo_bar = vaxis.widgets.alignment.center(
top_bar,
44,
top_bar.height - (top_bar.height / 3),
);
try logo_bar.wrap(title_segs[0..]);
_ = try logo_bar.print(title_segs[0..], .{ .wrap = .word });

// - Middle
const middle_bar = win.initChild(
Expand All @@ -203,9 +199,7 @@ pub fn main() !void {
.{ .limit = win.width },
.{ .limit = 1 },
);
if (active == .btm) bottom_bar.fill(.{
.style = .{ .bg = selected_bg }
});
if (active == .btm) bottom_bar.fill(.{ .style = .{ .bg = selected_bg } });
cmd_input.draw(bottom_bar);

// Render the screen
Expand All @@ -214,7 +208,7 @@ pub fn main() !void {
}

/// User Struct
pub const User = struct{
pub const User = struct {
first: []const u8,
last: []const u8,
user: []const u8,
Expand Down
4 changes: 2 additions & 2 deletions examples/text_input.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn main() !void {

// Start the read loop. This puts the terminal in raw mode and begins
// reading user input
try loop.run(alloc);
try loop.run();
defer loop.stop();

// Optionally enter the alternate screen
Expand Down Expand Up @@ -85,7 +85,7 @@ pub fn main() !void {
loop.stop();
var child = std.process.Child.init(&.{"nvim"}, alloc);
_ = try child.spawnAndWait();
try loop.run(alloc);
try loop.run();
try vx.enterAltScreen();
vx.queueRefresh();
} else if (key.matches(vaxis.Key.enter, .{})) {
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/Table.zig
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn drawTable(
.ul_style = if (idx == table_ctx.col) .single else .dotted,
},
}};
try hdr.wrap(seg[0..]);
_ = try hdr.print(seg[0..], .{ .wrap = .word });
}

const max_items = if (data_list.items.len > table_win.height -| 1) table_win.height -| 1 else data_list.items.len;
Expand Down Expand Up @@ -120,7 +120,7 @@ pub fn drawTable(
.text = if (data.len > table_ctx.col_width and alloc != null) try fmt.allocPrint(alloc.?, "{s}...", .{data[0..(table_ctx.col_width -| 4)]}) else data,
.style = .{ .bg = row_bg },
}};
try row_win.wrap(seg[0..]);
_ = try row_win.print(seg[0..], .{ .wrap = .word });
return;
}
const item_fields = meta.fields(DataT);
Expand Down Expand Up @@ -157,7 +157,7 @@ pub fn drawTable(
.text = if (item_txt.len > table_ctx.col_width and alloc != null) try fmt.allocPrint(alloc.?, "{s}...", .{item_txt[0..(table_ctx.col_width -| 4)]}) else item_txt,
.style = .{ .bg = row_bg },
}};
try item_win.wrap(seg[0..]);
_ = try item_win.print(seg[0..], .{ .wrap = .word });
}
}
}

0 comments on commit 1b957ec

Please sign in to comment.