Class: Clacky::RichUI::RichTasksPanel

Inherits:
Object
  • Object
show all
Includes:
Components::BaseComponent
Defined in:
lib/clacky/rich_ui/components/sidebar_panels.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Components::BaseComponent

#colored, #muted, #status_marker, #theme, #truncate

Constructor Details

#initializeRichTasksPanel

Returns a new instance of RichTasksPanel.



54
55
56
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 54

def initialize
  @tasks = []
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



52
53
54
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 52

def height
  @height
end

#widthObject

Returns the value of attribute width.



52
53
54
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 52

def width
  @width
end

Instance Method Details

#has_tasks?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 62

def has_tasks?
  !@tasks.empty?
end

#renderObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 66

def render
  return muted("No active tasks") if @tasks.empty?

  lines = []
  done_count = 0
  total = @tasks.length
  @tasks.each do |task|
    label = task_label(task)
    status = task_status(task)
    done_count += 1 if %i[done completed].include?(status)
    lines << "#{status_marker(status)} #{label}"
  end
  lines << "" unless lines.empty?
  lines << muted("#{done_count}/#{total} done")
  lines.join("\n")
end

#set_tasks(tasks) ⇒ Object



58
59
60
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 58

def set_tasks(tasks)
  @tasks = Array(tasks)
end

#task_status(task) ⇒ Object



93
94
95
96
97
98
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 93

def task_status(task)
  case task
  when Hash then (task[:status] || task["status"] || :pending).to_sym
  else :pending
  end
end