todo-jsonl 0.1.25 → 0.1.32

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 +44 -43
  3. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d47bb16f60f84f6c3e55951169bdb0871f915b7a6948844897fa8a150df05456
4
- data.tar.gz: '09600be32199c25bc946036ee947290c7c77472d00933fee39c67d9bd2dc0649'
3
+ metadata.gz: 70b3b87cee25e9b7f3b98d8c4fabfa9314953ab473fa845af8d5ac3865416bf3
4
+ data.tar.gz: fc60551fd9ad077cbb794c91dc94595cc8969eaeede825d42bf425b1654113f4
5
5
  SHA512:
6
- metadata.gz: 3ae62a56b667ebcb55e661d1ac64cd4c2b62db7d7d4f106c79a034ca58264d4d7c3ea20a4d262e4386806baa88d472c88dcc5a6946c4d3ca8eb01bbc3d99363e
7
- data.tar.gz: ede2f1f9f155ce5ff5acacdd784b030c01e11f14a4ef6d85e5223663dc3a0dea5a2ab8a3eac95f498808747fa9588723d1feef36828e4657ee23cd41736aa4e0
6
+ metadata.gz: ee42c84380d64142ba3f64a9ea7deee06f874f3a9f6a9ac4142fc834a14b8f66732118ca1072d43bf484674971c37944053deff4fed89e797527b7a83fa1ff25
7
+ data.tar.gz: f79bc0d5be7041e6efcc25f1f88afa43eecf10c382d7353f6b3fa55d6752756b767152b52ab694b5999eda0bbce58ed60ba36b520b09c16309b0ee06f36f82f5
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
  #
@@ -129,6 +130,7 @@ class Todo
129
130
  rescue => error
130
131
  puts "#{colorize('ERROR:', :red)} #{error}"
131
132
  end
133
+ self
132
134
  end
133
135
 
134
136
  private
@@ -177,15 +179,15 @@ class Todo
177
179
  due_dates_for_queries = next_7_days.map do |day| day.strftime(DATE_FORMAT) end
178
180
 
179
181
  @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('|')})"
182
+ ':active' => lambda do |task| /(new|started|blocked)/.match(task[:state]) end,
183
+ ':done' => lambda do |task| 'done' == task[:state] end,
184
+ ':blocked' => lambda do |task| 'blocked' == task[:state] end,
185
+ ':started' => lambda do |task| 'started' == task[:state] end,
186
+ ':new' => lambda do |task| 'new' == task[:state] end,
187
+ ':all' => lambda do |task| /\w+/.match(task[:state]) end,
188
+ ':today' => lambda do |task| due_dates_for_queries[0] == task[:due] end,
189
+ ':tomorrow' => lambda do |task| due_dates_for_queries[1] == task[:due] end,
190
+ ':next7days' => lambda do |task| /(#{due_dates_for_queries.join('|')})/.match(task[:due]) end
189
191
  }
190
192
  end
191
193
 
@@ -240,74 +242,76 @@ class Todo
240
242
  update_function.call(tasks[item])
241
243
  tasks[item][:modified] = @today.strftime(DATE_FORMAT)
242
244
  write_tasks(tasks)
243
- send(post_action, tasks) if post_action
245
+ case post_action
246
+ when :show then show(item, tasks)
247
+ when :list then list(tasks)
248
+ end
244
249
  end
245
250
 
246
- def append(item, text = '')
247
- update_task item, :list, lambda { |task|
251
+ def append(item, text)
252
+ update_task(item, :list, lambda do |task|
248
253
  task[:title] = [task[:title], text].join(' ')
249
254
  postprocess_tags(task)
250
- }
255
+ end)
251
256
  end
252
257
 
253
258
  def rename(item, text)
254
- update_task item, :list, lambda { |task|
259
+ update_task(item, :list, lambda do |task|
255
260
  task[:title] = text
256
261
  postprocess_tags(task)
257
- }
262
+ end)
258
263
  end
259
264
 
260
265
  def delete(item)
261
266
  tasks = load_tasks(item)
262
267
  tasks.delete(item)
263
268
  write_tasks(tasks)
264
- list(tasks)
269
+ list
265
270
  end
266
271
 
267
272
  def change_state(item, state, note = nil)
268
- update_task item, :list, lambda { |task|
273
+ update_task(item, :list, lambda do |task|
269
274
  task[:state] = state
270
275
  if !note.nil? && !note.empty?
271
276
  task[:note] ||= []
272
277
  task[:note].push(note)
273
278
  end
274
- }
279
+ end)
275
280
  end
276
281
 
277
282
  def set_priority(item, note = nil)
278
- update_task item, :list, lambda { |task|
283
+ update_task(item, :list, lambda do |task|
279
284
  task[:priority] = !task[:priority]
280
285
  task.delete(:priority) if !task[:priority]
281
286
  if !note.nil? && !note.empty?
282
287
  task[:note] ||= []
283
288
  task[:note].push(note)
284
289
  end
285
- }
290
+ end)
286
291
  end
287
292
 
288
293
  def due_date(item, date = '')
