Module: CLI::UI::Terminal
- Defined in:
- lib/cli/ui/terminal.rb
Constant Summary collapse
- DEFAULT_WIDTH =
80
- DEFAULT_HEIGHT =
24
Class Method Summary collapse
-
.height ⇒ Object
Returns the width of the terminal, if possible Otherwise, will return DEFAULT_HEIGHT.
- .setup_winsize_trap ⇒ Object
-
.width ⇒ Object
Returns the width of the terminal, if possible Otherwise will return DEFAULT_WIDTH.
- .winsize ⇒ Object
Class Method Details
.height ⇒ Object
Returns the width of the terminal, if possible Otherwise, will return DEFAULT_HEIGHT
20 21 22 |
# File 'lib/cli/ui/terminal.rb', line 20 def self.height winsize[0] end |
.setup_winsize_trap ⇒ Object
39 40 41 42 43 |
# File 'lib/cli/ui/terminal.rb', line 39 def self.setup_winsize_trap @winsize_trap ||= Signal.trap('WINCH') do @winsize = nil end end |
.width ⇒ Object
Returns the width of the terminal, if possible Otherwise will return DEFAULT_WIDTH
13 14 15 |
# File 'lib/cli/ui/terminal.rb', line 13 def self.width winsize[1] end |
.winsize ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cli/ui/terminal.rb', line 24 def self.winsize @winsize ||= begin winsize = IO.console.winsize setup_winsize_trap if winsize.any?(&:zero?) [DEFAULT_HEIGHT, DEFAULT_WIDTH] else winsize end rescue [DEFAULT_HEIGHT, DEFAULT_WIDTH] end end |