From 11c830281578f312e985b7cd12d6dc163d1f4485 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2020 23:12:57 +0000 Subject: [PATCH 1/2] Update rubocop-performance requirement from ~> 1.8.0 to ~> 1.9.0 Updates the requirements on [rubocop-performance](https://github.com/rubocop-hq/rubocop-performance) to permit the latest version. - [Release notes](https://github.com/rubocop-hq/rubocop-performance/releases) - [Changelog](https://github.com/rubocop-hq/rubocop-performance/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubocop-hq/rubocop-performance/compare/v1.8.0...v1.9.0) Signed-off-by: dependabot-preview[bot] --- colorls.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/colorls.gemspec b/colorls.gemspec index df918cc6..17839796 100644 --- a/colorls.gemspec +++ b/colorls.gemspec @@ -73,7 +73,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' From 67ee23069c70c2ab354d891c1b0d580137dfc489 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Sun, 22 Nov 2020 21:29:51 +0100 Subject: [PATCH 2/2] Take display width of characters into account Some Unicode characters, e.g. chinese, consume more space when displayed on a terminal than a single roman character. To avoid alignment issues, try to determine the width using the unicode-display_width gem. --- colorls.gemspec | 1 + lib/colorls.rb | 1 + lib/colorls/core.rb | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/colorls.gemspec b/colorls.gemspec index 17839796..d303687c 100644 --- a/colorls.gemspec +++ b/colorls.gemspec @@ -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' diff --git a/lib/colorls.rb b/lib/colorls.rb index ddae64ef..87872466 100644 --- a/lib/colorls.rb +++ b/lib/colorls.rb @@ -7,6 +7,7 @@ require 'io/console' require 'rainbow/ext/string' require 'clocale' +require 'unicode/display_width' require 'colorls/core' require 'colorls/fileinfo' diff --git a/lib/colorls/core.rb b/lib/colorls/core.rb index 1cee9098..f560ffc7 100644 --- a/lib/colorls/core.rb +++ b/lib/colorls/core.rb @@ -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) @@ -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