tot 0.0.1.1 → 0.0.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/lib/tot/version.rb +1 -1
- data/lib/tot.rb +52 -17
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTUwOTA3NmQxYmRlMWVmYTkzZmYxNmZlOTg3ZTI2Nzg3NzM0NGEwZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NGUxMDhiNDZkNDY3YjhiODg4ZWEzN2Q2NGM2MzY5NjU5MzMwZTU3OQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjU0NWNlZTJiYTM3MTRmNDQwMjYwYTkzM2NiY2Y1MWI1YmZiNzMwN2FhZTJh
|
10
|
+
MjdkM2VlOWM3MDI1OWQ5MWJjYTI1NzlhYTM3MjE5NzRiMGRmYTEyNWVmMGZl
|
11
|
+
ZDYzNmUwOWVhNjQ3OGM3OTdlMDg5YTNjOWQ1NGY4MDlkNjhkY2Q=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODFlZGU1NmVkYmNjYWI2ZDZiYjIyNGY4MGQ0M2ZhZTNmNmY3OGQ2NGVmOWU4
|
14
|
+
YzE1NTNmNTdmMGJjMjM1OWEzMTNjYzU1NDkxZjI2OGY1M2U3NzU2NzU4NGZm
|
15
|
+
OGZlZGEzOWI2YjM0NzBlN2MxNzQyNjNhZmZmYzVmNDhjODllNTc=
|
data/lib/tot/version.rb
CHANGED
data/lib/tot.rb
CHANGED
@@ -32,7 +32,7 @@ module Tot
|
|
32
32
|
def load_file
|
33
33
|
todo_path = Config.todo_path
|
34
34
|
File.open(todo_path,'w'){|file| YAML.dump([],file)} unless File.exists? todo_path
|
35
|
-
@tasks = YAML.load_file(todo_path)
|
35
|
+
@tasks = YAML.load_file(todo_path).sort_by{|i| i['date']}
|
36
36
|
end
|
37
37
|
|
38
38
|
def dump
|
@@ -41,16 +41,7 @@ module Tot
|
|
41
41
|
File.open(Config.todo_path,'w'){|file| YAML.dump(@tasks, file)}
|
42
42
|
end
|
43
43
|
|
44
|
-
def each
|
45
|
-
@tasks = load_file.sort_by{|i| i['date']}
|
46
|
-
@tasks.each do |todo|
|
47
|
-
yield todo
|
48
|
-
end
|
49
|
-
self
|
50
|
-
end
|
51
|
-
|
52
44
|
def add(new_todo)
|
53
|
-
@tasks = load_file
|
54
45
|
@tasks.push new_todo
|
55
46
|
dump
|
56
47
|
end
|
@@ -61,9 +52,21 @@ module Tot
|
|
61
52
|
dump
|
62
53
|
end
|
63
54
|
|
55
|
+
def each
|
56
|
+
@tasks = load_file
|
57
|
+
@tasks.each do |todo|
|
58
|
+
yield todo
|
59
|
+
end
|
60
|
+
self
|
61
|
+
end
|
62
|
+
|
64
63
|
def delete_at(at)
|
65
64
|
@tasks.delete_at at
|
66
65
|
end
|
66
|
+
|
67
|
+
def find_all!(&block)
|
68
|
+
@tasks = self.find_all(&block)
|
69
|
+
end
|
67
70
|
def print_color(with_index = false) #{{{
|
68
71
|
@tasks.each_with_index do |todo,idx|
|
69
72
|
#https://github.com/flori/term-ansicolor/blob/master/examples/example.rb
|
@@ -153,13 +156,12 @@ module Tot
|
|
153
156
|
desc 'list' , 'list up your todo'
|
154
157
|
method_option :tag, :type => :array
|
155
158
|
def list
|
156
|
-
|
157
|
-
|
159
|
+
if options['tag']
|
160
|
+
@todo_manager.find_all! do |todo|
|
158
161
|
options[:tag].all?{|i| todo['tag'].include? i}
|
159
|
-
else
|
160
|
-
true
|
161
162
|
end
|
162
|
-
end
|
163
|
+
end
|
164
|
+
@todo_manager.print_color(false)
|
163
165
|
end
|
164
166
|
|
165
167
|
desc 'add' , 'add a task'
|
@@ -176,6 +178,7 @@ module Tot
|
|
176
178
|
system([ENV['EDITOR'],tmpfile].join(' '))
|
177
179
|
new_todo['text'] = File.readlines(tmpfile).join
|
178
180
|
print new_todo['text']
|
181
|
+
File.delete tmpfile
|
179
182
|
@todo_manager.add new_todo
|
180
183
|
end
|
181
184
|
|
@@ -208,8 +211,40 @@ EOF
|
|
208
211
|
end
|
209
212
|
|
210
213
|
desc 'edit TITLE', 'edit a task'
|
211
|
-
method_options :text => :boolean, :title => :boolean, :date => :
|
212
|
-
def edit
|
214
|
+
method_options :text => :boolean, :title => :boolean, :date => :boolean, :tag => :boolean
|
215
|
+
def edit(title)
|
216
|
+
reg = Regexp.new(title,Regexp::IGNORECASE)
|
217
|
+
todos = @todo_manager.find_all{|item| reg.match(item['title'])}
|
218
|
+
if todos.size == 0
|
219
|
+
puts 'No matched task.'
|
220
|
+
elsif todos.size > 1
|
221
|
+
puts todos.size.to_s + ' tasks matched.'
|
222
|
+
else
|
223
|
+
todo = todos[0]
|
224
|
+
old_title = todo['title']
|
225
|
+
if options['title']
|
226
|
+
todo['title'] = Readline.readline('New Title> ').chomp('\n')
|
227
|
+
elsif options['date']
|
228
|
+
todo['date'] = Time.parse(Utils.datetime_filter(Readline.readline('date> ', true).chomp('\n')).to_s)
|
229
|
+
elsif options['tag']
|
230
|
+
todo['tag'] = Readline.readline("tag (old_value: #{todo['tag'].join(' ')})> ", true)
|
231
|
+
.chomp('\n').split(' ')
|
232
|
+
else
|
233
|
+
tmpfile = "/tmp/tot.markdown"
|
234
|
+
File.open(tmpfile,'w'){|file| file.write todo['text']}
|
235
|
+
system([ENV['EDITOR'],tmpfile].join(' '))
|
236
|
+
todo['text'] = File.readlines(tmpfile).join
|
237
|
+
File.delete tmpfile
|
238
|
+
end
|
239
|
+
|
240
|
+
puts 'Title: ' + todo['title']
|
241
|
+
puts 'Date: ' + todo['date'].strftime("%Y/%m/%d %H:%M")
|
242
|
+
puts 'Tags: ' + todo['tag'].to_s
|
243
|
+
puts
|
244
|
+
print todo['text']
|
245
|
+
@todo_manager.delete_at(@todo_manager.find_index{|obj| obj['title'] == old_title})
|
246
|
+
@todo_manager.add todo
|
247
|
+
end
|
213
248
|
|
214
249
|
end
|
215
250
|
end
|