mirror of
https://github.com/athityakumar/colorls.git
synced 2024-09-19 05:31:23 +02:00
Account for git status and inode in item widths
This commit is contained in:
parent
793cd20cc8
commit
fb102b1700
2 changed files with 11 additions and 5 deletions
|
@ -26,6 +26,7 @@ module ColorLS
|
||||||
|
|
||||||
class Core
|
class Core
|
||||||
def initialize(all: false, sort: false, show: false,
|
def initialize(all: false, sort: false, show: false,
|
||||||
|
mode: nil, show_git: false, almost_all: false, colors: [], group: nil,
|
||||||
reverse: false, hyperlink: false, tree_depth: nil, show_inode: false, show_group: true, show_user: true,
|
reverse: false, hyperlink: false, tree_depth: nil, show_inode: false, show_group: true, show_user: true,
|
||||||
indicator_style: 'slash', time_style: '')
|
indicator_style: 'slash', time_style: '')
|
||||||
@count = {folders: 0, recognized_files: 0, unrecognized_files: 0}
|
@count = {folders: 0, recognized_files: 0, unrecognized_files: 0}
|
||||||
|
@ -41,7 +42,8 @@ module ColorLS
|
||||||
init_long_format(mode,show_group,show_user)
|
init_long_format(mode,show_group,show_user)
|
||||||
@tree = {mode: mode == :tree, depth: tree_depth}
|
@tree = {mode: mode == :tree, depth: tree_depth}
|
||||||
@horizontal = mode == :horizontal
|
@horizontal = mode == :horizontal
|
||||||
@git_status = init_git_status(git_status)
|
@show_git = show_git
|
||||||
|
@git_status = init_git_status(show_git)
|
||||||
@time_style = time_style
|
@time_style = time_style
|
||||||
@indicator_style = indicator_style
|
@indicator_style = indicator_style
|
||||||
|
|
||||||
|
@ -152,8 +154,12 @@ module ColorLS
|
||||||
# how much characters an item occupies besides its name
|
# how much characters an item occupies besides its name
|
||||||
CHARS_PER_ITEM = 12
|
CHARS_PER_ITEM = 12
|
||||||
|
|
||||||
|
def additional_chars
|
||||||
|
CHARS_PER_ITEM + (@show_git ? 4 : 0) + (@show_inode ? 10 : 0)
|
||||||
|
end
|
||||||
|
|
||||||
def item_widths
|
def item_widths
|
||||||
@contents.map { |item| Unicode::DisplayWidth.of(item.show) + CHARS_PER_ITEM }
|
@contents.map { |item| Unicode::DisplayWidth.of(item.show) + additional_chars }
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_hidden_contents
|
def filter_hidden_contents
|
||||||
|
@ -351,7 +357,7 @@ module ColorLS
|
||||||
entry = fetch_string(content, *options(content))
|
entry = fetch_string(content, *options(content))
|
||||||
line << (' ' * padding)
|
line << (' ' * padding)
|
||||||
line << ' ' << entry.encode(Encoding.default_external, undef: :replace)
|
line << ' ' << entry.encode(Encoding.default_external, undef: :replace)
|
||||||
padding = widths[i] - Unicode::DisplayWidth.of(content.show) - CHARS_PER_ITEM
|
padding = widths[i] - Unicode::DisplayWidth.of(content.show) - additional_chars
|
||||||
end
|
end
|
||||||
print line << "\n"
|
print line << "\n"
|
||||||
end
|
end
|
||||||
|
|
|
@ -102,7 +102,7 @@ module ColorLS
|
||||||
mode: STDOUT.tty? ? :vertical : :one_per_line, # rubocop:disable Style/GlobalStdStream
|
mode: STDOUT.tty? ? :vertical : :one_per_line, # rubocop:disable Style/GlobalStdStream
|
||||||
all: false,
|
all: false,
|
||||||
almost_all: false,
|
almost_all: false,
|
||||||
git_status: false,
|
show_git: false,
|
||||||
colors: [],
|
colors: [],
|
||||||
tree_depth: 3,
|
tree_depth: 3,
|
||||||
show_inode: false,
|
show_inode: false,
|
||||||
|
@ -142,7 +142,7 @@ module ColorLS
|
||||||
options.on('-A', '--almost-all', 'do not list . and ..') { @opts[:almost_all] = true }
|
options.on('-A', '--almost-all', 'do not list . and ..') { @opts[:almost_all] = true }
|
||||||
options.on('-d', '--dirs', 'show only directories') { @opts[:show] = :dirs }
|
options.on('-d', '--dirs', 'show only directories') { @opts[:show] = :dirs }
|
||||||
options.on('-f', '--files', 'show only files') { @opts[:show] = :files }
|
options.on('-f', '--files', 'show only files') { @opts[:show] = :files }
|
||||||
options.on('--gs', '--git-status', 'show git status for each file') { @opts[:git_status] = true }
|
options.on('--gs', '--git-status', 'show git status for each file') { @opts[:show_git] = true }
|
||||||
options.on('-p', 'append / indicator to directories') { @opts[:indicator_style] = 'slash' }
|
options.on('-p', 'append / indicator to directories') { @opts[:indicator_style] = 'slash' }
|
||||||
options.on('-i', '--inode', 'show inode number') { @opts[:show_inode] = true }
|
options.on('-i', '--inode', 'show inode number') { @opts[:show_inode] = true }
|
||||||
options.on('--report=[WORD]', %w[short long], 'show report: short, long (default if omitted)') do |word|
|
options.on('--report=[WORD]', %w[short long], 'show report: short, long (default if omitted)') do |word|
|
||||||
|
|
Loading…
Reference in a new issue