todo-jsonl 0.1.28 → 0.1.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/todo.rb +28 -37
  3. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2869302296a5a0ab3af889b0a76926cfba6d59552d5e4103524dae1ae3e7fd50
4
- data.tar.gz: f2d7d03e8b62139d3197386c44391caf4a9d4fae545012389272cebdca61c3d9
3
+ metadata.gz: 89f9cb1d9f24fe4077faebac43c8fe85041021f560a9cd812e67acace53441cc
4
+ data.tar.gz: cddf8951cc9afbdea4ee6831f3c86fc5419a4f00582a2b1292007bba15b9cf13
5
5
  SHA512:
6
- metadata.gz: 40c72337ffd6a818adf28ef001cbd3b4f365af92d1fecd9a36ea361522a2125d83500ed76d4633df228c2c87a987083b08541452e7129af914452e7ca6652563
7
- data.tar.gz: 6f42e59df9b34c140f3c6bba11010f0b6a3f7a3c45d1c7b23d5ded213ee2562e62a963b3e889a6886b97ff991e49e78af6efccf898fd951220c1cad8bcb2f66d
6
+ metadata.gz: 9e90bb2be2db37e6bfdcee15f7953112bba1db7804562dd4ab697a033a7d38ec4cd495abb394320263ff2a76fb5ff23c0886eb8ae381959a170828a0d7d83d9f
7
+ data.tar.gz: ab376c488d6a86676ee134154ef62e7c63f801d3002ef1df28ec2aee521f535730739ff4a13847dd0d77ad19bab0b6b36d5ce7732d6b317696e125293fa95d28
data/bin/todo.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # todo.rb - todo list manager inspired by todo.txt using the jsonl format.
3
+ # todo.rb - todo list manager on the command-line
4
+ # inspired by todo.txt using the jsonl format.
4
5
  #
5
6
  # Copyright (c) 2020-2021 Gabor Bata
6
7
  #
@@ -28,7 +29,6 @@ require 'json'
28
29
  require 'date'
29
30
 
30
31
  class Todo
