Class: TTY::Terminal
- Inherits:
-
Object
- Object
- TTY::Terminal
- Defined in:
- lib/tty/terminal.rb
Constant Summary collapse
- @@default_width =
80
- @@default_height =
24
Instance Method Summary collapse
-
#color? ⇒ Boolean
Check if terminal supports color.
-
#default_height ⇒ Integer
Return default height of terminal.
-
#default_height=(height) ⇒ Integer
Set default height of terminal.
-
#default_width ⇒ Integer
Return default width of terminal.
-
#default_width=(width) ⇒ Integer
Set default width of terminal.
-
#dynamic_height ⇒ Integer
Calculate dynamic height of the terminal.
-
#dynamic_height_stty ⇒ Integer
Detect terminal height with stty utility.
-
#dynamic_height_tput ⇒ Integer
Detect terminal height with tput utility.
-
#dynamic_width ⇒ Integer
Calculate dynamic width of the terminal.
-
#dynamic_width_stty ⇒ Integer
Detect terminal width with stty utility.
-
#dynamic_width_tput ⇒ Integer
Detect terminal width with tput utility.
-
#height ⇒ Object
Determine current height.
-
#width ⇒ Integer
Determine current width.
Instance Method Details
#color? ⇒ Boolean
Check if terminal supports color
144 145 146 |
# File 'lib/tty/terminal.rb', line 144 def color? %x{tput colors 2>/dev/null}.to_i > 2 end |
#default_height ⇒ Integer
Return default height of terminal
41 42 43 |
# File 'lib/tty/terminal.rb', line 41 def default_height @@default_height end |
#default_height=(height) ⇒ Integer
Set default height of terminal
53 54 55 |
# File 'lib/tty/terminal.rb', line 53 def default_height=(height) @@default_height = height end |
#default_width ⇒ Integer
Return default width of terminal
18 19 20 |
# File 'lib/tty/terminal.rb', line 18 def default_width @@default_width end |
#default_width=(width) ⇒ Integer
Set default width of terminal
29 30 31 |
# File 'lib/tty/terminal.rb', line 29 def default_width=(width) @@default_width = width end |
#dynamic_height ⇒ Integer
Calculate dynamic height of the terminal
99 100 101 |
# File 'lib/tty/terminal.rb', line 99 def dynamic_height @dynamic_height ||= (dynamic_height_stty.nonzero? || dynamic_height_tput) end |
#dynamic_height_stty ⇒ Integer
Detect terminal height with stty utility
117 118 119 |
# File 'lib/tty/terminal.rb', line 117 def dynamic_height_stty %x{stty size 2>/dev/null}.split[0].to_i end |
#dynamic_height_tput ⇒ Integer
Detect terminal height with tput utility
135 136 137 |
# File 'lib/tty/terminal.rb', line 135 def dynamic_height_tput %x{tput lines 2>/dev/null}.to_i end |
#dynamic_width ⇒ Integer
Calculate dynamic width of the terminal
90 91 92 |
# File 'lib/tty/terminal.rb', line 90 def dynamic_width @dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput) end |
#dynamic_width_stty ⇒ Integer
Detect terminal width with stty utility
108 109 110 |
# File 'lib/tty/terminal.rb', line 108 def dynamic_width_stty %x{stty size 2>/dev/null}.split[1].to_i end |
#dynamic_width_tput ⇒ Integer
Detect terminal width with tput utility
126 127 128 |
# File 'lib/tty/terminal.rb', line 126 def dynamic_width_tput %x{tput cols 2>/dev/null}.to_i end |