289
- update_task item, :list, lambda { |task|
294
+ update_task(item, :list, lambda do |task|
290
295
  task[:due] = convert_due_date(date)
291
296
  task.delete(:due) if task[:due].nil?
292
- }
297
+ end)
293
298
  end
294
299
 
295
300
  def list(tasks = nil, patterns = nil)
296
- tasks = tasks || load_tasks
301
+ tasks ||= load_tasks
297
302
  task_indent = [tasks.keys.max.to_s.size, 4].max
298
- patterns = patterns.nil? || patterns.empty? ? [':active'] : patterns
299
- items = filter_tasks(tasks, patterns)
300
- items = items.sort_by do |num, task|
303
+ patterns ||= []
304
+ patterns += [':active'] if (patterns & [':active', ':done', ':blocked', ':started', ':new', ':all']).empty?
305
+ items = filter_tasks(tasks, patterns).sort_by do |num, task|
301
306
  [task[:priority] && task[:state] != 'done' ? 0 : 1, ORDER[task[:state] || 'default'], task[:due] || 'n/a', num]
302
307
  end
303
308
  items.each do |num, task|
304
309
  state = task[:state] || 'default'
305
- color = COLORS[state]
306
- display_state = colorize(STATES[state], color)
310
+ display_state = colorize(STATES[state], COLORS[state])
307
311
  title = task[:title].gsub(CONTEXT_TAG_PATTERN) do |tag|
308
312
  (tag.start_with?(' ') ? ' ' : '') + colorize(tag.strip, :cyan)
309
313
  end
310
- priority_flag = task[:priority] ? colorize(PRIORITY_FLAG, :red) : ' '
314
+ priority_flag = task[:priority] && state != 'done' ? colorize(PRIORITY_FLAG, :red) : ' '
311
315
  due_date = ''
312
316
  if task[:due] && state != 'done'
313
317
  date_diff = (Date.strptime(task[:due], DATE_FORMAT) - @today).to_i
@@ -326,20 +330,20 @@ class Todo
326
330
  end
327
331
 
328
332
  def add_note(item, text)
329
- update_task item, :show, lambda { |task|
333
+ update_task(item, :show, lambda do |task|
330
334
  task[:note] ||= []
331
335
  task[:note].push(text)
332
- }
336
+ end)
333
337
  end
334
338
 
335
339
  def delete_note(item)
336
- update_task item, :show, lambda { |task|
340
+ update_task(item, :show, lambda do |task|
337
341
  task.delete(:note)
338
- }
342
+ end)
339
343
  end
340
344
 
341
345
  def show(item, tasks = nil)
342
- tasks = tasks || load_tasks(item)
346
+ tasks ||= load_tasks(item)
343
347
  tasks[item].each do |key, value|
344
348
  val = value.kind_of?(Array) ? "\n" + value.join("\n") : value
345
349
  puts "#{colorize(key.to_s.rjust(10, ' ') + ':', :cyan)} #{val}"
@@ -355,7 +359,7 @@ class Todo
355
359
  execute(command == 'repl' ? [] : command.split(/\s+/))
356
360
  end
357
361
  print "\ntodo> "
358
- command = STDIN.gets.chomp
362
+ command = STDIN.gets.chomp.strip
359
363
  end
360
364
  end
361
365
 
@@ -363,7 +367,7 @@ class Todo
363
367
  tasks = load_tasks
364
368
  patterns = [':done'] + patterns.to_a
365
369
  items = filter_tasks(tasks, patterns)
366
- items.keys.each do |num| tasks.delete(num) end
370
+ items.each_key do |num| tasks.delete(num) end
367
371
  write_tasks(tasks)
368
372
  puts "Deleted #{items.size} todo(s)"
369
373
  end
@@ -371,10 +375,8 @@ class Todo
371
375
  def filter_tasks(tasks, patterns)
372
376
  items = {}
373
377
  tasks.each do |num, task|
374
- normalized_task = "state=#{task[:state]} due=#{task[:due]} #{task[:title]}"
375
- match = true
376
- patterns.each do |pattern|
377
- match = false unless /#{@queries[pattern] || pattern}/ix.match(normalized_task)
378
+ match = patterns.uniq.all? do |pattern|
379
+ @queries[pattern] ? @queries[pattern].call(task) : /#{pattern}/ix.match(task[:title])
378
380
  end
379
381
  items[num] = task if match
380
382
  end
@@ -382,7 +384,7 @@ class Todo
382
384
  end
383
385
 
384
386
  def colorize(text, color)
385
- "\e[#{COLOR_CODES[color]}m#{text}\e[0m"
387
+ "\e[#{COLOR_CODES[color] || 37}m#{text}\e[0m"
386
388
  end
387
389
 
388
390
  def convert_due_date(date)
@@ -397,7 +399,6 @@ class Todo
397
399
  end
398
400
  return due
399
401
  end
400
-
401
402
  end
402
403
 
403
404
  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.25
4
+ version: 0.1.32
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-08 00:00:00.000000000 Z
11
+ date: 2021-03-17 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: []