Class: NattyUI::Wrapper::Element
- Inherits:
-
Object
- Object
- NattyUI::Wrapper::Element
- Includes:
- Features
- Defined in:
- lib/natty-ui/wrapper/element.rb
Overview
Basic visual element.
Direct Known Subclasses
Ask, Heading, HorizontalRule, ListInColumns, Pairs, Progress, Query, Request, Section, Table
Instance Attribute Summary collapse
-
#available_width ⇒ Integer
readonly
Available columns count within the element.
-
#closed? ⇒ Boolean
readonly
Whether its closed or not.
-
#parent ⇒ Section, Wrapper
readonly
Parent element.
-
#status ⇒ Symbol?
readonly
Status when closed.
-
#wrapper ⇒ Wrapper
readonly
Assigned output stream wrapper.
Instance Method Summary collapse
-
#animate(..., animation: :default) ⇒ Wrapper::Section, Wrapper
included
from Features
Print given arguments line-wise with animation.
-
#ask(question, yes: "jotsyd\r\n", no: 'n') ⇒ Boolean?
included
from Features
Ask a yes/no question from user.
-
#close ⇒ Element
Close the element.
-
#completed(title, *args) {|message| ... } ⇒ Object, Wrapper::Message
(also: #done, #ok)
included
from Features
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)
included
from Features
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
included
from Features
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
included
from Features
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
included
from Features
Prints a H1 title.
-
#h2(title, space: 0) ⇒ Wrapper::Section, Wrapper
included
from Features
Prints a H2 title.
-
#h3(title, space: 0) ⇒ Wrapper::Section, Wrapper
included
from Features
Prints a H3 title.
-
#h4(title, space: 0) ⇒ Wrapper::Section, Wrapper
included
from Features
Prints a H4 title.
-
#h5(title, space: 0) ⇒ Wrapper::Section, Wrapper
included
from Features
Prints a H5 title.
-
#hr(symbol = '─') ⇒ Wrapper::Section, Wrapper
included
from Features
Print a horizontal rule.
-
#information(title, *args) {|message| ... } ⇒ Object, Wrapper::Message
(also: #info)
included
from Features
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
included
from Features
Print items of a given list as columns.
-
#message(title, *args, glyph: :default) {|message| ... } ⇒ Object, Wrapper::Message
(also: #msg)
included
from Features
Creates a section with a highlighted
title
and prints given additional arguments as lines into the section. -
#pairs(seperator = ': ', **kwargs) ⇒ Wrapper::Section, Wrapper
included
from Features
Table-like display of key/value pairs.
-
#progress(title, max_value: nil, spinner: :default) ⇒ Wrapper::Progress
included
from Features
Creates progress element implementing additional ProgressAttributes.
-
#query(question, *choices, result: :char, display: :list, **kw_choices) ⇒ Char, ...
included
from Features
Request a choice from user.
-
#quote(*args) {|section| ... } ⇒ Object, Wrapper::Quote
included
from Features
Creates a quotation section and prints given arguments as lines into the section.
-
#request(question, password: false) ⇒ String?
included
from Features
Request user input.
-
#section(*args, prefix: ' ', suffix: ' ') {|section| ... } ⇒ Object, Wrapper::Section
(also: #sec)
included
from Features
Creates a default section and prints given arguments as lines into the section.
-
#table(*table, type: :default, expand: false) {|Table| ... } ⇒ Wrapper::Section, Wrapper
included
from Features
Table view of data.
-
#task(title, *args) {|task| ... } ⇒ Object, Wrapper::Task
included
from Features
Creates task section implementing additional ProgressAttributes.
-
#warning(title, *args) {|message| ... } ⇒ Object, Wrapper::Message
(also: #warn)
included
from Features
Creates a warning message section with a highlighted
title
and prints given additional arguments as lines into the section.
Instance Attribute Details
#available_width ⇒ Integer (readonly)
Returns available columns count within the element.
15 |
# File 'lib/natty-ui/wrapper/element.rb', line 15 def available_width = @parent.available_width |
#closed? ⇒ Boolean (readonly)
Returns whether its closed or not.
19 |
# File 'lib/natty-ui/wrapper/element.rb', line 19 def closed? = (@status != nil) |
#parent ⇒ Section, Wrapper (readonly)
Returns parent element.
22 23 24 |
# File 'lib/natty-ui/wrapper/element.rb', line 22 def parent @parent end |
#status ⇒ Symbol? (readonly)
Returns status when closed.
25 26 27 |
# File 'lib/natty-ui/wrapper/element.rb', line 25 def status @status end |
Instance Method Details
#animate(..., animation: :default) ⇒ Wrapper::Section, Wrapper Originally defined in module Features
Print given arguments line-wise with animation.
#ask(question, yes: "jotsyd\r\n", no: 'n') ⇒ Boolean? Originally defined in module Features
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
#close ⇒ Element
Close the element.
39 |
# File 'lib/natty-ui/wrapper/element.rb', line 39 def close = _close(:closed) |
#completed(title, *args) {|message| ... } ⇒ Object, Wrapper::Message Also known as: done, ok Originally defined in module Features
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
.
#error(title, *args) {|message| ... } ⇒ Object, Wrapper::Message Also known as: err Originally defined in module Features
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 Originally defined in module Features
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
.
#framed(*args, type: :default) {|framed| ... } ⇒ Object, Wrapper::Framed Originally defined in module Features
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.
#h1(title, space: 0) ⇒ Wrapper::Section, Wrapper Originally defined in module Features
Prints a H1 title.
#h2(title, space: 0) ⇒ Wrapper::Section, Wrapper Originally defined in module Features
Prints a H2 title.
#h3(title, space: 0) ⇒ Wrapper::Section, Wrapper Originally defined in module Features
Prints a H3 title.
#h4(title, space: 0) ⇒ Wrapper::Section, Wrapper Originally defined in module Features
Prints a H4 title.
#h5(title, space: 0) ⇒ Wrapper::Section, Wrapper Originally defined in module Features
Prints a H5 title.
#hr(symbol = '─') ⇒ Wrapper::Section, Wrapper Originally defined in module Features
Print a horizontal rule
#information(title, *args) {|message| ... } ⇒ Object, Wrapper::Message Also known as: info Originally defined in module Features
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 Originally defined in module Features
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.
#message(title, *args, glyph: :default) {|message| ... } ⇒ Object, Wrapper::Message Also known as: msg Originally defined in module Features
Creates a section with a highlighted title
and prints given additional
arguments as lines into the section.
#pairs(seperator = ': ', **kwargs) ⇒ Wrapper::Section, Wrapper Originally defined in module Features
Table-like display of key/value pairs.
#progress(title, max_value: nil, spinner: :default) ⇒ Wrapper::Progress Originally defined in module Features
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.
#query(question, *choices, result: :char, display: :list, **kw_choices) ⇒ Char, ... Originally defined in module Features
Request a choice from user.
#quote(*args) {|section| ... } ⇒ Object, Wrapper::Quote Originally defined in module Features
Creates a quotation section and prints given arguments as lines into the section.
#request(question, password: false) ⇒ String? Originally defined in module Features
Request user input.
#section(*args, prefix: ' ', suffix: ' ') {|section| ... } ⇒ Object, Wrapper::Section Also known as: sec Originally defined in module Features
Creates a default section and prints given arguments as lines into the section.
#table(*args, type: :default, expand: false) ⇒ Wrapper::Section, Wrapper #table(type: :default, expand: false) ⇒ Wrapper::Section, Wrapper Originally defined in module Features
Table view of data.
#task(title, *args) {|task| ... } ⇒ Object, Wrapper::Task Originally defined in module Features
Creates task section implementing additional ProgressAttributes.
A task section has additional states and can be closed with #completed or #failed.
#warning(title, *args) {|message| ... } ⇒ Object, Wrapper::Message Also known as: warn Originally defined in module Features
Creates a warning message section with a highlighted title
and
prints given additional arguments as lines into the section.