feat: improve layout of filelist view

This commit is contained in:
CJ van den Berg 2024-08-11 21:03:37 +02:00
parent 3a7e124255
commit 3cbca45b82
3 changed files with 32 additions and 16 deletions

View file

@ -587,3 +587,14 @@ pub fn is_directory(rel_path: []const u8) !bool {
dir.close();
return true;
}
pub fn shorten_path(buf: []u8, path: []const u8, removed_prefix: *usize, max_len: usize) []const u8 {
removed_prefix.* = 0;
if (path.len <= max_len) return path;
const ellipsis = "";
const prefix = path.len - max_len;
defer removed_prefix.* = prefix - 1;
@memcpy(buf[0..ellipsis.len], ellipsis);
@memcpy(buf[ellipsis.len .. max_len + ellipsis.len], path[prefix..]);
return buf[0 .. max_len + ellipsis.len];
}