Module: Dry::CLI::Help::Terminal
- Defined in:
- lib/dry/cli/help/terminal.rb,
sig/dry/cli/help.rbs
Overview
The width of the terminal help prints to.
Constant Summary collapse
- FALLBACK_WIDTH =
80
Class Method Summary collapse
- .from_console(console) ⇒ Integer?
- .from_env(env) ⇒ Integer?
-
.width(env: ENV, console: IO.console) ⇒ Integer
COLUMNSwins over the console, so a user or a test can pin the width.
Class Method Details
.from_console(console) ⇒ Integer?
30 31 32 33 34 35 |
# File 'lib/dry/cli/help/terminal.rb', line 30 def from_console(console) columns = console&.winsize&.last columns if columns&.positive? rescue SystemCallError nil end |
.from_env(env) ⇒ Integer?
24 25 26 27 |
# File 'lib/dry/cli/help/terminal.rb', line 24 def from_env(env) columns = Integer(env.fetch("COLUMNS", ""), exception: false) columns if columns&.positive? end |
.width(env: ENV, console: IO.console) ⇒ Integer
COLUMNS wins over the console, so a user or a test can pin the width.
19 20 21 |
# File 'lib/dry/cli/help/terminal.rb', line 19 def width(env: ENV, console: IO.console) from_env(env) || from_console(console) || FALLBACK_WIDTH end |