diff --git a/lib/colorls/core.rb b/lib/colorls/core.rb index 5a674553..7448e830 100644 --- a/lib/colorls/core.rb +++ b/lib/colorls/core.rb @@ -28,7 +28,7 @@ class Core 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, - indicator_style: 'slash', long_style_options: {}) + indicator_style: 'slash', long_style_options: {}, icons: true) @count = {folders: 0, recognized_files: 0, unrecognized_files: 0} @all = all @almost_all = almost_all @@ -46,14 +46,16 @@ def initialize(all: false, sort: false, show: false, @time_style = long_style_options.key?(:time_style) ? long_style_options[:time_style] : '' @indicator_style = indicator_style @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 - @additional_chars_per_item = 12 + (@show_git ? 4 : 0) + (@show_inode ? 10 : 0) + @icons = icons init_colors colors - init_icons end + def additional_chars_per_item + 12 + (@show_git ? 4 : 0) + (@show_inode ? 10 : 0) + end + def ls_dir(info) if @tree[:mode] print "\n" @@ -155,7 +157,7 @@ def init_git_status(show_git) end 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 def filter_hidden_contents @@ -341,7 +343,7 @@ def fetch_string(content, key, color, increment) logo = value.gsub(/\\u[\da-f]{4}/i) { |m| [m[-4..].to_i(16)].pack('U') } name = @hyperlink ? make_link(content) : content.show 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? "#{inode(content)} #{long_info(content)} #{git_info(content)} #{entry.colorize(color)}#{symlink_info(content)}" @@ -354,7 +356,7 @@ def ls_line(chunk, widths) 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_per_item + padding = widths[i] - Unicode::DisplayWidth.of(content.show) - additional_chars_per_item end print line << "\n" end diff --git a/lib/colorls/flags.rb b/lib/colorls/flags.rb index d80c245a..41b288c6 100644 --- a/lib/colorls/flags.rb +++ b/lib/colorls/flags.rb @@ -175,6 +175,7 @@ def add_format_options(options) end 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('--without-icons', 'list entries without icons') { @opts[:icons] = false } end def default_long_style_options