Module: NattyUI::Features
- Included in:
- Wrapper, Wrapper::Element
- Defined in:
- lib/natty-ui/wrapper/features.rb,
lib/natty-ui/wrapper/ask.rb,
lib/natty-ui/wrapper/task.rb,
lib/natty-ui/wrapper/query.rb,
lib/natty-ui/wrapper/quote.rb,
lib/natty-ui/wrapper/table.rb,
lib/natty-ui/wrapper/framed.rb,
lib/natty-ui/wrapper/animate.rb,
lib/natty-ui/wrapper/heading.rb,
lib/natty-ui/wrapper/message.rb,
lib/natty-ui/wrapper/request.rb,
lib/natty-ui/wrapper/section.rb,
lib/natty-ui/wrapper/progress.rb,
lib/natty-ui/wrapper/horizontal_rule.rb,
lib/natty-ui/wrapper/list_in_columns.rb
Overview
Features of NattyUI - methods to display natty elements.
Defined Under Namespace
Classes: Table
Instance Method Summary collapse
-
#animate(..., animation: :default) ⇒ Wrapper::Section, Wrapper
Print given arguments line-wise with animation.
-
#ask(question, yes: "jotsyd\r\n", no: 'n') ⇒ Boolean?
Ask a yes/no question from user.
-
#completed(title, *args) {|message| ... } ⇒ Object, Wrapper::Message
(also: #done, #ok)
Creates a completion message section with a highlighted
title
and prints given additional arguments as lines into the section. -
#error(title, *args) {|message| ... } ⇒ Object, Wrapper::Message
(also: #err)
Creates a error message section with a highlighted
title
and prints given additional arguments as lines into the section. -
#failed(title, *args) {|message| ... } ⇒ Object, Wrapper::Message
Creates a failure message section with a highlighted
title
and prints given additional arguments as lines into the section. -
#framed(*args, type: :default) {|framed| ... } ⇒ Object, Wrapper::Framed
Creates frame-enclosed section with a highlighted
title
and prints given additional arguments as lines into the section. -
#h1(title, space: 0) ⇒ Wrapper::Section, Wrapper
Prints a H1 title.
-
#h2(title, space: 0) ⇒ Wrapper::Section, Wrapper
Prints a H2 title.
-
#h3(title, space: 0) ⇒ Wrapper::Section, Wrapper
Prints a H3 title.
-
#h4(title, space: 0) ⇒ Wrapper::Section, Wrapper
Prints a H4 title.
-
#h5(title, space: 0) ⇒ Wrapper::Section, Wrapper
Prints a H5 title.
-
#hr(symbol = '─') ⇒ Wrapper::Section, Wrapper
Print a horizontal rule.
-
#information(title, *args) {|message| ... } ⇒ Object, Wrapper::Message
(also: #info)
Creates a informational message section with a highlighted
title
and prints given additional arguments as lines into the section. -
#ls(*args, compact: true, glyph: nil) ⇒ Wrapper, Wrapper::Element
Print items of a given list as columns.
-
#message(title, *args, glyph: :default) {|message| ... } ⇒ Object, Wrapper::Message
(also: #msg)
Creates a section with a highlighted
title
and prints given additional arguments as lines into the section. -
#pairs(seperator = ': ', **kwargs) ⇒ Wrapper::Section, Wrapper
Table-like display of key/value pairs.
-
#progress(title, max_value: nil, spinner: :default) ⇒ Wrapper::Progress
Creates progress element implementing additional ProgressAttributes.
-
#query(question, *choices, result: :char, display: :list, **kw_choices) ⇒ Char, ...
Request a choice from user.
-
#quote(*args) {|section| ... } ⇒ Object, Wrapper::Quote
Creates a quotation section and prints given arguments as lines into the section.
-
#request(question, password: false) ⇒ String?
Request user input.
-
#section(*args, prefix: ' ', suffix: ' ') {|section| ... } ⇒ Object, Wrapper::Section
(also: #sec)
Creates a default section and prints given arguments as lines into the section.
-
#table(*table, type: :default, expand: false) {|Table| ... } ⇒ Wrapper::Section, Wrapper
Table view of data.
-
#task(title, *args) {|task| ... } ⇒ Object, Wrapper::Task
Creates task section implementing additional ProgressAttributes.
-
#warning(title, *args) {|message| ... } ⇒ Object, Wrapper::Message
(also: #warn)
Creates a warning message section with a highlighted
title
and prints given additional arguments as lines into the section.
Instance Method Details
#animate(..., animation: :default) ⇒ Wrapper::Section, Wrapper
Print given arguments line-wise with animation.
12 13 14 15 |
# File 'lib/natty-ui/wrapper/animate.rb', line 12 def animate(*args, **kwargs) kwargs[:animation] ||= :default puts(*args, **kwargs) end |
#ask(question, yes: "jotsyd\r\n", no: 'n') ⇒ Boolean?
Ask a yes/no question from user.
The defaults for yes
and no
will work for
Afrikaans, Dutch, English, French, German, Italian, Polish, Portuguese,
Romanian, Spanish and Swedish.
The default for yes
includes ENTER
and RETURN
key
32 33 34 |
# File 'lib/natty-ui/wrapper/ask.rb', line 32 def ask(question, yes: "jotsyd\r\n", no: 'n') _element(:Ask, question, yes, no) end |
#completed(title, *args) {|message| ... } ⇒ Object, Wrapper::Message Also known as: done, ok
Creates a completion message section with a highlighted title
and
prints given additional arguments as lines into the section.
When used for a #task section it closes this section with status :ok
.
63 64 65 |
# File 'lib/natty-ui/wrapper/message.rb', line 63 def completed(title, *args, &block) _section(:Message, args, title: title, glyph: :completed, &block) end |
#error(title, *args) {|message| ... } ⇒ Object, Wrapper::Message Also known as: err
Creates a error message section with a highlighted title
and
prints given additional arguments as lines into the section.
50 51 52 |
# File 'lib/natty-ui/wrapper/message.rb', line 50 def error(title, *args, &block) _section(:Message, args, title: title, glyph: :error, &block) end |
#failed(title, *args) {|message| ... } ⇒ Object, Wrapper::Message
Creates a failure message section with a highlighted title
and
prints given additional arguments as lines into the section.
When used for a #task section it closes this section with status
:failed
.
78 79 80 |
# File 'lib/natty-ui/wrapper/message.rb', line 78 def failed(title, *args, &block) _section(:Message, args, title: title, glyph: :failed, &block) end |
#framed(*args, type: :default) {|framed| ... } ⇒ Object, Wrapper::Framed
Creates frame-enclosed section with a highlighted title
and
prints given additional arguments as lines into the section.
When no block is given, the section must be closed, see Wrapper::Element#close.
18 19 20 |
# File 'lib/natty-ui/wrapper/framed.rb', line 18 def framed(*args, type: :default, &block) _section(:Framed, args, type: NattyUI::Frame[type], &block) end |
#h1(title, space: 0) ⇒ Wrapper::Section, Wrapper
Prints a H1 title.
12 |
# File 'lib/natty-ui/wrapper/heading.rb', line 12 def h1(title, space: 0) = _element(:Heading, title, space, '═══════') |
#h2(title, space: 0) ⇒ Wrapper::Section, Wrapper
Prints a H2 title.
18 |
# File 'lib/natty-ui/wrapper/heading.rb', line 18 def h2(title, space: 0) = _element(:Heading, title, space, '━━━━━') |
#h3(title, space: 0) ⇒ Wrapper::Section, Wrapper
Prints a H3 title.
24 |
# File 'lib/natty-ui/wrapper/heading.rb', line 24 def h3(title, space: 0) = _element(:Heading, title, space, '━━━') |
#h4(title, space: 0) ⇒ Wrapper::Section, Wrapper
Prints a H4 title.
30 |
# File 'lib/natty-ui/wrapper/heading.rb', line 30 def h4(title, space: 0) = _element(:Heading, title, space, '───') |
#h5(title, space: 0) ⇒ Wrapper::Section, Wrapper
Prints a H5 title.
36 |
# File 'lib/natty-ui/wrapper/heading.rb', line 36 def h5(title, space: 0) = _element(:Heading, title, space, '──') |
#hr(symbol = '─') ⇒ Wrapper::Section, Wrapper
Print a horizontal rule
11 |
# File 'lib/natty-ui/wrapper/horizontal_rule.rb', line 11 def hr(symbol = '─') = _element(:HorizontalRule, symbol) |
#information(title, *args) {|message| ... } ⇒ Object, Wrapper::Message Also known as: info
Creates a informational message section with a highlighted title
and
prints given additional arguments as lines into the section.
28 29 30 |
# File 'lib/natty-ui/wrapper/message.rb', line 28 def information(title, *args, &block) _section(:Message, args, title: title, glyph: :information, &block) end |
#ls(*args, compact: true, glyph: nil) ⇒ Wrapper, Wrapper::Element
Print items of a given list as columns. In the default compact format columns may have diffrent widths and the list items are ordered column-wise. The non-compact format prints all columns in same width and order the list items row-wise.
43 44 45 |
# File 'lib/natty-ui/wrapper/list_in_columns.rb', line 43 def ls(*args, compact: true, glyph: nil) _element(:ListInColumns, args, compact, glyph) end |
#message(title, *args, glyph: :default) {|message| ... } ⇒ Object, Wrapper::Message Also known as: msg
Creates a section with a highlighted title
and prints given additional
arguments as lines into the section.
16 17 18 |
# File 'lib/natty-ui/wrapper/message.rb', line 16 def (title, *args, glyph: :default, &block) _section(:Message, args, title: title, glyph: glyph, &block) end |
#pairs(seperator = ': ', **kwargs) ⇒ Wrapper::Section, Wrapper
Table-like display of key/value pairs.
80 81 82 |
# File 'lib/natty-ui/wrapper/table.rb', line 80 def pairs(seperator = ': ', **kwargs) kwargs.empty? ? self : _element(:Pairs, kwargs, seperator) end |
#progress(title, max_value: nil, spinner: :default) ⇒ Wrapper::Progress
Creates progress element implementing additional ProgressAttributes.
When a max_value
is given, the progress will by displayed as a bar.
Otherwise the spinner
is used for a little animation.
When no pre-defined spinner is specified then spinner will be used char-wise as a string for the progress animation.
A progress element has additional states and can be closed with #completed or #failed.
23 24 25 |
# File 'lib/natty-ui/wrapper/progress.rb', line 23 def progress(title, max_value: nil, spinner: :default) _element(:Progress, title, max_value, spinner) end |
#query(question, *choices, result: :char, display: :list, **kw_choices) ⇒ Char, ...
Request a choice from user.
38 39 40 |
# File 'lib/natty-ui/wrapper/query.rb', line 38 def query(question, *choices, result: :char, display: :list, **kw_choices) _element(:Query, question, choices, kw_choices, result, display) end |
#quote(*args) {|section| ... } ⇒ Object, Wrapper::Quote
Creates a quotation section and prints given arguments as lines into the section.
14 |
# File 'lib/natty-ui/wrapper/quote.rb', line 14 def quote(*args, &block) = _section(:Quote, args, prefix: '▍ ', &block) |
#request(question, password: false) ⇒ String?
Request user input.
13 14 15 |
# File 'lib/natty-ui/wrapper/request.rb', line 13 def request(question, password: false) _element(:Request, question, password) end |
#section(*args, prefix: ' ', suffix: ' ') {|section| ... } ⇒ Object, Wrapper::Section Also known as: sec
Creates a default section and prints given arguments as lines into the section.
16 17 18 |
# File 'lib/natty-ui/wrapper/section.rb', line 16 def section(*args, prefix: ' ', suffix: ' ', &block) _section(:Section, args, prefix: prefix, suffix: suffix, &block) end |
#table(*args, type: :default, expand: false) ⇒ Wrapper::Section, Wrapper #table(type: :default, expand: false) ⇒ Wrapper::Section, Wrapper
Table view of data.
58 59 60 61 62 63 |
# File 'lib/natty-ui/wrapper/table.rb', line 58 def table(*table, type: :default, expand: false) type = NattyUI::Frame[type] table = Table.create(*table) yield(table) if block_given? _element(:Table, table, type, ) end |
#task(title, *args) {|task| ... } ⇒ Object, Wrapper::Task
Creates task section implementing additional ProgressAttributes.
A task section has additional states and can be closed with #completed or #failed.
17 18 19 |
# File 'lib/natty-ui/wrapper/task.rb', line 17 def task(title, *args, &block) _section(:Task, args, title: title, &block) end |
#warning(title, *args) {|message| ... } ⇒ Object, Wrapper::Message Also known as: warn
Creates a warning message section with a highlighted title
and
prints given additional arguments as lines into the section.
39 40 41 |
# File 'lib/natty-ui/wrapper/message.rb', line 39 def warning(title, *args, &block) _section(:Message, args, title: title, glyph: :warning, &block) end |