todo-jsonl 0.1.29 → 1.0.0

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 +34 -45
  3. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2af368dfb4ac9e0f8e6448e005bb7242c509d6bf0ce1e97bdc8783629c3dd77f
4
- data.tar.gz: dc5f0da8574ea5bda98627c122e9a0bdc7c3d661cba879c4ac09bff3cdb075ba
3
+ metadata.gz: 1f9f0379dadc07a6aa67bc1dc0662fcb6df0b4183f55de8abbda1020e8393bfc
4
+ data.tar.gz: c61ac4593f27a6bb737fe2c419fb28b356eed555291c68b33dd17a7a2589ce8b
5
5
  SHA512:
6
- metadata.gz: 1d0b4562ca3af2722f5fb2eb594f248ccaf2b69b18eb2a7f2e19f386da1f60352260631a7afd53e5cf375a3f7c37297a85808a701870b0c2eb73efe9797416e8
7
- data.tar.gz: 030be81b91d66d0d084dff2c805df49cc1f2705aa020d607a06003d542a139e0f6b6708d307a6e448e14c0ca76b135878e643c5ab54132ac457be506cea43b4f
6
+ metadata.gz: ce2c81b1964521382cfef561aa92e7c954a4537664966243132d9d6b8752593bcc8fe4386ff7e565e751856697ca08e1a12a798b26cb2f83856db78adea4e2a2
7
+ data.tar.gz: 6235a7b73886fd6a9a8944287c8c47f012797affac60f492eb7551dd19e4690f06ad7986d63523474cf730d74507ab0caae03de5af6b296ba9613788ed408581
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,
@@ -173,20 +173,19 @@ class Todo
173
173
 
174
174
  def setup
175
175
  @today = Date.today
