Class: Menu
- Inherits:
-
Object
- Object
- Menu
- Defined in:
- lib/terminal-basic-menu.rb
Overview
Basic menu class used to create an instance of a terminal menu
Instance Attribute Summary collapse
-
#block_align ⇒ Object
Returns the value of attribute block_align.
-
#body ⇒ Object
Returns the value of attribute body.
-
#border_color ⇒ Object
Returns the value of attribute border_color.
-
#footer ⇒ Object
Returns the value of attribute footer.
-
#header ⇒ Object
Returns the value of attribute header.
-
#width ⇒ Object
Returns the value of attribute width.
-
#word_wrap ⇒ Object
writeonly
Sets the attribute word_wrap.
Instance Method Summary collapse
- #display_body ⇒ Object
- #display_footer ⇒ Object
- #display_header ⇒ Object
- #display_menu ⇒ Object
-
#initialize(output: $stdout, width: 50, header: nil, body: nil, footer: nil, border_color: 0) ⇒ Menu
constructor
A new instance of Menu.
Constructor Details
#initialize(output: $stdout, width: 50, header: nil, body: nil, footer: nil, border_color: 0) ⇒ Menu
Returns a new instance of Menu.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/terminal-basic-menu.rb', line 6 def initialize(output: $stdout, width: 50, header: nil, body: nil, footer: nil, border_color: 0) @output = output @width = width - 4 # adjust to allow '| ' and ' |' on each side @header = header @body = body = @border_color = border_color @word_wrap = true @block_align = true end |
Instance Attribute Details
#block_align ⇒ Object
Returns the value of attribute block_align.
5 6 7 |
# File 'lib/terminal-basic-menu.rb', line 5 def block_align @block_align end |
#body ⇒ Object
Returns the value of attribute body.
5 6 7 |
# File 'lib/terminal-basic-menu.rb', line 5 def body @body end |
#border_color ⇒ Object
Returns the value of attribute border_color.
5 6 7 |
# File 'lib/terminal-basic-menu.rb', line 5 def border_color @border_color end |
#footer ⇒ Object
Returns the value of attribute footer.
5 6 7 |
# File 'lib/terminal-basic-menu.rb', line 5 def end |
#header ⇒ Object
Returns the value of attribute header.
5 6 7 |
# File 'lib/terminal-basic-menu.rb', line 5 def header @header end |
#width ⇒ Object
Returns the value of attribute width.
5 6 7 |
# File 'lib/terminal-basic-menu.rb', line 5 def width @width end |
#word_wrap=(value) ⇒ Object
Sets the attribute word_wrap
5 6 7 |
# File 'lib/terminal-basic-menu.rb', line 5 def word_wrap=(value) @word_wrap = value end |
Instance Method Details
#display_body ⇒ Object
41 42 43 44 |
# File 'lib/terminal-basic-menu.rb', line 41 def display_body print_text(@body[:text], @body[:align], @body[:color]) print_choices(@body[:choices], @body[:choice_align], @body[:color]) end |
#display_footer ⇒ Object
46 47 48 |
# File 'lib/terminal-basic-menu.rb', line 46 def print_text([:text], [:align], [:color]) end |
#display_header ⇒ Object
37 38 39 |
# File 'lib/terminal-basic-menu.rb', line 37 def display_header print_text(@header[:text], @header[:align], @header[:color]) end |
#display_menu ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/terminal-basic-menu.rb', line 17 def # Return if nothing to display return unless @header || @body || # Change left to ljust etc. align_to_method! print_line_break if @header display_header print_line_break end if @body display_body print_line_break end if print_line_break end end |