Module: NattyUI
- Extended by:
- Features
- Defined in:
- lib/natty-ui.rb,
lib/natty-ui/task.rb,
lib/natty-ui/frame.rb,
lib/natty-ui/margin.rb,
lib/natty-ui/element.rb,
lib/natty-ui/section.rb,
lib/natty-ui/version.rb,
lib/natty-ui/features.rb,
lib/natty-ui/progress.rb,
lib/natty-ui/temporary.rb,
lib/natty-ui/renderer/ls.rb,
lib/natty-ui/utils/utils.rb,
lib/natty-ui/helper/table.rb,
lib/natty-ui/utils/border.rb,
lib/natty-ui/dumb_progress.rb,
lib/natty-ui/renderer/bars.rb,
lib/natty-ui/renderer/mark.rb,
lib/natty-ui/renderer/quote.rb,
lib/natty-ui/renderer/shell.rb,
lib/natty-ui/renderer/choice.rb,
lib/natty-ui/renderer/select.rb,
lib/natty-ui/utils/str_const.rb,
lib/natty-ui/renderer/heading.rb,
lib/natty-ui/renderer/dumb_choice.rb,
lib/natty-ui/renderer/dumb_select.rb,
lib/natty-ui/renderer/shell_runner.rb,
lib/natty-ui/renderer/table_renderer.rb,
lib/natty-ui/renderer/horizontal_rule.rb,
lib/natty-ui/renderer/dumb_shell_runner.rb
Overview
This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, lovely, natty user interface you like to have for your command line applications.
NattyUI ᓚᕠᗢ is the top-level module and default UI element of the gem. It extends Features, so every output, section, and interaction method is available directly on the module or through the Kernel#ui helper.
Defined Under Namespace
Modules: Features Classes: Element, Frame, Margin, Progress, Section, Table, Task, Temporary
Constant Summary collapse
- VERSION =
The version number of the gem.
'1.0.2'
Class Attribute Summary collapse
- .element ⇒ Features readonly
-
.input_mode ⇒ :default, ...
readonly
Supported input mode of the current terminal.
-
.title ⇒ String?
Current terminal title.
User Interaction collapse
-
.await {|temp| ... } ⇒ nil
extended
from Features
Waits for the user to press any key.
-
.choice(*items, abortable: false, selected: nil, **pairs) {|temp| ... } ⇒ Object
extended
from Features
Presents a list of options and returns the one the user selects.
-
.query(**options) {|temp| ... } ⇒ Object
extended
from Features
Waits for a key event and returns information about it.
-
.select(*items, abortable: false, selected: nil, **pairs) {|temp| ... } ⇒ Array
extended
from Features
Presents a list of options and returns all items the user selects.
Section elements collapse
-
.error(title, border: :default) {|section| ... } ⇒ Object, Section
extended
from Features
Creates a Section with
:errorstyling. -
.fatal(title, border: :default) {|section| ... } ⇒ Object, Section
extended
from Features
Creates a Section with
:fatalstyling. -
.frame(title = nil, border: :default, style: nil) {|frame| ... } ⇒ Object, Frame
extended
from Features
Creates a Frame element — a bordered box with an optional title.
-
.information(title, border: :default) {|section| ... } ⇒ Object, Section
(also: #info)
extended
from Features
Creates a Section with
:informationstyling. -
.margin {|margin| ... } ⇒ Object, Margin
extended
from Features
Creates a Margin element that adds horizontal and vertical whitespace.
-
.message(title, border: :default) {|section| ... } ⇒ Object, Section
(also: #msg)
extended
from Features
Creates a Section with
:messagestyling. -
.progress(*title, max: nil, **popts) {|progress| ... } ⇒ Object, Progress
extended
from Features
Creates a Progress element for tracking incremental work.
-
.section(title = nil, type: :default, border: :default) {|section| ... } ⇒ Object, Section
(also: #begin)
extended
from Features
Creates a Section element — a bordered container with an optional title.
-
.task(title, pin: false) {|task| ... } ⇒ Object, Task
extended
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
extended
from Features
Creates a Temporary element whose output is erased when it closes.
-
.warning(title, border: :default) {|section| ... } ⇒ Object, Section
(also: #warn)
extended
from Features
Creates a Section with
:warningstyling.
Output methods collapse
-
.h1(title) ⇒ Features
extended
from Features
Prints a level-1 heading.
-
.h2(title) ⇒ Features
extended
from Features
Prints a level-2 heading.
-
.h3(title) ⇒ Features
extended
from Features
Prints a level-3 heading.
-
.h4(title) ⇒ Features
extended
from Features
Prints a level-4 heading.
-
.h5(title) ⇒ Features
extended
from Features
Prints a level-5 heading.
-
.h6(title) ⇒ Features
extended
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
extended
from Features
Prints a horizontal bar chart.
-
.heading(level, title) ⇒ Features
extended
from Features
Prints a heading at the given level.
-
.hr(kind = nil) ⇒ Features
extended
from Features
Prints a horizontal rule spanning the available width.
-
.ls(*items, compact: true, glyph: nil) ⇒ Features
extended
from Features
Prints a multi-column list.
-
.mark(*text, mark: :default, **popts) ⇒ Features
extended
from Features
Prints text with a leading mark symbol.
-
.ok(*text, **popts) ⇒ Features
extended
from Features
Prints text with a green check-mark prefix.
-
.pin(*text, mark: :default, **popts) ⇒ Features
extended
from Features
Prints text with a mark that persists after a Temporary element closes.
-
.puts(*text, **popts) ⇒ Features
extended
from Features
Formats and prints text to the terminal.
-
.quote(*text) ⇒ Features
extended
from Features
Prints text with a left-side quotation border.
-
.space(count = 1) ⇒ Features
extended
from Features
Prints one or more blank lines.
-
.table(**options) {|table| ... } ⇒ Features
extended
from Features
Renders a Table to the terminal.
-
.vbars(values, min: nil, max: nil, normalize: false, height: 10, bar_width: 3, style: nil) ⇒ Features
extended
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>)?
extended
from Features
Executes a shell command, captures its output, and returns it.
-
#sh(*cmd, env = {}, shell: false, input: nil, **spawn_options) ⇒ Object
extended
from Features
Executes a shell command and prints its output to the terminal.
Class Attribute Details
.input_mode ⇒ :default, ... (readonly)
Supported input mode of the current terminal.
49 50 51 52 53 54 55 56 |
# File 'lib/natty-ui.rb', line 49 def input_mode case Terminal.input_mode when :csi_u, :legacy :default when :dumb :dumb end end |
.title ⇒ String?
Current terminal title.
Returns the title most recently set via title=, or nil when no
title has been set yet. Titles are kept in an internal stack; assigning
nil to title= pops the current entry and restores the previous one.
74 |
# File 'lib/natty-ui.rb', line 74 def title = @title_stack[-1] |
Class 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.
.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.
.puts(*text, **popts) ⇒ Features Originally defined in module Features
Formats and prints text to the terminal.
Text is word-wrapped to fit the available column width. BBCode-like
markup is interpreted by default (e.g. [b]bold[/b], [red]text[/fg]).
.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.