176
- next_7_days = (0..6).map do |day| @today + day end
177
- @due_date_days = next_7_days.map do |day| day.strftime('%A').downcase end
178
- due_dates_for_queries = next_7_days.map do |day| day.strftime(DATE_FORMAT) end
179
-
176
+ next_7_days = (0..6).map { |day| @today + day }
177
+ @due_date_days = next_7_days.map { |day| day.strftime('%A').downcase }
178
+ due_dates_for_queries = next_7_days.map { |day| day.strftime(DATE_FORMAT) }
180
179
  @queries = {
181
- ':active' => lambda do |task| /(new|started|blocked)/.match(task[:state]) end,
182
- ':done' => lambda do |task| 'done' == task[:state] end,
183
- ':blocked' => lambda do |task| 'blocked' == task[:state] end,
184
- ':started' => lambda do |task| 'started' == task[:state] end,
185
- ':new' => lambda do |task| 'new' == task[:state] end,
186
- ':all' => lambda do |task| /\w+/.match(task[:state]) end,
187
- ':today' => lambda do |task| due_dates_for_queries[0] == task[:due] end,
188
- ':tomorrow' => lambda do |task| due_dates_for_queries[1] == task[:due] end,
189
- ':next7days' => lambda do |task| /(#{due_dates_for_queries.join('|')})/.match(task[:due]) end
180
+ ':active' => lambda { |task| /(new|started|blocked)/.match(task[:state]) },
181
+ ':done' => lambda { |task| 'done' == task[:state] },
182
+ ':blocked' => lambda { |task| 'blocked' == task[:state] },
183
+ ':started' => lambda { |task| 'started' == task[:state] },
184
+ ':new' => lambda { |task| 'new' == task[:state] },
185
+ ':all' => lambda { |task| /\w+/.match(task[:state]) },
186
+ ':today' => lambda { |task| due_dates_for_queries[0] == task[:due] },
187
+ ':tomorrow' => lambda { |task| due_dates_for_queries[1] == task[:due] },
188
+ ':next7days' => lambda { |task| /(#{due_dates_for_queries.join('|')})/.match(task[:due]) }
190
189
  }
191
190
  end
192
191
 
@@ -225,8 +224,8 @@ class Todo
225
224
 
226
225
  def add(text)
227
226
  task = {
228
- state: 'new',
229
- title: text,
227
+ state: 'new',
228
+ title: text,
230
229
  modified: @today.strftime(DATE_FORMAT)
231
230
  }
232
231
  postprocess_tags(task)
@@ -247,7 +246,7 @@ class Todo
247
246
  end
248
247
  end
249
248
 
250
- def append(item, text = '')
249
+ def append(item, text)
251
250
  update_task(item, :list, lambda do |task|
252
251
  task[:title] = [task[:title], text].join(' ')
253
252
  postprocess_tags(task)
@@ -297,21 +296,20 @@ class Todo
297
296
  end
298
297
 
299
298
  def list(tasks = nil, patterns = nil)
300
- tasks = tasks || load_tasks
299
+ tasks ||= load_tasks
301
300
  task_indent = [tasks.keys.max.to_s.size, 4].max
302
- patterns = patterns.nil? || patterns.empty? ? [':active'] : patterns
303
- items = filter_tasks(tasks, patterns)
304
- 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|
305
304
  [task[:priority] && task[:state] != 'done' ? 0 : 1, ORDER[task[:state] || 'default'], task[:due] || 'n/a', num]
306
305
  end
307
306
  items.each do |num, task|
308
307
  state = task[:state] || 'default'
309
- color = COLORS[state]
310
- display_state = colorize(STATES[state], color)
308
+ display_state = colorize(STATES[state], COLORS[state])
311
309
  title = task[:title].gsub(CONTEXT_TAG_PATTERN) do |tag|
312
310
  (tag.start_with?(' ') ? ' ' : '') + colorize(tag.strip, :cyan)
313
311
  end
314
- priority_flag = task[:priority] ? colorize(PRIORITY_FLAG, :red) : ' '
312
+ priority_flag = task[:priority] && state != 'done' ? colorize(PRIORITY_FLAG, :red) : ' '
315
313
  due_date = ''
316
314
  if task[:due] && state != 'done'
317
315
  date_diff = (Date.strptime(task[:due], DATE_FORMAT) - @today).to_i
@@ -343,7 +341,7 @@ class Todo
343
341
  end
344
342
 
345
343
  def show(item, tasks = nil)
346
- tasks = tasks || load_tasks(item)
344
+ tasks ||= load_tasks(item)
347
345
  tasks[item].each do |key, value|
348
346
  val = value.kind_of?(Array) ? "\n" + value.join("\n") : value
349
347
  puts "#{colorize(key.to_s.rjust(10, ' ') + ':', :cyan)} #{val}"
@@ -359,7 +357,7 @@ class Todo
359
357
  execute(command == 'repl' ? [] : command.split(/\s+/))
360
358
  end
361
359
  print "\ntodo> "
362
- command = STDIN.gets.chomp
360
+ command = STDIN.gets.chomp.strip
363
361
  end
364
362
  end
365
363
 
@@ -367,40 +365,31 @@ class Todo
367
365
  tasks = load_tasks
368
366
  patterns = [':done'] + patterns.to_a
369
367
  items = filter_tasks(tasks, patterns)
370
- items.keys.each do |num| tasks.delete(num) end
368
+ items.each_key { |num| tasks.delete(num) }
371
369
  write_tasks(tasks)
372
370
  puts "Deleted #{items.size} todo(s)"
373
371
  end
374
372
 
375
373
  def filter_tasks(tasks, patterns)
376
- items = {}
377
- tasks.each do |num, task|
378
- match = true
379
- patterns.each do |pattern|
380
- match = false unless @queries[pattern] ? @queries[pattern].call(task) : /#{pattern}/ix.match(task[:title])
374
+ patterns = patterns.uniq
375
+ tasks.select do |num, task|
376
+ patterns.all? do |pattern|
377
+ @queries[pattern] ? @queries[pattern].call(task) : /#{pattern}/ix.match(task[:title])
381
378
  end
382
- items[num] = task if match
383
379
  end
384
- return items
385
380
  end
386
381
 
387
382
  def colorize(text, color)
388
- "\e[#{COLOR_CODES[color]}m#{text}\e[0m"
383
+ "\e[#{COLOR_CODES[color] || 37}m#{text}\e[0m"
389
384
  end
390
385
 
391
386
  def convert_due_date(date)
392
- due = nil
393
387
  day_index = @due_date_days.index(date.to_s.downcase) ||
394
388
  DUE_DATE_DAYS_SIMPLE.index(date.to_s.downcase) ||
395
- @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
389
+ @due_date_days.map { |day| day[0..2] }.index(date.to_s.downcase)
390
+ return (@today + day_index).strftime(DATE_FORMAT) if day_index
391
+ date.nil? || date.empty? ? nil : Date.strptime(date, DATE_FORMAT).strftime(DATE_FORMAT)
402
392
  end
403
-
404
393
  end
405
394
 
406
395
  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.29
4
+ version: 1.0.0
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-10 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: []