Sha256: ff1deb19329348f7fadf490b7452f2b16090a89100af0b142ac00a6481085bd7

Contents?: true

Size: 867 Bytes

Versions: 2

Compression:

Stored size: 867 Bytes

Contents

# Monkeypatch `todo-txt-gem` to create ANSI decorated terminal output.
class Todo::Task
  def to_s_highlighted
    # If stdout is not a tty, then return the raw string as the output is
    # probably being piped to a file and the color codes will make a mess.
    return to_s unless STDOUT.tty?

    pastel = Pastel.new
    if done?
      # Completed tasks are rendered with a strikethrough
      pastel.strikethrough(to_s)
    else
      # Open tasks delegate to the custom formatting function
      print_open_task(pastel)
    end
  end

  private

  def print_open_task(pastel)
    [
      pastel.red(print_priority),
      pastel.yellow(created_on.to_s),
      text,
      pastel.bold.magenta(print_contexts),
      pastel.bold.blue(print_projects),
      pastel.bold.cyan(print_tags)
    ].reject { |item| !item || item.nil? || item.empty? }.join(' ')
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
intent-0.6.0 lib/gem_ext/todo-txt.rb
intent-0.5.5 lib/gem_ext/todo-txt.rb