Class: Tasku::Output::Terminal
- Inherits:
-
Object
- Object
- Tasku::Output::Terminal
- Defined in:
- lib/tasku/output/terminal.rb
Constant Summary collapse
- PRIORITY_STYLES =
{ "none" => { color: :dim, symbol: " " }, "low" => { color: :cyan, symbol: "↓" }, "medium" => { color: :yellow, symbol: "■" }, "high" => { color: :red, symbol: "▲" }, "urgent" => { color: :bright_magenta, symbol: "‼" } }.freeze
- STATUS_STYLES =
{ "backlog" => { color: :dim, symbol: "○" }, "todo" => { color: :blue, symbol: "○" }, "in_progress" => { color: :yellow, symbol: "◉" }, "done" => { color: :green, symbol: "✓" }, "cancelled" => { color: :red, symbol: "✗" }, "archived" => { color: :dim, symbol: "⊘" } }.freeze
- COL_SEP =
" "
Instance Method Summary collapse
-
#initialize ⇒ Terminal
constructor
A new instance of Terminal.
- #render_added(task) ⇒ Object
- #render_deleted(task) ⇒ Object
- #render_list(tasks) ⇒ Object
- #render_show(task) ⇒ Object
- #render_stats(tasks) ⇒ Object
- #render_updated(task) ⇒ Object
Constructor Details
#initialize ⇒ Terminal
Returns a new instance of Terminal.
27 28 29 30 |
# File 'lib/tasku/output/terminal.rb', line 27 def initialize @pastel = Pastel.new @term_width = [terminal_width, 80].min end |
Instance Method Details
#render_added(task) ⇒ Object
81 82 83 |
# File 'lib/tasku/output/terminal.rb', line 81 def render_added(task) puts @pastel.green(" ✓ Task ##{task.id} created") + " — #{@pastel.bold(task.name)}" end |
#render_deleted(task) ⇒ Object
89 90 91 |
# File 'lib/tasku/output/terminal.rb', line 89 def render_deleted(task) puts @pastel.red(" ✗ Task ##{task.id} deleted") + " — #{@pastel.bold(task.name)}" end |
#render_list(tasks) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tasku/output/terminal.rb', line 32 def render_list(tasks) if tasks.empty? puts @pastel.yellow(" No tasks found.") return end rows = tasks.map { |t| build_columns(t) } col_widths = compute_widths(rows) total = col_widths.sum + (COL_SEP.length * (col_widths.length - 1)) puts "" puts @pastel.dim(" #{"─" * total}") rows.each do |cols| line = cols.each_with_index.map { |c, i| c.to_s.ljust(col_widths[i]) }.join(COL_SEP) puts " #{line}" end puts @pastel.dim(" #{"─" * total}") puts @pastel.dim(" #{tasks.length} task(s) found") end |
#render_show(task) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/tasku/output/terminal.rb', line 52 def render_show(task) puts "" puts @pastel.bold(" Task ##{task.id}") puts @pastel.dim(" #{"─" * 60}") fields = [ ["Name", @pastel.bold(task.name)], ["Description", task.description ? @pastel.dim(task.description) : @pastel.dim("—")], ["Project", task.project || @pastel.dim("—")], ["Category", task.category || @pastel.dim("—")], ["Priority", priority_tag(task.priority)], ["Status", status_tag(task.status)], ["Start Day", task.start_day ? task.start_day.to_s : @pastel.dim("—")], ["Due Day", due_cell(task)], ["Code", task.code || @pastel.dim("—")], ["Model", task.model_name || @pastel.dim("—")], ["Tags", task.tag_list.empty? ? @pastel.dim("—") : task.tag_list.join(", ")], ["Est. Hours", task.estimated_hours ? task.estimated_hours.to_s : @pastel.dim("—")], ["Created", task.created_at&.strftime("%Y-%m-%d %H:%M") || @pastel.dim("—")], ["Updated", task.updated_at&.strftime("%Y-%m-%d %H:%M") || @pastel.dim("—")] ] max_label = fields.map { |l, _| l.length }.max fields.each do |label, value| puts " #{@pastel.dim(label.ljust(max_label))} #{value}" end puts "" end |
#render_stats(tasks) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/tasku/output/terminal.rb', line 93 def render_stats(tasks) puts "" puts @pastel.bold(" Task Statistics") puts @pastel.dim(" #{"─" * 60}") total = tasks.length by_status = tasks.group_by(&:status).transform_values(&:length) by_priority = tasks.group_by(&:priority).transform_values(&:length) overdue = tasks.count(&:overdue?) projects = tasks.map(&:project).compact.uniq.length puts " #{@pastel.dim("Total tasks:".ljust(20))} #{total}" puts " #{@pastel.dim("Overdue:".ljust(20))} #{overdue.positive? ? @pastel.red(overdue.to_s) : @pastel.green("0")}" puts " #{@pastel.dim("Projects:".ljust(20))} #{projects}" puts "" puts " #{@pastel.dim("By Status:")}" Tasku::Task::VALID_STATUSES.each do |s| count = by_status[s] || 0 next if count.zero? puts " #{status_tag(s)} #{@pastel.send(STATUS_STYLES.dig(s, :color) || :dim, count.to_s.rjust(3))}" end puts "" puts " #{@pastel.dim("By Priority:")}" Tasku::Task::VALID_PRIORITIES.each do |p| count = by_priority[p] || 0 next if count.zero? puts " #{priority_tag(p)} #{@pastel.send(PRIORITY_STYLES.dig(p, :color) || :dim, count.to_s.rjust(3))}" end puts "" end |
#render_updated(task) ⇒ Object
85 86 87 |
# File 'lib/tasku/output/terminal.rb', line 85 def render_updated(task) puts @pastel.green(" ✓ Task ##{task.id} updated") + " — #{@pastel.bold(task.name)}" end |