Class: RubyRich::Sidebar
- Inherits:
-
Object
- Object
- RubyRich::Sidebar
- Defined in:
- lib/ruby_rich/sidebar.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#plan ⇒ Object
readonly
Returns the value of attribute plan.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #add_task(label, status: :pending) ⇒ Object
- #blur ⇒ Object
- #focus ⇒ Object
-
#initialize(plan: "", tasks: []) ⇒ Sidebar
constructor
A new instance of Sidebar.
- #render ⇒ Object
- #set_tasks(tasks) ⇒ Object
- #update_plan(text) ⇒ Object
Constructor Details
#initialize(plan: "", tasks: []) ⇒ Sidebar
Returns a new instance of Sidebar.
8 9 10 11 12 13 14 |
# File 'lib/ruby_rich/sidebar.rb', line 8 def initialize(plan: "", tasks: []) @plan = plan @tasks = tasks @width = 0 @height = 0 @focused = false end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
5 6 7 |
# File 'lib/ruby_rich/sidebar.rb', line 5 def height @height end |
#plan ⇒ Object (readonly)
Returns the value of attribute plan.
6 7 8 |
# File 'lib/ruby_rich/sidebar.rb', line 6 def plan @plan end |
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
6 7 8 |
# File 'lib/ruby_rich/sidebar.rb', line 6 def tasks @tasks end |
#width ⇒ Object
Returns the value of attribute width.
5 6 7 |
# File 'lib/ruby_rich/sidebar.rb', line 5 def width @width end |
Instance Method Details
#add_task(label, status: :pending) ⇒ Object
36 37 38 39 |
# File 'lib/ruby_rich/sidebar.rb', line 36 def add_task(label, status: :pending) @tasks << { label: label, status: status } self end |
#blur ⇒ Object
21 22 23 24 |
# File 'lib/ruby_rich/sidebar.rb', line 21 def blur @focused = false self end |
#focus ⇒ Object
16 17 18 19 |
# File 'lib/ruby_rich/sidebar.rb', line 16 def focus @focused = true self end |
#render ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/ruby_rich/sidebar.rb', line 41 def render plan_height = [(@height * 0.48).floor, 3].max tasks_height = [@height - plan_height, 3].max [ *panel_lines("Plan", @plan, plan_height), *panel_lines("Tasks", render_tasks, tasks_height) ].first(@height) end |
#set_tasks(tasks) ⇒ Object
31 32 33 34 |
# File 'lib/ruby_rich/sidebar.rb', line 31 def set_tasks(tasks) @tasks = tasks self end |
#update_plan(text) ⇒ Object
26 27 28 29 |
# File 'lib/ruby_rich/sidebar.rb', line 26 def update_plan(text) @plan = text.to_s self end |