Class: Thor::Interactive::TUI::StatusBar
- Inherits:
-
Object
- Object
- Thor::Interactive::TUI::StatusBar
- Defined in:
- lib/thor/interactive/tui/status_bar.rb
Overview
Configurable status bar with left/center/right sections. App authors provide lambdas that receive the Thor instance.
Instance Attribute Summary collapse
-
#center ⇒ Object
Returns the value of attribute center.
-
#left ⇒ Object
Returns the value of attribute left.
-
#right ⇒ Object
Returns the value of attribute right.
Instance Method Summary collapse
-
#initialize(thor_class, thor_instance, options = {}) ⇒ StatusBar
constructor
A new instance of StatusBar.
- #render_text(width, override_center: nil, override_right: nil) ⇒ Object
Constructor Details
#initialize(thor_class, thor_instance, options = {}) ⇒ StatusBar
Returns a new instance of StatusBar.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/thor/interactive/tui/status_bar.rb', line 11 def initialize(thor_class, thor_instance, = {}) @thor_class = thor_class @thor_instance = thor_instance config = [:status_bar] || {} @left = config[:left] || ->(instance) { " #{instance.class.name}" } @center = config[:center] || ->(instance) { "" } @right = config[:right] || ->(instance) { " ready " } end |
Instance Attribute Details
#center ⇒ Object
Returns the value of attribute center.
9 10 11 |
# File 'lib/thor/interactive/tui/status_bar.rb', line 9 def center @center end |
#left ⇒ Object
Returns the value of attribute left.
9 10 11 |
# File 'lib/thor/interactive/tui/status_bar.rb', line 9 def left @left end |
#right ⇒ Object
Returns the value of attribute right.
9 10 11 |
# File 'lib/thor/interactive/tui/status_bar.rb', line 9 def right @right end |
Instance Method Details
#render_text(width, override_center: nil, override_right: nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/thor/interactive/tui/status_bar.rb', line 22 def render_text(width, override_center: nil, override_right: nil) left_text = evaluate_section(@left) center_text = override_center || evaluate_section(@center) right_text = override_right || evaluate_section(@right) # Calculate spacing if center_text.empty? padding = width - left_text.length - right_text.length padding = 1 if padding < 1 left_text + (" " * padding) + right_text else # Three-section layout left_space = width - left_text.length - center_text.length - right_text.length left_pad = [left_space / 2, 1].max right_pad = [left_space - left_pad, 1].max left_text + (" " * left_pad) + center_text + (" " * right_pad) + right_text end end |