Module: Toys::StandardMixins::Terminal
- Includes:
- Mixin
- Defined in:
- lib/toys/standard_mixins/terminal.rb
Overview
A mixin that provides a simple terminal. It includes a set of methods that produce styled output, get user input, and otherwise interact with the user's terminal. This mixin is not as richly featured as other mixins such as Highline, but it has no gem dependencies so is ideal for basic cases.
You may make these methods available to your tool by including the following directive in your tool configuration:
include :terminal
A Terminal object will then be available by calling the #terminal method. For information on using this object, see the documentation for Utils::Terminal. Some of the most useful methods are also mixed into the tool and can be called directly.
You can configure the Terminal object by passing options to the include
directive. For example:
include :terminal, styled: true
The arguments will be passed on to Utils::Terminal#initialize.
Constant Summary collapse
- KEY =
Context key for the terminal object.
::Object.new.freeze
Instance Method Summary collapse
- #ask(prompt, *styles, default: nil, trailing_text: :default) ⇒ Object
- #confirm(prompt = "Proceed?", *styles, default: nil) ⇒ Object
- #puts(str = "", *styles) ⇒ Object (also: #say)
- #spinner(leading_text: "", final_text: "", frame_length: nil, frames: nil, style: nil, &block) ⇒ Object
-
#terminal ⇒ Toys::Utils::Terminal
Returns a tool-wide terminal instance.
- #write(str = "", *styles) ⇒ Object
Instance Method Details
#ask(prompt, *styles, default: nil, trailing_text: :default) ⇒ Object
97 98 99 |
# File 'lib/toys/standard_mixins/terminal.rb', line 97 def ask(prompt, *styles, default: nil, trailing_text: :default) terminal.ask(prompt, *styles, default: default, trailing_text: trailing_text) end |
#confirm(prompt = "Proceed?", *styles, default: nil) ⇒ Object
104 105 106 |
# File 'lib/toys/standard_mixins/terminal.rb', line 104 def confirm(prompt = "Proceed?", *styles, default: nil) terminal.confirm(prompt, *styles, default: default) end |
#puts(str = "", *styles) ⇒ Object Also known as: say
82 83 84 |
# File 'lib/toys/standard_mixins/terminal.rb', line 82 def puts(str = "", *styles) terminal.puts(str, *styles) end |
#spinner(leading_text: "", final_text: "", frame_length: nil, frames: nil, style: nil, &block) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/toys/standard_mixins/terminal.rb', line 111 def spinner(leading_text: "", final_text: "", frame_length: nil, frames: nil, style: nil, &block) terminal.spinner(leading_text: leading_text, final_text: final_text, frame_length: frame_length, frames: frames, style: style, &block) end |
#terminal ⇒ Toys::Utils::Terminal
Returns a tool-wide terminal instance
75 76 77 |
# File 'lib/toys/standard_mixins/terminal.rb', line 75 def terminal self[KEY] end |
#write(str = "", *styles) ⇒ Object
90 91 92 |
# File 'lib/toys/standard_mixins/terminal.rb', line 90 def write(str = "", *styles) terminal.write(str, *styles) end |