todo-jsonl 0.1.24 → 0.1.31
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.
- checksums.yaml +4 -4
- data/bin/todo.rb +66 -73
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ef8eba60ead95705dc2479f4f40fc9e25989b99b25a429de36c6703dca61196
|
4
|
+
data.tar.gz: 9e161dd022343525a4d1e4fd94c214763edc9a57796f3955a510082acda95515
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba7a785128d5f7fddac436e7d2b069f3b96f69fd8f37240e06f8b2382d113391cafaf64b9cb4a48ce0260ef305b292039a40f065c8ff0188509273cad01e79c3
|
7
|
+
data.tar.gz: a7d648320d0ff43680a3f6707094749b8f2f117798aafb6c0a0b94a6e625ee48d4f747b79d531fb00fb7d701094141d6a5c4a814895f240ce9fa51a1acfa6a0a
|
data/bin/todo.rb
CHANGED
@@ -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
|
@@ -155,7 +156,7 @@ class Todo
|
|
155
156
|
* list <regex> [regex...] list tasks (only active tasks by default)
|
156
157
|
* show <tasknumber> show all task details
|
157
158
|
* repl enter read-eval-print loop mode
|
158
|
-
* cleanup <regex> [regex...] cleanup completed tasks by
|
159
|
+
* cleanup <regex> [regex...] cleanup completed tasks by regex
|
159
160
|
* help this help screen
|
160
161
|
|
161
162
|
With list command the following pre-defined regex patterns can be also used:
|
@@ -177,15 +178,15 @@ class Todo
|
|
177
178
|
due_dates_for_queries = next_7_days.map do |day| day.strftime(DATE_FORMAT) end
|
178
179
|
|
179
180
|
@queries = {
|
180
|
-
':active' =>
|
181
|
-
':done' => '
|
182
|
-
':blocked' => '
|
183
|
-
':started' => '
|
184
|
-
':new' => '
|
185
|
-
':all' =>
|
186
|
-
':today' =>
|
187
|
-
':tomorrow' =>
|
188
|
-
':next7days' =>
|
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
|
189
190
|
}
|
190
191
|
end
|
191
192
|
|
@@ -201,9 +202,7 @@ class Todo
|
|
201
202
|
end
|
202
203
|
end
|
203
204
|
end
|
204
|
-
if item_to_check && !tasks.has_key?(item_to_check)
|
205
|
-
raise "#{item_to_check}: No such todo"
|
206
|
-
end
|
205
|
+
raise "#{item_to_check}: No such todo" if item_to_check && !tasks.has_key?(item_to_check)
|
207
206
|
tasks
|
208
207
|
end
|
209
208
|
|
@@ -237,22 +236,29 @@ class Todo
|
|
237
236
|
list
|
238
237
|
end
|
239
238
|
|
240
|
-
def
|
239
|
+
def update_task(item, post_action, update_function)
|
241
240
|
tasks = load_tasks(item)
|
242
|
-
tasks[item]
|
241
|
+
update_function.call(tasks[item])
|
243
242
|
tasks[item][:modified] = @today.strftime(DATE_FORMAT)
|
244
|
-
postprocess_tags(tasks[item])
|
245
243
|
write_tasks(tasks)
|
246
|
-
|
244
|
+
case post_action
|
245
|
+
when :show then show(item, tasks)
|
246
|
+
when :list then list(tasks)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def append(item, text = '')
|
251
|
+
update_task(item, :list, lambda do |task|
|
252
|
+
task[:title] = [task[:title], text].join(' ')
|
253
|
+
postprocess_tags(task)
|
254
|
+
end)
|
247
255
|
end
|
248
256
|
|
249
257
|
def rename(item, text)
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
write_tasks(tasks)
|
255
|
-
list(tasks)
|
258
|
+
update_task(item, :list, lambda do |task|
|
259
|
+
task[:title] = text
|
260
|
+
postprocess_tags(task)
|
261
|
+
end)
|
256
262
|
end
|
257
263
|
|
258
264
|
def delete(item)
|
@@ -263,55 +269,47 @@ class Todo
|
|
263
269
|
end
|
264
270
|
|
265
271
|
def change_state(item, state, note = nil)
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
end
|
273
|
-
write_tasks(tasks)
|
274
|
-
list(tasks)
|
272
|
+
update_task(item, :list, lambda do |task|
|
273
|
+
task[:state] = state
|
274
|
+
if !note.nil? && !note.empty?
|
275
|
+
task[:note] ||= []
|
276
|
+
task[:note].push(note)
|
277
|
+
end
|
278
|
+
end)
|
275
279
|
end
|
276
280
|
|
277
281
|
def set_priority(item, note = nil)
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
end
|
286
|
-
write_tasks(tasks)
|
287
|
-
list(tasks)
|
282
|
+
update_task(item, :list, lambda do |task|
|
283
|
+
task[:priority] = !task[:priority]
|
284
|
+
task.delete(:priority) if !task[:priority]
|
285
|
+
if !note.nil? && !note.empty?
|
286
|
+
task[:note] ||= []
|
287
|
+
task[:note].push(note)
|
288
|
+
end
|
289
|
+
end)
|
288
290
|
end
|
289
291
|
|
290
292
|
def due_date(item, date = '')
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
write_tasks(tasks)
|
296
|
-
list(tasks)
|
293
|
+
update_task(item, :list, lambda do |task|
|
294
|
+
task[:due] = convert_due_date(date)
|
295
|
+
task.delete(:due) if task[:due].nil?
|
296
|
+
end)
|
297
297
|
end
|
298
298
|
|
299
299
|
def list(tasks = nil, patterns = nil)
|
300
300
|
tasks = tasks || load_tasks
|
301
301
|
task_indent = [tasks.keys.max.to_s.size, 4].max
|
302
|
-
patterns = patterns.nil? || patterns.empty? ? [
|
303
|
-
items = filter_tasks(tasks, patterns)
|
304
|
-
items = items.sort_by do |num, task|
|
302
|
+
patterns = patterns.nil? || patterns.empty? ? [':active'] : patterns
|
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
|
-
|
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
|
@@ -330,24 +328,20 @@ class Todo
|
|
330
328
|
end
|
331
329
|
|
332
330
|
def add_note(item, text)
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
write_tasks(tasks)
|
338
|
-
show(item)
|
331
|
+
update_task(item, :show, lambda do |task|
|
332
|
+
task[:note] ||= []
|
333
|
+
task[:note].push(text)
|
334
|
+
end)
|
339
335
|
end
|
340
336
|
|
341
337
|
def delete_note(item)
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
write_tasks(tasks)
|
346
|
-
show(item)
|
338
|
+
update_task(item, :show, lambda do |task|
|
339
|
+
task.delete(:note)
|
340
|
+
end)
|
347
341
|
end
|
348
342
|
|
349
|
-
def show(item)
|
350
|
-
tasks = load_tasks(item)
|
343
|
+
def show(item, tasks = nil)
|
344
|
+
tasks = tasks || load_tasks(item)
|
351
345
|
tasks[item].each do |key, value|
|
352
346
|
val = value.kind_of?(Array) ? "\n" + value.join("\n") : value
|
353
347
|
puts "#{colorize(key.to_s.rjust(10, ' ') + ':', :cyan)} #{val}"
|
@@ -363,13 +357,13 @@ class Todo
|
|
363
357
|
execute(command == 'repl' ? [] : command.split(/\s+/))
|
364
358
|
end
|
365
359
|
print "\ntodo> "
|
366
|
-
command = STDIN.gets.chomp
|
360
|
+
command = STDIN.gets.chomp.strip
|
367
361
|
end
|
368
362
|
end
|
369
363
|
|
370
364
|
def cleanup(patterns)
|
371
365
|
tasks = load_tasks
|
372
|
-
patterns = [
|
366
|
+
patterns = [':done'] + patterns.to_a
|
373
367
|
items = filter_tasks(tasks, patterns)
|
374
368
|
items.keys.each do |num| tasks.delete(num) end
|
375
369
|
write_tasks(tasks)
|
@@ -379,10 +373,9 @@ class Todo
|
|
379
373
|
def filter_tasks(tasks, patterns)
|
380
374
|
items = {}
|
381
375
|
tasks.each do |num, task|
|
382
|
-
normalized_task = "state=#{task[:state]} due=#{task[:due]} #{task[:title]}"
|
383
376
|
match = true
|
384
377
|
patterns.each do |pattern|
|
385
|
-
match = false unless
|
378
|
+
match = false unless @queries[pattern] ? @queries[pattern].call(task) : /#{pattern}/ix.match(task[:title])
|
386
379
|
end
|
387
380
|
items[num] = task if match
|
388
381
|
end
|
@@ -390,10 +383,10 @@ class Todo
|
|
390
383
|
end
|
391
384
|
|
392
385
|
def colorize(text, color)
|
393
|
-
"\e[#{COLOR_CODES[color]}m#{text}\e[0m"
|
386
|
+
"\e[#{COLOR_CODES[color] || 37}m#{text}\e[0m"
|
394
387
|
end
|
395
388
|
|
396
|
-
def convert_due_date(date
|
389
|
+
def convert_due_date(date)
|
397
390
|
due = nil
|
398
391
|
day_index = @due_date_days.index(date.to_s.downcase) ||
|
399
392
|
DUE_DATE_DAYS_SIMPLE.index(date.to_s.downcase) ||
|
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.
|
4
|
+
version: 0.1.31
|
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-
|
11
|
+
date: 2021-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|