tangled
alpha
login
or
join now
rockorager.dev
/
comlink
2
fork
atom
an experimental irc client
2
fork
atom
overview
issues
pulls
pipelines
ui: handle /quit properly
rockorager.dev
1 year ago
6c2827f5
07e41c24
+12
-23
2 changed files
expand all
collapse all
unified
split
src
app.zig
ui.zig
+4
-23
src/app.zig
···
59
59
60
60
completer: ?Completer,
61
61
62
62
-
should_quit: bool,
63
63
-
64
62
binds: std.ArrayList(Bind),
65
63
66
64
paste_buffer: std.ArrayList(u8),
···
104
102
.bundle = .{},
105
103
.deinited = false,
106
104
.completer = null,
107
107
-
.should_quit = false,
108
105
.buffer_list = .{
109
106
.children = .{
110
107
.builder = .{
···
207
204
for (self.binds.items) |bind| {
208
205
if (key.matches(bind.key.codepoint, bind.key.mods)) {
209
206
switch (bind.command) {
210
210
-
.quit => self.should_quit = true,
207
207
+
.quit => ctx.quit = true,
211
208
.@"next-channel" => self.nextChannel(),
212
209
.@"prev-channel" => self.prevChannel(),
213
210
.redraw => try ctx.queueRefresh(),
···
486
483
},
487
484
.@"next-channel" => self.nextChannel(),
488
485
.@"prev-channel" => self.prevChannel(),
489
489
-
.quit => self.should_quit = true,
486
486
+
.quit => {
487
487
+
if (self.ctx) |ctx| ctx.quit = true;
488
488
+
},
490
489
.who => {
491
490
if (channel == null) return error.InvalidCommand;
492
491
const msg = try std.fmt.bufPrint(
···
630
629
}
631
630
}
632
631
}
633
633
-
634
634
-
/// Returns the number of lines the segments would consume in the given window
635
635
-
fn lineCountForWindow(win: vaxis.Window, segments: []const vaxis.Segment) usize {
636
636
-
// Fastpath if we have fewer bytes than the width
637
637
-
var byte_count: usize = 0;
638
638
-
for (segments) |segment| {
639
639
-
byte_count += segment.text.len;
640
640
-
}
641
641
-
// One line if we are fewer bytes than the width
642
642
-
if (byte_count <= win.width) return 1;
643
643
-
644
644
-
// Slow path. We have to layout the text
645
645
-
const result = win.print(segments, .{ .commit = false, .wrap = .word }) catch return 0;
646
646
-
if (result.col == 0)
647
647
-
return result.row
648
648
-
else
649
649
-
return result.row + 1;
650
650
-
}
+8
src/ui.zig
···
1
1
+
const std = @import("std");
2
2
+
const vaxis = @import("vaxis");
3
3
+
4
4
+
const vxfw = vaxis.vxfw;
5
5
+
6
6
+
const Allocator = std.mem.Allocator;
7
7
+
8
8
+
pub const main = struct {};