Compare commits
3 commits
308f46c8a2
...
660449c1c0
| Author | SHA1 | Date | |
|---|---|---|---|
| 660449c1c0 | |||
| 99b721febf | |||
|
|
99a4fb0936 |
2 changed files with 9 additions and 6 deletions
|
|
@ -90,11 +90,11 @@ pub fn toggle_prefix_in_text(prefix: []const u8, text: []const u8, allocator: st
|
|||
return result.toOwnedSlice(allocator);
|
||||
}
|
||||
|
||||
pub fn write_string(writer: anytype, string: []const u8, pad: ?usize) !void {
|
||||
pub fn write_string(writer: *std.Io.Writer, string: []const u8, pad: ?usize) !void {
|
||||
try writer.writeAll(string);
|
||||
if (pad) |pad_| try write_padding(writer, string.len, pad_);
|
||||
}
|
||||
|
||||
pub fn write_padding(writer: anytype, len: usize, pad_len: usize) !void {
|
||||
pub fn write_padding(writer: *std.Io.Writer, len: usize, pad_len: usize) !void {
|
||||
for (0..pad_len - len) |_| try writer.writeAll(" ");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ fn update_max_col_sizes(palette: *Type, comp_sizes: []const usize) u8 {
|
|||
return total_length;
|
||||
}
|
||||
|
||||
fn write_columns(palette: *Type, writer: anytype, column_info: [][]const u8) void {
|
||||
fn write_columns(palette: *Type, writer: *std.Io.Writer, column_info: [][]const u8) void {
|
||||
if (palette.value.column_size.len == 0)
|
||||
return;
|
||||
write_string(writer, column_info[0][0..@min(palette.value.column_size[0], column_info[0].len)], columns[0].max_width) catch {};
|
||||
|
|
@ -108,10 +108,12 @@ pub fn load_entries(palette: *Type) !usize {
|
|||
var cbor_item: []const u8 = undefined;
|
||||
if (!try cbor.matchValue(&iter, cbor.extract_cbor(&cbor_item))) return error.BadCompletion;
|
||||
const label_, const parent_, const kind, const sel = get_values(cbor_item);
|
||||
const label_len_ = tui.egc_chunk_width(label_, 0, 1);
|
||||
const parent_len = tui.egc_chunk_width(parent_, 0, 1);
|
||||
(try palette.entries.addOne(palette.allocator)).* = .{ .cbor = cbor_item, .label = label_[0..@min(columns[0].max_width, label_.len)], .range = sel };
|
||||
|
||||
const current_lengths: [3]usize = .{ label_.len, parent_.len, @tagName(kind).len };
|
||||
const label_len: u8 = @truncate(if (label_.len > columns[0].max_width) columns[0].max_width else label_.len);
|
||||
const current_lengths: [3]usize = .{ label_len_, parent_len, @tagName(kind).len };
|
||||
const label_len: u8 = @truncate(if (label_len_ > columns[0].max_width) columns[0].max_width else label_len_);
|
||||
max_cols_len = @max(max_cols_len, label_len, update_max_col_sizes(palette, ¤t_lengths));
|
||||
max_label_len = @max(max_label_len, label_len);
|
||||
}
|
||||
|
|
@ -128,7 +130,8 @@ pub fn load_entries(palette: *Type) !usize {
|
|||
palette.quick_activate_enabled = false;
|
||||
|
||||
const total_width = total_row_width();
|
||||
return 2 + if (max_cols_len > label.len + 3) total_width - max_label_len else label.len + 1 - max_cols_len;
|
||||
const outer_label_len = tui.egc_chunk_width(label, 0, 1);
|
||||
return 2 + if (max_cols_len > outer_label_len + 3) total_width - max_label_len else outer_label_len + 1 - max_cols_len;
|
||||
}
|
||||
|
||||
pub fn clear_entries(palette: *Type) void {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue