diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml new file mode 100644 index 00000000..ba844b97 --- /dev/null +++ b/.github/workflows/ruby.yml @@ -0,0 +1,32 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake +# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby + +name: Ruby + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + + runs-on: ubuntu-latest + strategy: + matrix: + ruby-version: ['2.6', '2.7', '3.0'] + + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - name: Run tests + run: bundle exec rake diff --git a/lib/colorls.rb b/lib/colorls.rb index 57f369db..33a350d2 100644 --- a/lib/colorls.rb +++ b/lib/colorls.rb @@ -5,6 +5,7 @@ require 'English' require 'filesize' require 'io/console' +require 'io/console/size' require 'rainbow/ext/string' require 'clocale' require 'unicode/display_width' diff --git a/lib/colorls/core.rb b/lib/colorls/core.rb index 5ec1f3e8..b7300b82 100644 --- a/lib/colorls/core.rb +++ b/lib/colorls/core.rb @@ -8,8 +8,17 @@ def self.file_encoding @file_encoding end - @screen_width = IO.console.winsize[1] - @screen_width = 80 if @screen_width.zero? + def self.terminal_width + console = IO.console + + width = IO.console_size[1] + + return width if console.nil? || console.winsize[1].zero? + + console.winsize[1] + end + + @screen_width = terminal_width def self.screen_width @screen_width