Use console_size if console is nil

When running on github actions CI, there is no proper tty / console.
This commit is contained in:
Claudio Bley 2020-12-08 23:07:28 +01:00 committed by Claudio Bley
parent 74adb532bf
commit 22fb57ac21
2 changed files with 12 additions and 2 deletions

View file

@ -5,6 +5,7 @@ require 'etc'
require 'English'
require 'filesize'
require 'io/console'
require 'io/console/size'
require 'rainbow/ext/string'
require 'clocale'
require 'unicode/display_width'

View file

@ -8,8 +8,17 @@ module ColorLS
@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