feat: trip leading whitespace from clipboard history palette display

This commit is contained in:
CJ van den Berg 2025-10-13 20:27:43 +02:00
parent 6c6a8cee32
commit 46def038bd
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -24,8 +24,13 @@ pub fn load_entries(palette: *Type) !usize {
if (history.len > 0) {
var idx = history.len - 1;
while (true) : (idx -= 1) {
var label_ = history[idx];
while (label_.len > 0) switch (label_[0]) {
' ', '\t', '\n' => label_ = label_[1..],
else => break,
};
(try palette.entries.addOne(palette.allocator)).* = .{
.label = history[idx],
.label = label_,
.idx = idx,
};
if (idx == 0) break;
@ -46,14 +51,15 @@ pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !v
var hint: std.Io.Writer.Allocating = .init(palette.allocator);
defer hint.deinit();
const item = if (tui.clipboard_get_history()) |clipboard| clipboard[entry.idx] else &.{};
var line_count: usize = 1;
for (0..entry.label.len) |i| if (entry.label[i] == '\n') {
for (0..item.len) |i| if (item[i] == '\n') {
line_count += 1;
};
if (line_count > 1)
try hint.writer.print(" {d} lines", .{line_count})
else
try hint.writer.print(" {d} {s}", .{ entry.label.len, if (entry.label.len == 1) "byte" else "bytes" });
try hint.writer.print(" {d} {s}", .{ item.len, if (item.len == 1) "byte " else "bytes" });
try cbor.writeValue(writer, hint.written());
try cbor.writeValue(writer, matches orelse &[_]usize{});