Module: Tins::Terminal
Overview
A module for handling terminal-related functionality and terminal input/output operations.
Provides methods for interacting with terminal capabilities, reading from standard input, and managing terminal sessions.
Instance Method Summary collapse
-
#columns ⇒ Integer
(also: #cols)
Returns the number of columns in the terminal.
-
#rows ⇒ Integer
(also: #lines)
Returns the number of rows (lines) in the terminal window.
-
#winsize ⇒ Array<Integer>
Returns the window size of the console.
Instance Method Details
#columns ⇒ Integer Also known as: cols
Returns the number of columns in the terminal
This method attempts to determine the terminal width by checking various sources in order of preference: system winsize information, stty output, tput output, and falls back to a default of 80 columns if none are available
55 56 57 58 |
# File 'lib/tins/terminal.rb', line 55 def columns winsize[1] || `stty size 2>/dev/null`.split[1].to_i.nonzero? || `tput cols 2>/dev/null`.to_i.nonzero? || 80 end |
#rows ⇒ Integer Also known as: lines
Returns the number of rows (lines) in the terminal window.
Attempts to determine the terminal size by checking various sources in order of preference: window size, stty command output, tput command output, and defaults to 25 lines if all methods fail.
41 42 43 44 |
# File 'lib/tins/terminal.rb', line 41 def rows winsize[0] || `stty size 2>/dev/null`.split[0].to_i.nonzero? || `tput lines 2>/dev/null`.to_i.nonzero? || 25 end |
#winsize ⇒ Array<Integer>
Returns the window size of the console.
This method attempts to retrieve the terminal window dimensions by accessing the console object and its winsize method.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/tins/terminal.rb', line 21 def winsize if IO.respond_to?(:console) c = IO.console if c.respond_to?(:winsize) c.winsize else [] end else [] end end |