From cd394c0febd41eaf8fef98f973fb6cf3e97fcb56 Mon Sep 17 00:00:00 2001 From: goar5670 Date: Sun, 20 Mar 2022 21:22:43 +0300 Subject: [PATCH] Fix different inode number lengths --- lib/colorls/core.rb | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/colorls/core.rb b/lib/colorls/core.rb index b9ef205..7ffb55b 100644 --- a/lib/colorls/core.rb +++ b/lib/colorls/core.rb @@ -46,6 +46,8 @@ module ColorLS @git_status = init_git_status(show_git) @time_style = time_style @indicator_style = indicator_style + # how much characters an item occupies besides its name + @additional_chars_per_item = 12 + (@show_git ? 4 : 0) + (@show_inode ? 10 : 0) init_colors colors @@ -151,15 +153,8 @@ module ColorLS end end - # how much characters an item occupies besides its name - CHARS_PER_ITEM = 12 - - def additional_chars - CHARS_PER_ITEM + (@show_git ? 4 : 0) + (@show_inode ? 10 : 0) - end - def item_widths - @contents.map { |item| Unicode::DisplayWidth.of(item.show) + additional_chars } + @contents.map { |item| Unicode::DisplayWidth.of(item.show) + @additional_chars_per_item } end def filter_hidden_contents @@ -307,7 +302,7 @@ module ColorLS def inode(content) return '' unless @show_inode - content.stats.ino.to_s.colorize(@colors[:inode]) + content.stats.ino.to_s.rjust(10).colorize(@colors[:inode]) end def long_info(content) @@ -358,7 +353,7 @@ module ColorLS entry = fetch_string(content, *options(content)) line << (' ' * padding) line << ' ' << entry.encode(Encoding.default_external, undef: :replace) - padding = widths[i] - Unicode::DisplayWidth.of(content.show) - additional_chars + padding = widths[i] - Unicode::DisplayWidth.of(content.show) - @additional_chars_per_item end print line << "\n" end