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 paste and message limit indicator
rockorager.dev
1 year ago
254d636a
72827f70
+61
-7
3 changed files
expand all
collapse all
unified
split
build.zig.zon
src
app.zig
irc.zig
+2
-2
build.zig.zon
···
7
7
.hash = "1220affeb3fe37ef09411b5a213b5fdf9bb6568e9913bade204694648983a8b2776d",
8
8
},
9
9
.vaxis = .{
10
10
-
.url = "git+https://github.com/rockorager/libvaxis#af450ebb1ba068c5d44d7c878fa5157188094c0a",
11
11
-
.hash = "1220212b2aa3c0148526494403917994acc01aec1f123634df5fe843e7f034c0b703",
10
10
+
.url = "git+https://github.com/rockorager/libvaxis#bcc1d027cb2ede571bb76669441d2e09944bd3d3",
11
11
+
.hash = "1220fca568653885767394bc659714e0e9ccda935e5c02d4333b1d60b064bc6ac0bc",
12
12
},
13
13
.zeit = .{
14
14
.url = "git+https://github.com/rockorager/zeit?ref=main#d943bc4bfe9e18490460dfdd64f48e997065eba8",
+27
src/app.zig
···
198
198
self.ctx = ctx;
199
199
switch (event) {
200
200
.key_press => |key| {
201
201
+
if (self.state.paste.pasting) {
202
202
+
ctx.consume_event = true;
203
203
+
// Always ignore enter key
204
204
+
if (key.codepoint == vaxis.Key.enter) return;
205
205
+
if (key.text) |text| {
206
206
+
try self.paste_buffer.appendSlice(text);
207
207
+
}
208
208
+
return;
209
209
+
}
201
210
if (key.matches('c', .{ .ctrl = true })) {
202
211
ctx.quit = true;
203
212
}
···
212
221
else => {},
213
222
}
214
223
return ctx.consumeAndRedraw();
224
224
+
}
225
225
+
}
226
226
+
},
227
227
+
.paste_start => self.state.paste.pasting = true,
228
228
+
.paste_end => {
229
229
+
self.state.paste.pasting = false;
230
230
+
if (std.mem.indexOfScalar(u8, self.paste_buffer.items, '\n')) |_| {
231
231
+
log.debug("paste had line ending", .{});
232
232
+
return;
233
233
+
}
234
234
+
defer self.paste_buffer.clearRetainingCapacity();
235
235
+
if (self.selectedBuffer()) |buffer| {
236
236
+
switch (buffer) {
237
237
+
.client => {},
238
238
+
.channel => |channel| {
239
239
+
try channel.text_field.insertSliceAtCursor(self.paste_buffer.items);
240
240
+
return ctx.consumeAndRedraw();
241
241
+
},
215
242
}
216
243
}
217
244
},
+32
-5
src/irc.zig
···
620
620
.surface = scrollbar_surface,
621
621
});
622
622
623
623
-
// Draw the text field
624
624
-
try children.append(.{
625
625
-
.origin = .{ .col = 0, .row = max.height - 1 },
626
626
-
.surface = try self.text_field.draw(ctx),
627
627
-
});
623
623
+
{
624
624
+
// Draw the character limit. 14 is length of message overhead "PRIVMSG :\r\n"
625
625
+
const max_limit = maximum_message_size -| self.name.len -| 14 -| self.name.len;
626
626
+
const limit = try std.fmt.allocPrint(
627
627
+
ctx.arena,
628
628
+
"{d}/{d}",
629
629
+
.{ self.text_field.buf.realLength(), max_limit },
630
630
+
);
631
631
+
const style: vaxis.Style = if (self.text_field.buf.realLength() > max_limit)
632
632
+
.{ .fg = .{ .index = 1 } }
633
633
+
else
634
634
+
.{ .dim = true };
635
635
+
const limit_text: vxfw.Text = .{ .text = limit, .style = style };
636
636
+
const limit_ctx = ctx.withConstraints(.{}, ctx.max);
637
637
+
const limit_s = try limit_text.draw(limit_ctx);
638
638
+
639
639
+
try children.append(.{
640
640
+
.origin = .{ .col = max.width -| limit_s.size.width, .row = max.height - 1 },
641
641
+
.surface = limit_s,
642
642
+
});
643
643
+
644
644
+
const text_field_ctx = ctx.withConstraints(
645
645
+
ctx.min,
646
646
+
.{ .height = 1, .width = max.width -| limit_s.size.width -| 1 },
647
647
+
);
648
648
+
649
649
+
// Draw the text field
650
650
+
try children.append(.{
651
651
+
.origin = .{ .col = 0, .row = max.height - 1 },
652
652
+
.surface = try self.text_field.draw(text_field_ctx),
653
653
+
});
654
654
+
}
628
655
629
656
if (self.completer_shown) {
630
657
const widest: u16 = @intCast(self.completer.widestMatch(ctx));