todo-jsonl 0.1.22 → 0.1.30
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 +63 -68
- 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: e18e67f8684606fee2693456e247af3edd78926e4d022a12f96c3b255dab3e1c
|
4
|
+
data.tar.gz: 93c21f98eece4e5fce236c5f485073a3d9b052be489cc30dca25a59bab2413e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6addcea04123ade9a05649cf9d6b9ac569a23f6210b103fc715076cadd6775c0ca738cb6a3b3733f28270d66cb1e4d7bbe21a92b20c51b4a2e032b40b7942fed
|
7
|
+
data.tar.gz: 8131e3ccc7e5e28168b16582bb989474b79257284a0effc9d072acfe18844de6684873e295fc99da89535ddefb8a5ab1fcf85ce3e4d968828cff6973224d1151
|
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,43 +269,37 @@ 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? ? [
|
302
|
+
patterns = patterns.nil? || patterns.empty? ? [':active'] : patterns
|
303
303
|
items = filter_tasks(tasks, patterns)
|
304
304
|
items = items.sort_by do |num, task|
|
305
305
|
[task[:priority] && task[:state] != 'done' ? 0 : 1, ORDER[task[:state] || 'default'], task[:due] || 'n/a', num]
|
@@ -330,24 +330,20 @@ class Todo
|
|
330
330
|
end
|
331
331
|
|
332
332
|
def add_note(item, text)
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
write_tasks(tasks)
|
338
|
-
show(item)
|
333
|
+
update_task(item, :show, lambda do |task|
|
334
|
+
task[:note] ||= []
|
335
|
+
task[:note].push(text)
|
336
|
+
end)
|
339
337
|
end
|
340
338
|
|
341
339
|
def delete_note(item)
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
write_tasks(tasks)
|
346
|
-
show(item)
|
340
|
+
update_task(item, :show, lambda do |task|
|
341
|
+
task.delete(:note)
|
342
|
+
end)
|
347
343
|
end
|
348
344
|
|
349
|
-
def show(item)
|
350
|
-
tasks = load_tasks(item)
|
345
|
+
def show(item, tasks = nil)
|
346
|
+
tasks = tasks || load_tasks(item)
|
351
347
|
tasks[item].each do |key, value|
|
352
348
|
val = value.kind_of?(Array) ? "\n" + value.join("\n") : value
|
353
349
|
puts "#{colorize(key.to_s.rjust(10, ' ') + ':', :cyan)} #{val}"
|
@@ -363,26 +359,25 @@ class Todo
|
|
363
359
|
execute(command == 'repl' ? [] : command.split(/\s+/))
|
364
360
|
end
|
365
361
|
print "\ntodo> "
|
366
|
-
command = STDIN.gets.chomp
|
362
|
+
command = STDIN.gets.chomp.strip
|
367
363
|
end
|
368
364
|
end
|
369
365
|
|
370
366
|
def cleanup(patterns)
|
371
367
|
tasks = load_tasks
|
372
|
-
patterns = [
|
368
|
+
patterns = [':done'] + patterns.to_a
|
373
369
|
items = filter_tasks(tasks, patterns)
|
374
370
|
items.keys.each do |num| tasks.delete(num) end
|
375
371
|
write_tasks(tasks)
|
376
|
-
puts "
|
372
|
+
puts "Deleted #{items.size} todo(s)"
|
377
373
|
end
|
378
374
|
|
379
375
|
def filter_tasks(tasks, patterns)
|
380
376
|
items = {}
|
381
377
|
tasks.each do |num, task|
|
382
|
-
normalized_task = "state=#{task[:state]} due=#{task[:due]} #{task[:title]}"
|
383
378
|
match = true
|
384
379
|
patterns.each do |pattern|
|
385
|
-
match = false unless
|
380
|
+
match = false unless @queries[pattern] ? @queries[pattern].call(task) : /#{pattern}/ix.match(task[:title])
|
386
381
|
end
|
387
382
|
items[num] = task if match
|
388
383
|
end
|
@@ -393,7 +388,7 @@ class Todo
|
|
393
388
|
"\e[#{COLOR_CODES[color]}m#{text}\e[0m"
|
394
389
|
end
|
395
390
|
|
396
|
-
def convert_due_date(date
|
391
|
+
def convert_due_date(date)
|
397
392
|
due = nil
|
398
393
|
day_index = @due_date_days.index(date.to_s.downcase) ||
|
399
394
|
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.30
|
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-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|