31
-
32
32
  COLOR_CODES = {
33
33
  black: 30,
34
34
  red: 31,
@@ -129,6 +129,7 @@ class Todo
129
129
  rescue => error
130
130
  puts "#{colorize('ERROR:', :red)} #{error}"
131
131
  end
132
+ self
132
133
  end
133
134
 
134
135
  private
@@ -175,17 +176,16 @@ class Todo
175
176
  next_7_days = (0..6).map do |day| @today + day end
176
177
  @due_date_days = next_7_days.map do |day| day.strftime('%A').downcase end
177
178
  due_dates_for_queries = next_7_days.map do |day| day.strftime(DATE_FORMAT) end
178
-
179
179
  @queries = {
180
- ':active' => 'state=(new|started|blocked)',
181
- ':done' => 'state=done',
182
- ':blocked' => 'state=blocked',
183
- ':started' => 'state=started',
184
- ':new' => 'state=new',
185
- ':all' => 'state=\w+',
186
- ':today' => "due=#{due_dates_for_queries[0]}",
187
- ':tomorrow' => "due=#{due_dates_for_queries[1]}",
188
- ':next7days' => "due=(#{due_dates_for_queries.join('|')})"
180
+ ':active' => lambda do |task| /(new|started|blocked)/.match(task[:state]) end,
181
+ ':done' => lambda do |task| 'done' == task[:state] end,
182
+ ':blocked' => lambda do |task| 'blocked' == task[:state] end,
183
+ ':started' => lambda do |task| 'started' == task[:state] end,
184
+ ':new' => lambda do |task| 'new' == task[:state] end,
185
+ ':all' => lambda do |task| /\w+/.match(task[:state]) end,
186
+ ':today' => lambda do |task| due_dates_for_queries[0] == task[:due] end,
187
+ ':tomorrow' => lambda do |task| due_dates_for_queries[1] == task[:due] end,
188
+ ':next7days' => lambda do |task| /(#{due_dates_for_queries.join('|')})/.match(task[:due]) end
189
189
  }
190
190
  end
191
191
 
@@ -246,7 +246,7 @@ class Todo
246
246
  end
247
247
  end
248
248
 
249
- def append(item, text = '')
249
+ def append(item, text)
250
250
  update_task(item, :list, lambda do |task|
251
251
  task[:title] = [task[:title], text].join(' ')
252
252
  postprocess_tags(task)
@@ -296,21 +296,20 @@ class Todo
296
296
  end
297
297
 
298
298
  def list(tasks = nil, patterns = nil)
299
- tasks = tasks || load_tasks
299
+ tasks ||= load_tasks
300
300
  task_indent = [tasks.keys.max.to_s.size, 4].max
301
- patterns = patterns.nil? || patterns.empty? ? [':active'] : patterns
302
- items = filter_tasks(tasks, patterns)
303
- items = items.sort_by do |num, task|
301
+ patterns ||= []
302
+ patterns += [':active'] if (patterns & [':active', ':done', ':blocked', ':started', ':new', ':all']).empty?
303
+ items = filter_tasks(tasks, patterns).sort_by do |num, task|
304
304
  [task[:priority] && task[:state] != 'done' ? 0 : 1, ORDER[task[:state] || 'default'], task[:due] || 'n/a', num]
305
305
  end
306
306
  items.each do |num, task|
307
307
  state = task[:state] || 'default'
308
- color = COLORS[state]
309
- display_state = colorize(STATES[state], color)
308
+ display_state = colorize(STATES[state], COLORS[state])
310
309
  title = task[:title].gsub(CONTEXT_TAG_PATTERN) do |tag|
311
310
  (tag.start_with?(' ') ? ' ' : '') + colorize(tag.strip, :cyan)
312
311
  end
313
- priority_flag = task[:priority] ? colorize(PRIORITY_FLAG, :red) : ' '
312
+ priority_flag = task[:priority] && state != 'done' ? colorize(PRIORITY_FLAG, :red) : ' '
314
313
  due_date = ''
315
314
  if task[:due] && state != 'done'
316
315
  date_diff = (Date.strptime(task[:due], DATE_FORMAT) - @today).to_i
@@ -342,7 +341,7 @@ class Todo
342
341
  end
343
342
 
344
343
  def show(item, tasks = nil)
345
- tasks = tasks || load_tasks(item)
344
+ tasks ||= load_tasks(item)
346
345
  tasks[item].each do |key, value|
347
346
  val = value.kind_of?(Array) ? "\n" + value.join("\n") : value
348
347
  puts "#{colorize(key.to_s.rjust(10, ' ') + ':', :cyan)} #{val}"
@@ -358,7 +357,7 @@ class Todo
358
357
  execute(command == 'repl' ? [] : command.split(/\s+/))
359
358
  end
360
359
  print "\ntodo> "
361
- command = STDIN.gets.chomp
360
+ command = STDIN.gets.chomp.strip
362
361
  end
363
362
  end
364
363
 
@@ -366,7 +365,7 @@ class Todo
366
365
  tasks = load_tasks
367
366
  patterns = [':done'] + patterns.to_a
368
367
  items = filter_tasks(tasks, patterns)
369
- items.keys.each do |num| tasks.delete(num) end
368
+ items.each_key do |num| tasks.delete(num) end
370
369
  write_tasks(tasks)
371
370
  puts "Deleted #{items.size} todo(s)"
372
371
  end
@@ -374,33 +373,25 @@ class Todo
374
373
  def filter_tasks(tasks, patterns)
375
374
  items = {}
376
375
  tasks.each do |num, task|
377
- normalized_task = "state=#{task[:state]} due=#{task[:due]} #{task[:title]}"
378
- match = true
379
- patterns.each do |pattern|
380
- match = false unless /#{@queries[pattern] || pattern}/ix.match(normalized_task)
376
+ match = patterns.uniq.all? do |pattern|
377
+ @queries[pattern] ? @queries[pattern].call(task) : /#{pattern}/ix.match(task[:title])
381
378
  end
382
379
  items[num] = task if match
383
380
  end
384
- return items
381
+ items
385
382
  end
386
383
 
387
384
  def colorize(text, color)
388
- "\e[#{COLOR_CODES[color]}m#{text}\e[0m"
385
+ "\e[#{COLOR_CODES[color] || 37}m#{text}\e[0m"
389
386
  end
390
387
 
391
388
  def convert_due_date(date)
392
- due = nil
393
389
  day_index = @due_date_days.index(date.to_s.downcase) ||
394
390
  DUE_DATE_DAYS_SIMPLE.index(date.to_s.downcase) ||
395
391
  @due_date_days.map do |day| day[0..2] end.index(date.to_s.downcase)
396
- if day_index
397
- due = (@today + day_index).strftime(DATE_FORMAT)
398
- else
399
- due = date.nil? || date.empty? ? nil : Date.strptime(date, DATE_FORMAT).strftime(DATE_FORMAT)
400
- end
401
- return due
392
+ return (@today + day_index).strftime(DATE_FORMAT) if day_index
393
+ date.nil? || date.empty? ? nil : Date.strptime(date, DATE_FORMAT).strftime(DATE_FORMAT)
402
394
  end
403
-
404
395
  end
405
396
 
406
397
  Todo.new.execute(ARGV)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: todo-jsonl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.28
4
+ version: 0.1.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabor Bata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-09 00:00:00.000000000 Z
11
+ date: 2021-03-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -42,5 +42,6 @@ requirements: []
42
42
  rubygems_version: 3.0.3
43
43
  signing_key:
44
44
  specification_version: 4
45
- summary: todo list manager inspired by todo.txt using the jsonl format
45
+ summary: todo list manager on the command-line inspired by todo.txt using the jsonl
46
+ format
46
47
  test_files: []