Skip to content

Commit

Permalink
Hide priority flag on completed tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbata committed Mar 16, 2021
1 parent 1fe7e70 commit 9603dd9
Show file tree
Hide file tree
Showing 8 changed files with 736 additions and 761 deletions.
10 changes: 4 additions & 6 deletions bin/todo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,16 @@ def list(tasks = nil, patterns = nil)
tasks = tasks || load_tasks
task_indent = [tasks.keys.max.to_s.size, 4].max
patterns = patterns.nil? || patterns.empty? ? [':active'] : patterns
items = filter_tasks(tasks, patterns)
items = items.sort_by do |num, task|
items = filter_tasks(tasks, patterns).sort_by do |num, task|
[task[:priority] && task[:state] != 'done' ? 0 : 1, ORDER[task[:state] || 'default'], task[:due] || 'n/a', num]
end
items.each do |num, task|
state = task[:state] || 'default'
color = COLORS[state]
display_state = colorize(STATES[state], color)
display_state = colorize(STATES[state], COLORS[state])
title = task[:title].gsub(CONTEXT_TAG_PATTERN) do |tag|
(tag.start_with?(' ') ? ' ' : '') + colorize(tag.strip, :cyan)
end
priority_flag = task[:priority] ? colorize(PRIORITY_FLAG, :red) : ' '
priority_flag = task[:priority] && state != 'done' ? colorize(PRIORITY_FLAG, :red) : ' '
due_date = ''
if task[:due] && state != 'done'
date_diff = (Date.strptime(task[:due], DATE_FORMAT) - @today).to_i
Expand Down Expand Up @@ -385,7 +383,7 @@ def filter_tasks(tasks, patterns)
end

def colorize(text, color)
"\e[#{COLOR_CODES[color]}m#{text}\e[0m"
"\e[#{COLOR_CODES[color] || 37}m#{text}\e[0m"
end

def convert_due_date(date)
Expand Down
6 changes: 2 additions & 4 deletions node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "todo-jsonl",
"version": "0.1.30",
"version": "0.1.31",
"description": "todo list manager inspired by todo.txt using the jsonl format",
"main": "todo.js",
"bin": {
Expand All @@ -26,9 +26,7 @@
"todotxt",
"todoapp",
"jsonlines",
"jsonl",
"ruby",
"opal"
"jsonl"
],
"author": "Gabor Bata",
"license": "MIT",
Expand Down
870 changes: 435 additions & 435 deletions node/todo.js

Large diffs are not rendered by default.

31 changes: 6 additions & 25 deletions node/todo.js.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,7 @@ def setup
def load_tasks(item_to_check = nil)
count = 0
tasks = {}
todo_jsonl = `function() {
var fs = require('fs');
if (fs.existsSync(#{TODO_FILE})) {
return fs.readFileSync(#{TODO_FILE}, 'utf8');
} else {
return '';
}
}.call()`
todo_jsonl = `require('fs').existsSync(#{TODO_FILE}) ? require('fs').readFileSync(#{TODO_FILE}, 'utf8') : ''`
if !todo_jsonl.empty?
todo_jsonl.split("\n").each do |line|
next if line.strip == ''
Expand Down Expand Up @@ -233,17 +226,7 @@ def add(text)
modified: @today.strftime(DATE_FORMAT)
}
postprocess_tags(task)
`
var fs = require('fs');
var todo_jsonl;
if (fs.existsSync(#{TODO_FILE})) {
todo_jsonl = fs.readFileSync(#{TODO_FILE}, 'utf8');
} else {
todo_jsonl = '';
}
todo_jsonl += #{JSON.generate(task)} + "\n";
fs.writeFileSync(#{TODO_FILE}, todo_jsonl, 'utf8');
`
`require('fs').appendFileSync(#{TODO_FILE}, #{JSON.generate(task) + "\n"}, 'utf8')`
list
end

Expand Down Expand Up @@ -311,18 +294,16 @@ def list(tasks = nil, patterns = nil)
tasks = tasks || load_tasks
task_indent = [tasks.keys.max.to_s.size, 4].max
patterns = patterns.nil? || patterns.empty? ? [':active'] : patterns
items = filter_tasks(tasks, patterns)
items = items.sort_by do |num, task|
items = filter_tasks(tasks, patterns).sort_by do |num, task|
[task[:priority] && task[:state] != 'done' ? 0 : 1, ORDER[task[:state] || 'default'], task[:due] || 'n/a', num]
end
items.each do |num, task|
state = task[:state] || 'default'
color = COLORS[state]
display_state = colorize(STATES[state], color)
display_state = colorize(STATES[state], COLORS[state])
title = task[:title].gsub(CONTEXT_TAG_PATTERN) do |tag|
(tag.start_with?(' ') ? ' ' : '') + colorize(tag.strip, :cyan)
end
priority_flag = task[:priority] ? colorize(PRIORITY_FLAG, :red) : ' '
priority_flag = task[:priority] && state != 'done' ? colorize(PRIORITY_FLAG, :red) : ' '
due_date = ''
if task[:due] && state != 'done'
date_diff = (Date.parse(task[:due]) - @today).to_i
Expand Down Expand Up @@ -417,7 +398,7 @@ def filter_tasks(tasks, patterns)
end

def colorize(text, color)
`'\u001b[' + #{COLOR_CODES[color]} + 'm' + #{text} + '\u001b[0m'`
`'\u001b[' + #{COLOR_CODES[color] || 37} + 'm' + #{text} + '\u001b[0m'`
end

def convert_due_date(date)
Expand Down
4 changes: 2 additions & 2 deletions todo.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'todo-jsonl'
s.version = '0.1.30'
s.date = '2021-03-11'
s.version = '0.1.31'
s.date = '2021-03-16'
s.summary = 'todo list manager inspired by todo.txt using the jsonl format'
s.authors = ['Gabor Bata']
s.homepage = 'https://github.com/gaborbata/todo'
Expand Down
Loading

0 comments on commit 9603dd9

Please sign in to comment.