Merge pull request #552 from karandeepmadaan/feature/without-icons

feat(483): adds support for `--without-icons` feature flag
This commit is contained in:
Athitya Kumar 2022-10-27 14:34:52 +05:30 committed by GitHub
commit a0a78da84d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View file

@ -28,7 +28,7 @@ module ColorLS
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, mode: nil, show_git: false, almost_all: false, colors: [], group: nil,
reverse: false, hyperlink: false, tree_depth: nil, show_inode: false, reverse: false, hyperlink: false, tree_depth: nil, show_inode: false,
indicator_style: 'slash', long_style_options: {}) indicator_style: 'slash', long_style_options: {}, icons: true)
@count = {folders: 0, recognized_files: 0, unrecognized_files: 0} @count = {folders: 0, recognized_files: 0, unrecognized_files: 0}
@all = all @all = all
@almost_all = almost_all @almost_all = almost_all
@ -46,14 +46,16 @@ module ColorLS
@time_style = long_style_options.key?(:time_style) ? long_style_options[:time_style] : '' @time_style = long_style_options.key?(:time_style) ? long_style_options[:time_style] : ''
@indicator_style = indicator_style @indicator_style = indicator_style
@hard_links_count = long_style_options.key?(:hard_links_count) ? long_style_options[:hard_links_count] : true @hard_links_count = long_style_options.key?(:hard_links_count) ? long_style_options[:hard_links_count] : true
# how much characters an item occupies besides its name @icons = icons
@additional_chars_per_item = 12 + (@show_git ? 4 : 0) + (@show_inode ? 10 : 0)
init_colors colors init_colors colors
init_icons init_icons
end end
def additional_chars_per_item
12 + (@show_git ? 4 : 0) + (@show_inode ? 10 : 0)
end
def ls_dir(info) def ls_dir(info)
if @tree[:mode] if @tree[:mode]
print "\n" print "\n"
@ -155,7 +157,7 @@ module ColorLS
end end
def item_widths def item_widths
@contents.map { |item| Unicode::DisplayWidth.of(item.show) + @additional_chars_per_item } @contents.map { |item| Unicode::DisplayWidth.of(item.show) + additional_chars_per_item }
end end
def filter_hidden_contents def filter_hidden_contents
@ -341,7 +343,7 @@ module ColorLS
logo = value.gsub(/\\u[\da-f]{4}/i) { |m| [m[-4..].to_i(16)].pack('U') } logo = value.gsub(/\\u[\da-f]{4}/i) { |m| [m[-4..].to_i(16)].pack('U') }
name = @hyperlink ? make_link(content) : content.show name = @hyperlink ? make_link(content) : content.show
name += content.directory? && @indicator_style != 'none' ? '/' : ' ' name += content.directory? && @indicator_style != 'none' ? '/' : ' '
entry = "#{out_encode(logo)} #{out_encode(name)}" entry = @icons ? "#{out_encode(logo)} #{out_encode(name)}" : out_encode(name).to_s
entry = entry.bright if !content.directory? && content.executable? entry = entry.bright if !content.directory? && content.executable?
"#{inode(content)} #{long_info(content)} #{git_info(content)} #{entry.colorize(color)}#{symlink_info(content)}" "#{inode(content)} #{long_info(content)} #{git_info(content)} #{entry.colorize(color)}#{symlink_info(content)}"
@ -354,7 +356,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) - @additional_chars_per_item padding = widths[i] - Unicode::DisplayWidth.of(content.show) - additional_chars_per_item
end end
print line << "\n" print line << "\n"
end end

View file

@ -175,6 +175,7 @@ module ColorLS
end end
options.on('-x', 'list entries by lines instead of by columns') { @opts[:mode] = :horizontal } options.on('-x', 'list entries by lines instead of by columns') { @opts[:mode] = :horizontal }
options.on('-C', 'list entries by columns instead of by lines') { @opts[:mode] = :vertical } options.on('-C', 'list entries by columns instead of by lines') { @opts[:mode] = :vertical }
options.on('--without-icons', 'list entries without icons') { @opts[:icons] = false }
end end
def default_long_style_options def default_long_style_options