Class: RubyRich::Sidebar

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_rich/sidebar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#heightObject

Returns the value of attribute height.



5
6
7
# File 'lib/ruby_rich/sidebar.rb', line 5

def height
  @height
end

#planObject (readonly)

Returns the value of attribute plan.



6
7
8
# File 'lib/ruby_rich/sidebar.rb', line 6

def plan
  @plan
end

#tasksObject (readonly)

Returns the value of attribute tasks.



6
7
8
# File 'lib/ruby_rich/sidebar.rb', line 6

def tasks
  @tasks
end

#widthObject

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

#blurObject



21
22
23
24
# File 'lib/ruby_rich/sidebar.rb', line 21

def blur
  @focused = false
  self
end

#focusObject



16
17
18
19
# File 'lib/ruby_rich/sidebar.rb', line 16

def focus
  @focused = true
  self
end

#renderObject



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