Class: NattyUI::Element
- Inherits:
-
Object
- Object
- NattyUI::Element
- Includes:
- Features
- Defined in:
- lib/natty-ui/element.rb
Overview
Base class for all UI container elements.
Instances are never created directly; they are returned (or yielded) by the section-opening methods on Features: Features#section, Features#frame, Features#task, Features#progress, Features#margin, Features#temporary, and their typed variants.
Every Element includes Features, so all output and section methods are
available on the element itself.
Section elements collapse
-
#end ⇒ Features
Closes this element and returns the parent element.
-
#error(title, border: :default) {|section| ... } ⇒ Object, Section
included
from Features
Creates a Section with
:errorstyling. -
#fatal(title, border: :default) {|section| ... } ⇒ Object, Section
included
from Features
Creates a Section with
:fatalstyling. -
#frame(title = nil, border: :default, style: nil) {|frame| ... } ⇒ Object, Frame
included
from Features
Creates a Frame element — a bordered box with an optional title.
-
#information(title, border: :default) {|section| ... } ⇒ Object, Section
(also: #info)
included
from Features
Creates a Section with
:informationstyling. -
#margin {|margin| ... } ⇒ Object, Margin
included
from Features
Creates a Margin element that adds horizontal and vertical whitespace.
-
#message(title, border: :default) {|section| ... } ⇒ Object, Section
(also: #msg)
included
from Features
Creates a Section with
:messagestyling. -
#progress(*title, max: nil, **popts) {|progress| ... } ⇒ Object, Progress
included
from Features
Creates a Progress element for tracking incremental work.
-
#section(title = nil, type: :default, border: :default) {|section| ... } ⇒ Object, Section
(also: #begin)
included
from Features
Creates a Section element — a bordered container with an optional title.
-
#task(title, pin: false) {|task| ... } ⇒ Object, Task
included
from Features
Creates a Task element — a labelled step that shows a spinner while running and a check mark on success.
-
#temporary {|temp| ... } ⇒ Object, Temporary
included
from Features
Creates a Temporary element whose output is erased when it closes.
-
#warning(title, border: :default) {|section| ... } ⇒ Object, Section
(also: #warn)
included
from Features
Creates a Section with
:warningstyling.
User Interaction collapse
-
#await {|temp| ... } ⇒ nil
included
from Features
Waits for the user to press any key.
-
#choice(*items, abortable: false, selected: nil, **pairs) {|temp| ... } ⇒ Object
included
from Features
Presents a list of options and returns the one the user selects.
-
#query(**options) {|temp| ... } ⇒ Object
included
from Features
Waits for a key event and returns information about it.
-
#select(*items, abortable: false, selected: nil, **pairs) {|temp| ... } ⇒ Array
included
from Features
Presents a list of options and returns all items the user selects.
Output methods collapse
-
#h1(title) ⇒ Features
included
from Features
Prints a level-1 heading.
-
#h2(title) ⇒ Features
included
from Features
Prints a level-2 heading.
-
#h3(title) ⇒ Features
included
from Features
Prints a level-3 heading.
-
#h4(title) ⇒ Features
included
from Features
Prints a level-4 heading.
-
#h5(title) ⇒ Features
included
from Features
Prints a level-5 heading.
-
#h6(title) ⇒ Features
included
from Features
Prints a level-6 heading.
-
#hbars(values, min: nil, max: nil, normalize: false, width: :auto, style: nil, text: true, text_style: nil) ⇒ Features
included
from Features
Prints a horizontal bar chart.
-
#heading(level, title) ⇒ Features
included
from Features
Prints a heading at the given level.
-
#hr(kind = nil) ⇒ Features
included
from Features
Prints a horizontal rule spanning the available width.
-
#ls(*items, compact: true, glyph: nil) ⇒ Features
included
from Features
Prints a multi-column list.
-
#mark(*text, mark: :default, **popts) ⇒ Features
included
from Features
Prints text with a leading mark symbol.
-
#ok(*text, **popts) ⇒ Features
included
from Features
Prints text with a green check-mark prefix.
-
#pin(*text, mark: :default, **popts) ⇒ Features
included
from Features
Prints text with a mark that persists after a Temporary element closes.
-
#quote(*text) ⇒ Features
included
from Features
Prints text with a left-side quotation border.
-
#space(count = 1) ⇒ Features
included
from Features
Prints one or more blank lines.
-
#table(**options) {|table| ... } ⇒ Features
included
from Features
Renders a Table to the terminal.
-
#vbars(values, min: nil, max: nil, normalize: false, height: 10, bar_width: 3, style: nil) ⇒ Features
included
from Features
Prints a vertical bar chart.
Utilities collapse
-
#run(*cmd, env = {}, shell: false, input: nil, max_lines: 10, **spawn_options) ⇒ Array(Process::Status, Array<String>, Array<String>)?
included
from Features
Executes a shell command, captures its output, and returns it.
-
#sh(*cmd, env = {}, shell: false, input: nil, **spawn_options) ⇒ Object
included
from Features
Executes a shell command and prints its output to the terminal.
Instance Method Details
#await {|temp| ... } ⇒ nil Originally defined in module Features
Waits for the user to press any key.
#choice(*items, abortable: false, selected: nil) ⇒ Object #choice(abortable: false, selected: nil, **pairs) ⇒ Object Originally defined in module Features
Presents a list of options and returns the one the user selects.
In ANSI mode the user navigates with arrow keys and confirms with Enter. In dumb mode items are numbered and the user types the item number.
#end ⇒ Features
Closes this element and returns the parent element.
Calling end on an already-closed element is a no-op. All output
methods on this element become no-ops after end is called.
43 |
# File 'lib/natty-ui/element.rb', line 43 def end = NattyUI.__send__(:_end, self) |
#error(title, border: :default) {|section| ... } ⇒ Object, Section Originally defined in module Features
Creates a Section with :error styling.
#fatal(title, border: :default) {|section| ... } ⇒ Object, Section Originally defined in module Features
Creates a Section with :fatal styling.
#frame(title = nil, border: :default, style: nil) {|frame| ... } ⇒ Object, Frame Originally defined in module Features
Creates a NattyUI::Frame element — a bordered box with an optional title.
#hbars(values, min: nil, max: nil, normalize: false, width: :auto, style: nil, text: true, text_style: nil) ⇒ Features Originally defined in module Features
Prints a horizontal bar chart.
All values must be non-negative.
#hr(kind = nil) ⇒ Features Originally defined in module Features
Prints a horizontal rule spanning the available width.
#information(title, border: :default) {|section| ... } ⇒ Object, Section Also known as: info Originally defined in module Features
Creates a Section with :information styling.
#ls(*items, compact: true, glyph: nil) ⇒ Features Originally defined in module Features
Prints a multi-column list.
Items are arranged in columns to fit the terminal width.
#margin(value) ⇒ Object, Margin #margin(vertical = 0, horizontal = 1) ⇒ Object, Margin #margin(top, horizontal, bottom) ⇒ Object, Margin #margin(top, right, bottom, left) ⇒ Object, Margin #margin(top: 0, right: 0, bottom: 0, left: 0) ⇒ Object, Margin Originally defined in module Features
Creates a Margin element that adds horizontal and vertical whitespace.
#mark(*text, mark: :default, **popts) ⇒ Features Originally defined in module Features
Prints text with a leading mark symbol.
#message(title, border: :default) {|section| ... } ⇒ Object, Section Also known as: msg Originally defined in module Features
Creates a Section with :message styling.
#ok(*text, **popts) ⇒ Features Originally defined in module Features
Prints text with a green check-mark prefix.
Shorthand for mark(*text, mark: :checkmark, **options).
#progress(*title, max: nil, **popts) {|progress| ... } ⇒ Object, Progress Originally defined in module Features
Creates a Progress element for tracking incremental work.
When max is given the progress is displayed as a percentage bar.
When max is nil an open-ended dot animation is shown instead.
#query(**options) {|temp| ... } ⇒ Object Originally defined in module Features
Waits for a key event and returns information about it.
Key names are strings such as "a", "Enter", "Esc", "Back",
"Shift+Alt+F1".
#quote(*text) ⇒ Features Originally defined in module Features
Prints text with a left-side quotation border.
#run(*cmd, env = {}, shell: false, input: nil, max_lines: 10, **spawn_options) ⇒ Array(Process::Status, Array<String>, Array<String>)? Originally defined in module Features
Executes a shell command, captures its output, and returns it.
Stdout and stderr lines are displayed in a scrolling region limited to
max_lines. All other arguments are identical to #sh.
#section(title = nil, type: :default, border: :default) {|section| ... } ⇒ Object, Section Also known as: begin Originally defined in module Features
Creates a Section element — a bordered container with an optional title.
#select(*items, abortable: false, selected: nil) ⇒ Array #select(abortable: false, selected: nil, **pairs) ⇒ Array Originally defined in module Features
Presents a list of options and returns all items the user selects.
In ANSI mode the user toggles items with Space and confirms with Enter. In dumb mode items are numbered and the user types item numbers.
#sh(*cmd, env = {}, shell: false, input: nil, **spawn_options) ⇒ Object Originally defined in module Features
Executes a shell command and prints its output to the terminal.
All arguments and options are forwarded to Terminal.sh, which in turn
uses Process.spawn.
#task(title, pin: false) {|task| ... } ⇒ Object, Task Originally defined in module Features
Creates a Task element — a labelled step that shows a spinner while running and a check mark on success.
#temporary {|temp| ... } ⇒ Object, Temporary Originally defined in module Features
Creates a Temporary element whose output is erased when it closes.