Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(483): adds support for --without-icons feature flag #552

Merged
merged 4 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/colorls/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand 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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)}"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/colorls/flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down