tot 0.0.2.1 → 0.0.2.2
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 +8 -8
- data/README.md +1 -1
- data/lib/tot/version.rb +1 -1
- data/lib/tot.rb +137 -45
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTg5NmIxMDU2ZGExYTkwNzUyMzU0MWI3OGY1Zjc3MWM1N2RkNGI5ZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzBhYzdmNjE5NjIxMGNhZDVkN2ZkOWM4MTg1ODAyZWIxZjdhN2NkOA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NWIzZWRkNWI1NTM4MDQ1Njk3ZDVjZmRmZjQ4NjVlYzRhMGQ4NDQwMGQ3NjMw
|
10
|
+
YmZjMDgzZmFkOTU0ZDhjYTQ4YWNiMWRiNjRmOTFiMzE1MjQxY2JmOTlmOWMw
|
11
|
+
OWVjZTE5MDIwY2E5YjAzYzA1MTFlYjMzMTRhYWYxNTc1OWY0YTg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDEzMzZkYTM4ZWFiN2FlNjcwNjQzOGE0MTc5OTQ2OWQ2YTg1YTE4OGViYTZh
|
14
|
+
YjgwNjhlM2VkZTAxOGYyZDJlZTMxMDU1MWZjM2IyNDc3MmJkMDg0NmQ3YjQ4
|
15
|
+
ZDg5N2NhMzljZGNiNTdiNmIxY2UyNDFhZTU5NGFiYTY4YTA0MzI=
|
data/README.md
CHANGED
data/lib/tot/version.rb
CHANGED
data/lib/tot.rb
CHANGED
@@ -6,6 +6,8 @@ require "fileutils"
|
|
6
6
|
require "yaml"
|
7
7
|
require "time"
|
8
8
|
require "term/ansicolor"
|
9
|
+
require "tempfile"
|
10
|
+
require 'shellwords'
|
9
11
|
|
10
12
|
module Tot
|
11
13
|
module Config #{{{
|
@@ -50,10 +52,6 @@ module Tot
|
|
50
52
|
@tasks.push new_todo
|
51
53
|
end
|
52
54
|
|
53
|
-
def delete(at)
|
54
|
-
@tasks.delete_at(at)
|
55
|
-
end
|
56
|
-
|
57
55
|
def each
|
58
56
|
@tasks = load_file
|
59
57
|
@tasks.each do |todo|
|
@@ -66,6 +64,11 @@ module Tot
|
|
66
64
|
@tasks.delete_at at
|
67
65
|
end
|
68
66
|
|
67
|
+
def delete_by_title(title)
|
68
|
+
@tasks.delete_at(@tasks.find_index{|obj| obj['title'] == title})
|
69
|
+
@tasks
|
70
|
+
end
|
71
|
+
|
69
72
|
def find_all!(&block)
|
70
73
|
@tasks = self.find_all(&block)
|
71
74
|
end
|
@@ -78,19 +81,39 @@ module Tot
|
|
78
81
|
when 0..1
|
79
82
|
print Term::ANSIColor.bold, Term::ANSIColor.red
|
80
83
|
when 2..3
|
81
|
-
print Term::ANSIColor.yellow
|
84
|
+
print Term::ANSIColor.bold, Term::ANSIColor.yellow
|
85
|
+
when 4..7
|
86
|
+
print Term::ANSIColor.bold, Term::ANSIColor.magenta
|
82
87
|
else
|
83
|
-
print Term::ANSIColor.
|
88
|
+
print Term::ANSIColor.green
|
84
89
|
end
|
85
90
|
|
86
91
|
puts [("<<#{idx}>>" if with_index),
|
87
92
|
todo['date'].strftime("%Y/%m/%d %H:%M"),
|
88
93
|
todo['title'],
|
89
|
-
|
94
|
+
'['+todo['tag'].flatten.join(',')+']'].keep_if{|i| not i.nil?}.join(' | ')
|
90
95
|
print Term::ANSIColor.reset
|
91
96
|
end
|
92
97
|
self
|
93
98
|
end #}}}
|
99
|
+
|
100
|
+
# This method is incomplete, returns array of title for now.
|
101
|
+
def stdin_parser(lines) #{{{
|
102
|
+
lines = lines.split(/\n/) unless lines.class == Array
|
103
|
+
lines.map {|line|
|
104
|
+
line.chomp.gsub(/\e\[\d+m/,"").split('|').map(&:strip)
|
105
|
+
}.keep_if{|i| i != []}
|
106
|
+
.map {|l|
|
107
|
+
task = {}
|
108
|
+
task[:date] = Time.parse(l[0])
|
109
|
+
task[:title] = l[1]
|
110
|
+
task[:tag] = YAML.load(l[2])
|
111
|
+
task
|
112
|
+
}
|
113
|
+
rescue
|
114
|
+
raise RuntimeError, 'Stdin lines are invalid.'
|
115
|
+
end #}}}
|
116
|
+
|
94
117
|
#module_function :load_file, :dump, :listup, :add
|
95
118
|
end #}}}
|
96
119
|
|
@@ -146,13 +169,24 @@ module Tot
|
|
146
169
|
ret
|
147
170
|
end #}}}
|
148
171
|
|
149
|
-
|
172
|
+
def stdin_incoming? #{{{
|
173
|
+
(File.pipe?(STDIN) || File.select([STDIN], [], [], 0) != nil)
|
174
|
+
end #}}}
|
175
|
+
|
176
|
+
module_function :datetime_filter,:stdin_incoming?
|
150
177
|
end #}}}
|
151
178
|
|
152
179
|
class CLI < Thor
|
180
|
+
TTY = open("/dev/tty")
|
153
181
|
def initialize(*args)
|
154
182
|
super
|
155
183
|
@todo_manager = TodoManager.new
|
184
|
+
@stdin_tasks = []
|
185
|
+
# The following lines needs to be fixed when I correct stdin_parser.
|
186
|
+
if Utils.stdin_incoming?
|
187
|
+
@stdin_lines = STDIN.readlines
|
188
|
+
@stdin_tasks = @todo_manager.stdin_parser(@stdin_lines)
|
189
|
+
end
|
156
190
|
end
|
157
191
|
|
158
192
|
desc 'list' , 'list up your todo' #{{{
|
@@ -177,27 +211,46 @@ module Tot
|
|
177
211
|
desc 'add' , 'add a task' #{{{
|
178
212
|
def add
|
179
213
|
new_todo = {}
|
180
|
-
new_todo['title'] = Readline.readline('title> ', true).chomp('\n')
|
181
|
-
|
214
|
+
new_todo['title'] = Readline.readline('title> ', true).chomp('\n').strip
|
215
|
+
begin
|
216
|
+
new_todo['date'] = Time.parse(Utils.datetime_filter(Readline.readline('date> ', true).chomp('\n')).to_s)
|
217
|
+
rescue
|
218
|
+
puts "Invalid input. Please retry."
|
219
|
+
retry
|
220
|
+
end
|
182
221
|
new_todo['tag'] = Readline.readline('tag (separate by space)> ', true)
|
183
222
|
.chomp('\n').split(' ')
|
184
|
-
tmpfile = "/tmp/tot.markdown"
|
185
223
|
# File.open(tmpfile,"w"){|file|
|
186
224
|
# file.puts "\n\n# This line will be ignored."
|
187
225
|
# }
|
188
|
-
|
189
|
-
|
226
|
+
|
227
|
+
#tmpfile = "/tmp/tot.markdown"
|
228
|
+
#system([ENV['EDITOR'],tmpfile].join(' '))
|
229
|
+
Tempfile.open("/tmp/tot_",".markdown") do |t|
|
230
|
+
IO.copy_stream(STDIN, t) unless STDIN.tty?
|
231
|
+
STDIN.reopen(TTY)
|
232
|
+
system([ENV['EDITOR'], t.path, ">", TTY.path].join(" "))
|
233
|
+
new_todo['text'] = t.read
|
234
|
+
end
|
235
|
+
#new_todo['text'] = File.readlines(tmpfile).join
|
190
236
|
print new_todo['text']
|
191
|
-
File.delete tmpfile
|
237
|
+
#File.delete tmpfile
|
192
238
|
@todo_manager.add new_todo
|
193
239
|
@todo_manager.save
|
194
240
|
end #}}}
|
195
241
|
|
196
242
|
desc 'delete', 'delete a task' #{{{
|
197
243
|
def delete
|
198
|
-
@
|
199
|
-
|
200
|
-
|
244
|
+
if @stdin_tasks.empty?
|
245
|
+
@todo_manager.print_color(true)
|
246
|
+
@todo_manager.delete_at Readline.readline('Which Task?> ',false).chomp('\n').to_i
|
247
|
+
@todo_manager.save
|
248
|
+
elsif #@stdin_tasks.size >= 1
|
249
|
+
@stdin_tasks.each do |stdin_task|
|
250
|
+
@todo_manager.delete_by_title(stdin_task[:title])
|
251
|
+
end
|
252
|
+
@todo_manager.save
|
253
|
+
end
|
201
254
|
end #}}}
|
202
255
|
|
203
256
|
desc 'show', <<-EOF #{{{
|
@@ -206,12 +259,25 @@ TITLE does not need to be complete.
|
|
206
259
|
EOF
|
207
260
|
method_option :filter, :type => :array, :aliases => "-f",:default => nil
|
208
261
|
def show
|
262
|
+
|
263
|
+
#### stdinあり
|
264
|
+
if Utils.stdin_incoming?
|
265
|
+
todos = []
|
266
|
+
@stdin_tasks.each do |stdin_task|
|
267
|
+
todos.push @todo_manager.find_all!{|item| stdin_task[:title].match(item['title'])}
|
268
|
+
end
|
269
|
+
todos.flatten.each { |todo| puts '-'*30;print_todo(todo)}
|
270
|
+
return
|
271
|
+
end
|
272
|
+
|
273
|
+
#### stdinなし
|
209
274
|
reg = nil
|
210
275
|
if options['filter']
|
211
276
|
reg = Regexp.new(options['filter'].join('.*'),Regexp::IGNORECASE)
|
212
277
|
else
|
213
278
|
reg = /.*/
|
214
279
|
end
|
280
|
+
|
215
281
|
todo = nil
|
216
282
|
todos = @todo_manager.find_all!{|item| reg.match(item['title'])}
|
217
283
|
if todos.size == 0
|
@@ -223,17 +289,25 @@ EOF
|
|
223
289
|
else
|
224
290
|
todo = todos.first
|
225
291
|
end
|
226
|
-
|
227
|
-
|
228
|
-
puts
|
229
|
-
print todo['text']
|
230
|
-
|
292
|
+
|
293
|
+
print_todo(todo)
|
231
294
|
end #}}}
|
232
295
|
|
233
296
|
desc 'edit', 'edit a task' #{{{
|
234
297
|
method_options :text => :boolean, :title => :boolean, :date => :boolean, :tag => :boolean
|
235
298
|
method_option :filter, :type => :array, :aliases => "-f",:default => nil
|
236
299
|
def edit
|
300
|
+
#### stdinあり
|
301
|
+
if Utils.stdin_incoming?
|
302
|
+
todos = []
|
303
|
+
@stdin_tasks.each do |stdin_task|
|
304
|
+
todos.push @todo_manager.find_all!{|item| stdin_task[:title] == item['title']}
|
305
|
+
end
|
306
|
+
todos.flatten.each { |todo| edit_todo(todo,options)}
|
307
|
+
return
|
308
|
+
end
|
309
|
+
|
310
|
+
#### stdinなし
|
237
311
|
reg = nil
|
238
312
|
if options['filter']
|
239
313
|
reg = Regexp.new(options['filter'].join('.*'),Regexp::IGNORECASE)
|
@@ -251,32 +325,50 @@ EOF
|
|
251
325
|
else
|
252
326
|
todo = todos.first
|
253
327
|
end
|
328
|
+
|
329
|
+
edit_todo(todo,options)
|
330
|
+
end #}}}
|
254
331
|
|
255
|
-
|
256
|
-
|
257
|
-
todo['title']
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
File.delete tmpfile
|
269
|
-
end
|
332
|
+
no_commands do #{{{
|
333
|
+
def edit_todo(todo,options={})
|
334
|
+
old_title = todo['title']
|
335
|
+
if options['title']
|
336
|
+
todo['title'] = Readline.readline('New Title> ').chomp('\n')
|
337
|
+
elsif options['date']
|
338
|
+
todo['date'] = Time.parse(Utils.datetime_filter(Readline.readline('date> ', true).chomp('\n')).to_s)
|
339
|
+
elsif options['tag']
|
340
|
+
todo['tag'] = Readline.readline("tag (old_value: #{todo['tag'].join(' ')})> ", true)
|
341
|
+
.chomp('\n').split(' ')
|
342
|
+
else
|
343
|
+
#tmpfile = "/tmp/tot_" + Shellwords.shellescape(todo['title']) + ".markdown"
|
344
|
+
tmpfile = "/tmp/tot.markdown"
|
270
345
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
346
|
+
fileio = File.open(tmpfile,'w')
|
347
|
+
fileio.write todo['text']
|
348
|
+
fileio.flush
|
349
|
+
fileio.close
|
350
|
+
STDIN.reopen(TTY)
|
351
|
+
system([ENV['EDITOR'], tmpfile, ">", TTY.path].join(" "))
|
352
|
+
todo['text'] = File.readlines(tmpfile).join
|
353
|
+
puts todo
|
354
|
+
|
355
|
+
File.delete tmpfile
|
356
|
+
end
|
357
|
+
|
358
|
+
@todo_manager.refresh
|
359
|
+
@todo_manager.delete_by_title(old_title)
|
360
|
+
@todo_manager.add todo
|
361
|
+
@todo_manager.save
|
362
|
+
end
|
279
363
|
end #}}}
|
280
364
|
|
365
|
+
no_commands do #{{{
|
366
|
+
def print_todo(todo)
|
367
|
+
puts 'Title: ' + todo['title']
|
368
|
+
puts 'Date: ' + todo['date'].strftime("%Y/%m/%d %H:%M")
|
369
|
+
puts
|
370
|
+
print todo['text']
|
371
|
+
end
|
372
|
+
end #}}}
|
281
373
|
end
|
282
374
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.2.
|
4
|
+
version: 0.0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shohei Fujii
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|