Skip to content
New issue

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

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

Already on GitHub? # to your account

Take display width of characters into account #419

Merged
merged 2 commits into from
Nov 23, 2020
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
3 changes: 2 additions & 1 deletion colorls.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'filesize', '~> 0'
spec.add_runtime_dependency 'manpages', '~> 0'
spec.add_runtime_dependency 'rainbow', '>= 2.2', '< 4.0'
spec.add_runtime_dependency 'unicode-display_width', '~> 1.7'

spec.add_development_dependency 'bundler', '~> 2.0'
spec.add_development_dependency 'codecov', '~> 0.1'
Expand All @@ -73,7 +74,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rspec', '~> 3.7'
spec.add_development_dependency 'rspec-its', '~> 1.2'
spec.add_development_dependency 'rubocop', '~> 1.3.0'
spec.add_development_dependency 'rubocop-performance', '~> 1.8.0'
spec.add_development_dependency 'rubocop-performance', '~> 1.9.0'
spec.add_development_dependency 'rubocop-rspec', '~> 2.0'
spec.add_development_dependency 'rubygems-tasks', '~> 0'
spec.add_development_dependency 'simplecov', '~> 0.19.0'
Expand Down
1 change: 1 addition & 0 deletions lib/colorls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'io/console'
require 'rainbow/ext/string'
require 'clocale'
require 'unicode/display_width'

require 'colorls/core'
require 'colorls/fileinfo'
Expand Down
4 changes: 2 additions & 2 deletions lib/colorls/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def init_colors(colors)
CHARS_PER_ITEM = 12

def item_widths
@contents.map { |item| item.show.size + CHARS_PER_ITEM }
@contents.map { |item| Unicode::DisplayWidth.of(item.show) + CHARS_PER_ITEM }
end

def init_contents(path)
Expand Down Expand Up @@ -314,7 +314,7 @@ def ls_line(chunk, widths)
entry = fetch_string(@input, content, *options(content))
line << ' ' * padding
line << ' ' << entry.encode(Encoding.default_external, undef: :replace)
padding = widths[i] - content.show.length - CHARS_PER_ITEM
padding = widths[i] - Unicode::DisplayWidth.of(content.show) - CHARS_PER_ITEM
end
print line << "\n"
end
Expand Down