todo-curses 0.0.4 → 0.0.5
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/Gemfile.lock +3 -1
- data/README.md +8 -48
- data/Rakefile +2 -13
- data/lib/TodoCurses/version.rb +1 -1
- data/lib/TodoCurses/view.rb +2 -2
- data/lib/TodoCurses.rb +2 -4
- data/todo-curses.gemspec +1 -0
- metadata +16 -6
- data/README.rdoc +0 -19
- data/lib/TodoCurses/list.rb +0 -88
- data/lib/TodoCurses/logger.rb +0 -21
- data/lib/TodoCurses/task.rb +0 -339
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 732f87d6a1d0039ec07cfdc464b9a81bf82ba1e3
|
4
|
+
data.tar.gz: f3111293b08d469ea38f092dc3a6319305a8e3f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 133900726e93cc036678fd9cc165655ebd91daf5854ccf3db4b177f970e94eb5045041223e76ead393ca3a9f42c19c2f97bfe7ec6ce07a4c4470365c4d27066d
|
7
|
+
data.tar.gz: 2f1b823f7438d4cee0e8280d6623db11fd39369274cfa5348d0994c99a30f47024911a8721502f3cbc9e456f097dd1e2ac68e7177e19b6a621c17e4e5d1d5fc6
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
todo-curses (0.0.
|
4
|
+
todo-curses (0.0.5)
|
5
5
|
methadone (~> 1.9, >= 1.9.2)
|
6
6
|
ncursesw (~> 1.4, >= 1.4.9)
|
7
|
+
todo-txt (~> 0.7)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
@@ -62,6 +63,7 @@ GEM
|
|
62
63
|
test-unit (3.1.8)
|
63
64
|
power_assert
|
64
65
|
thor (0.19.1)
|
66
|
+
todo-txt (0.7)
|
65
67
|
unicode-display_width (1.0.2)
|
66
68
|
|
67
69
|
PLATFORMS
|
data/README.md
CHANGED
@@ -31,7 +31,14 @@ Grab the gem:
|
|
31
31
|
Then you'll probably want to make an alias in your .\*rc file. Here's
|
32
32
|
mine:
|
33
33
|
|
34
|
-
alias
|
34
|
+
alias t="todo.sh"
|
35
|
+
alias tt="vim ~/dev/todo/todo.txt"
|
36
|
+
alias ts="cd ~/dev/todo;./save.sh;cd -;t archive"
|
37
|
+
alias ttt="todo-curses ~/dev/todo/todo.txt"
|
38
|
+
|
39
|
+
This gives three ways to interact with the todo.txt file, depending
|
40
|
+
on the task at hand. Because todo-curses is still in the experimental
|
41
|
+
phase, I use Vim for my day-to-day work.
|
35
42
|
|
36
43
|
## Current features
|
37
44
|
|
@@ -44,53 +51,6 @@ mine:
|
|
44
51
|
- Move priority up with `shift+k`
|
45
52
|
- Completed tasks are archived to done.txt on exit
|
46
53
|
|
47
|
-
## Planned features
|
48
|
-
|
49
|
-
- Safer file handling (confirmations, errors, etc.)
|
50
|
-
- Use ctrl instead of shift for priority change
|
51
|
-
- Color code priorities
|
52
|
-
- Add a spacer between priority groups
|
53
|
-
- Priority view with `ctrl+1`
|
54
|
-
- Project view with `ctrl+2`
|
55
|
-
- Strip out application wrapper; not needed
|
56
|
-
- Prep for release as a gem
|
57
|
-
- If no argument is given, open the default file. Default tbd.
|
58
|
-
|
59
|
-
## Ideas for later
|
60
|
-
|
61
|
-
- Shift+J: Cycle through displays (Priority, project, etc.)
|
62
|
-
- F: filter tasks (free-text, one filter condition per line)
|
63
|
-
- T: append text to selected tasks
|
64
|
-
- O or Ctrl+O: open todo.txt file
|
65
|
-
- C or Ctrl+N: new todo.txt file
|
66
|
-
|
67
|
-
## Things not included
|
68
|
-
|
69
|
-
- A: archive tasks
|
70
|
-
- Ctrl+C: copy task to clipboard
|
71
|
-
- Ctrl+Shift+C: copy task to edit field
|
72
|
-
- Win+Alt+T: hide/unhide windows
|
73
|
-
- 0: clear filter
|
74
|
-
- 1-9: apply numbered filter preset
|
75
|
-
|
76
|
-
## Keyboard shortcut ideas
|
77
|
-
|
78
|
-
- N: new task
|
79
|
-
- J: next task
|
80
|
-
- K: prev task
|
81
|
-
- X: toggle task completion
|
82
|
-
- D or Del or Backspace: delete task (with confirmation)
|
83
|
-
- E or F2: update task
|
84
|
-
- I: set priority
|
85
|
-
- . or F5: reload tasks from file
|
86
|
-
- ?: show help
|
87
|
-
- Shift+K: increase priority
|
88
|
-
- Shift+J: decrease priority
|
89
|
-
- Alt+Left/Right: clear priority
|
90
|
-
- Ctrl+Alt+Up: increase due date by 1 day
|
91
|
-
- Ctrl+Alt+Down: decrease due date by 1 day
|
92
|
-
- Ctrl+Alt+Left/Right: remove due date
|
93
|
-
|
94
54
|
## Development
|
95
55
|
|
96
56
|
To release a new version, update
|
data/Rakefile
CHANGED
@@ -23,6 +23,7 @@ def dump_load_path
|
|
23
23
|
puts "Found in #{path}"
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
26
27
|
require 'bundler'
|
27
28
|
require 'rake/clean'
|
28
29
|
|
@@ -38,12 +39,10 @@ include Rake::DSL
|
|
38
39
|
|
39
40
|
Bundler::GemHelper.install_tasks
|
40
41
|
|
41
|
-
|
42
42
|
Rake::TestTask.new do |t|
|
43
|
-
t.pattern = 'test
|
43
|
+
t.pattern = 'test/*.rb'
|
44
44
|
end
|
45
45
|
|
46
|
-
|
47
46
|
CUKE_RESULTS = 'results.html'
|
48
47
|
CLEAN << CUKE_RESULTS
|
49
48
|
Cucumber::Rake::Task.new(:features) do |t|
|
@@ -52,20 +51,12 @@ Cucumber::Rake::Task.new(:features) do |t|
|
|
52
51
|
end
|
53
52
|
|
54
53
|
Rake::RDocTask.new do |rd|
|
55
|
-
|
56
54
|
rd.main = "README.rdoc"
|
57
|
-
|
58
55
|
rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
|
59
56
|
end
|
60
57
|
|
61
58
|
task :default => [:test,:features]
|
62
59
|
|
63
|
-
# Run the test application
|
64
|
-
desc 'run'
|
65
|
-
task :run do
|
66
|
-
sh 'bundle exec bin/todo-curses list todo.txt'
|
67
|
-
end
|
68
|
-
|
69
60
|
# Reset the testing todo.txt file, if you have one.
|
70
61
|
desc 'reset'
|
71
62
|
task :reset do
|
@@ -77,5 +68,3 @@ desc 'Lint Ruby'
|
|
77
68
|
RuboCop::RakeTask.new(:rubocop) do |t|
|
78
69
|
t.patterns = ['bin/**/*.rb', 'lib/**/*.rb']
|
79
70
|
end
|
80
|
-
|
81
|
-
task default: :run
|
data/lib/TodoCurses/version.rb
CHANGED
data/lib/TodoCurses/view.rb
CHANGED
@@ -116,14 +116,14 @@ module TodoCurses
|
|
116
116
|
# Moves the current selection's priority up by one unless it is at Z.
|
117
117
|
def priority_up
|
118
118
|
item = @menu.current_item.user_object
|
119
|
-
item.priority_inc
|
119
|
+
item.priority_inc!
|
120
120
|
save_list
|
121
121
|
end
|
122
122
|
|
123
123
|
# Moves the current selection's priority down by one unless it is at A.
|
124
124
|
def priority_down
|
125
125
|
item = @menu.current_item.user_object
|
126
|
-
item.priority_dec
|
126
|
+
item.priority_dec!
|
127
127
|
save_list
|
128
128
|
end
|
129
129
|
|
data/lib/TodoCurses.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
require 'TodoCurses/list.rb'
|
2
|
-
require 'TodoCurses/logger.rb'
|
3
1
|
require 'TodoCurses/view.rb'
|
4
2
|
require 'TodoCurses/version.rb'
|
5
|
-
require '
|
3
|
+
require 'todo-txt'
|
6
4
|
|
7
5
|
module TodoCurses
|
8
|
-
include
|
6
|
+
include Todo
|
9
7
|
|
10
8
|
if ARGV.size != 1
|
11
9
|
printf("usage: #{$PROGRAM_NAME} file\n")
|
data/todo-curses.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency('aruba', '~> 0.14.1')
|
23
23
|
spec.add_dependency('methadone', '~> 1.9', '>= 1.9.2')
|
24
24
|
spec.add_dependency('ncursesw', '~> 1.4', '>= 1.4.9')
|
25
|
+
spec.add_dependency('todo-txt', '~> 0.7')
|
25
26
|
spec.add_development_dependency('test-unit', '~> 3.1', '>= 3.1.8')
|
26
27
|
spec.add_development_dependency('rubocop', '~> 0.39.0')
|
27
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: todo-curses
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Loren Rogers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -112,6 +112,20 @@ dependencies:
|
|
112
112
|
- - ">="
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: 1.4.9
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: todo-txt
|
117
|
+
requirement: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - "~>"
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0.7'
|
122
|
+
type: :runtime
|
123
|
+
prerelease: false
|
124
|
+
version_requirements: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - "~>"
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0.7'
|
115
129
|
- !ruby/object:Gem::Dependency
|
116
130
|
name: test-unit
|
117
131
|
requirement: !ruby/object:Gem::Requirement
|
@@ -162,16 +176,12 @@ files:
|
|
162
176
|
- Gemfile.lock
|
163
177
|
- LICENSE.txt
|
164
178
|
- README.md
|
165
|
-
- README.rdoc
|
166
179
|
- Rakefile
|
167
180
|
- bin/console
|
168
181
|
- bin/setup
|
169
182
|
- bin/todo-curses
|
170
183
|
- images/todo-curses-demo.gif
|
171
184
|
- lib/TodoCurses.rb
|
172
|
-
- lib/TodoCurses/list.rb
|
173
|
-
- lib/TodoCurses/logger.rb
|
174
|
-
- lib/TodoCurses/task.rb
|
175
185
|
- lib/TodoCurses/version.rb
|
176
186
|
- lib/TodoCurses/view.rb
|
177
187
|
- todo-curses.gemspec
|
data/README.rdoc
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
= todo-curses - DESCRIBE YOUR GEM
|
2
|
-
|
3
|
-
Author:: YOUR NAME (YOUR EMAIL)
|
4
|
-
Copyright:: Copyright (c) 2016 YOUR NAME
|
5
|
-
|
6
|
-
|
7
|
-
DESCRIBE YOUR GEM HERE
|
8
|
-
|
9
|
-
== Links
|
10
|
-
|
11
|
-
* {Source on Github}[LINK TO GITHUB]
|
12
|
-
* RDoc[LINK TO RDOC.INFO]
|
13
|
-
|
14
|
-
== Install
|
15
|
-
|
16
|
-
== Examples
|
17
|
-
|
18
|
-
== Contributing
|
19
|
-
|
data/lib/TodoCurses/list.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
module TodoCurses
|
2
|
-
# Handles todo.txt list files
|
3
|
-
class List < Array
|
4
|
-
# Initializes a Todo List object with a path to the corresponding todo.txt
|
5
|
-
# file. For example, if your todo.txt file is located at:
|
6
|
-
#
|
7
|
-
# /home/sam/Dropbox/todo/todo.txt
|
8
|
-
#
|
9
|
-
# You would initialize this object like:
|
10
|
-
#
|
11
|
-
# list = TodoCurses::List.new "/home/sam/Dropbox/todo/todo-txt"
|
12
|
-
#
|
13
|
-
# Alternately, you can initialize this object with an array of strings or
|
14
|
-
# tasks. If the array is of strings, the strings will be converted into
|
15
|
-
# tasks. You can supply a mixed list of string and tasks if you wish.
|
16
|
-
#
|
17
|
-
# Example:
|
18
|
-
#
|
19
|
-
# array = Array.new
|
20
|
-
# array.push "(A) A string task!"
|
21
|
-
# array.push TodoCurses::Task.new("(A) An actual task!")
|
22
|
-
#
|
23
|
-
# list = TodoCurses::List.new array
|
24
|
-
def initialize(list)
|
25
|
-
if list.is_a? Array
|
26
|
-
# No file path was given.
|
27
|
-
@path = nil
|
28
|
-
|
29
|
-
# If path is an array, loop over it, adding to self.
|
30
|
-
list.each do |task|
|
31
|
-
# If it's a string, make a new task out of it.
|
32
|
-
if task.is_a? String
|
33
|
-
push TodoCurses::Task.new task
|
34
|
-
# If it's a task, just add it.
|
35
|
-
elsif task.is_a? TodoCurses::Task
|
36
|
-
push task
|
37
|
-
end
|
38
|
-
end
|
39
|
-
elsif list.is_a? String
|
40
|
-
@path = list
|
41
|
-
|
42
|
-
# Read in lines from file, create TodoCurses::Tasks out of them and push them
|
43
|
-
# onto self.
|
44
|
-
File.open(list) do |file|
|
45
|
-
file.each_line { |line| push TodoCurses::Task.new line }
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# The path to the todo.txt file that you supplied when you created the
|
51
|
-
# TodoCurses::List object.
|
52
|
-
def path
|
53
|
-
@path
|
54
|
-
end
|
55
|
-
|
56
|
-
# Filters the list by priority and returns a new list.
|
57
|
-
#
|
58
|
-
# Example:
|
59
|
-
#
|
60
|
-
# list = TodoCurses::List.new "/path/to/list"
|
61
|
-
# list.by_priority "A" #=> Will be a new list with only priority A tasks
|
62
|
-
def by_priority(priority)
|
63
|
-
TodoCurses::List.new select { |task| task.priority == priority }
|
64
|
-
end
|
65
|
-
|
66
|
-
# Filters the list by context and returns a new list.
|
67
|
-
#
|
68
|
-
# Example:
|
69
|
-
#
|
70
|
-
# list = TodoCurses::List.new "/path/to/list"
|
71
|
-
# list.by_context "@context" #=> Will be a new list with only tasks
|
72
|
-
# containing "@context"
|
73
|
-
def by_context(context)
|
74
|
-
TodoCurses::List.new select { |task| task.contexts.include? context }
|
75
|
-
end
|
76
|
-
|
77
|
-
# Filters the list by project and returns a new list.
|
78
|
-
#
|
79
|
-
# Example:
|
80
|
-
#
|
81
|
-
# list = TodoCurses::List.new "/path/to/list"
|
82
|
-
# list.by_project "+project" #=> Will be a new list with only tasks
|
83
|
-
# containing "+project"
|
84
|
-
def by_project(project)
|
85
|
-
TodoCurses::List.new select { |task| task.projects.include? project }
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
data/lib/TodoCurses/logger.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
|
-
module TodoCurses
|
4
|
-
module Logger
|
5
|
-
def self.included base
|
6
|
-
base.extend(self)
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.logger= new_logger
|
10
|
-
@@logger = new_logger
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.logger
|
14
|
-
@@logger ||= ::Logger.new(STDOUT)
|
15
|
-
end
|
16
|
-
|
17
|
-
def logger
|
18
|
-
TodoCurses::Logger.logger
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/TodoCurses/task.rb
DELETED
@@ -1,339 +0,0 @@
|
|
1
|
-
require 'date'
|
2
|
-
|
3
|
-
module TodoCurses
|
4
|
-
class Task
|
5
|
-
include Comparable
|
6
|
-
include TodoCurses::Logger
|
7
|
-
|
8
|
-
# The regular expression used to match contexts.
|
9
|
-
def self.contexts_regex
|
10
|
-
/(?:\s+|^)@\w+/
|
11
|
-
end
|
12
|
-
|
13
|
-
# The regex used to match projects.
|
14
|
-
def self.projects_regex
|
15
|
-
/(?:\s+|^)\+\w+/
|
16
|
-
end
|
17
|
-
|
18
|
-
# The regex used to match priorities.
|
19
|
-
def self.priority_regex
|
20
|
-
/(?:^|\s+)\(([A-Za-z])\)\s+/
|
21
|
-
end
|
22
|
-
|
23
|
-
# The regex used to match creation date.
|
24
|
-
def self.created_on_regex
|
25
|
-
/(?:^|-\d{2}\s|\)\s)(\d{4}-\d{2}-\d{2})\s/
|
26
|
-
end
|
27
|
-
|
28
|
-
# The regex used to match completion.
|
29
|
-
def self.done_regex
|
30
|
-
/^x\s+(\d{4}-\d{2}-\d{2})\s+/
|
31
|
-
end
|
32
|
-
|
33
|
-
# The regex used to match due date.
|
34
|
-
def self.due_on_regex
|
35
|
-
/(?:due:)(\d{4}-\d{2}-\d{2})(?:\s+|$)/i
|
36
|
-
end
|
37
|
-
|
38
|
-
# Creates a new task. The argument that you pass in must be the string
|
39
|
-
# representation of a task.
|
40
|
-
#
|
41
|
-
# Example:
|
42
|
-
#
|
43
|
-
# task = TodoCurses::Task.new("(A) A high priority task!")
|
44
|
-
def initialize task
|
45
|
-
@orig = task
|
46
|
-
@completed_on = get_completed_date #orig.scan(self.class.done_regex)[1] ||= nil
|
47
|
-
@priority, @created_on = orig_priority, orig_created_on
|
48
|
-
@due_on = get_due_on_date
|
49
|
-
@contexts ||= orig.scan(self.class.contexts_regex).map { |item| item.strip }
|
50
|
-
@projects ||= orig.scan(self.class.projects_regex).map { |item| item.strip }
|
51
|
-
end
|
52
|
-
|
53
|
-
# Returns the original content of the task.
|
54
|
-
#
|
55
|
-
# Example:
|
56
|
-
#
|
57
|
-
# task = TodoCurses::Task.new "(A) @context +project Hello!"
|
58
|
-
# task.orig #=> "(A) @context +project Hello!"
|
59
|
-
attr_reader :orig
|
60
|
-
|
61
|
-
# Returns the task's creation date, if any.
|
62
|
-
#
|
63
|
-
# Example:
|
64
|
-
#
|
65
|
-
# task = TodoCurses::Task.new "(A) 2012-03-04 Task."
|
66
|
-
# task.created_on
|
67
|
-
# #=> <Date: 2012-03-04 (4911981/2,0,2299161)>
|
68
|
-
#
|
69
|
-
# Dates _must_ be in the YYYY-MM-DD format as specified in the todo.txt
|
70
|
-
# format. Dates in any other format will be classed as malformed and this
|
71
|
-
# attribute will be nil.
|
72
|
-
attr_reader :created_on
|
73
|
-
|
74
|
-
# Returns the task's completion date if task is done.
|
75
|
-
#
|
76
|
-
# Example:
|
77
|
-
#
|
78
|
-
# task = TodoCurses::Task.new "x 2012-03-04 Task."
|
79
|
-
# task.completed_on
|
80
|
-
# #=> <Date: 2012-03-04 (4911981/2,0,2299161)>
|
81
|
-
#
|
82
|
-
# Dates _must_ be in the YYYY-MM-DD format as specified in the todo.txt
|
83
|
-
# format. Dates in any other format will be classed as malformed and this
|
84
|
-
# attribute will be nil.
|
85
|
-
attr_reader :completed_on
|
86
|
-
|
87
|
-
# Returns the task's due date, if any.
|
88
|
-
#
|
89
|
-
# Example:
|
90
|
-
#
|
91
|
-
# task = TodoCurses::Task.new "(A) This is a task. due:2012-03-04"
|
92
|
-
# task.due_on
|
93
|
-
# #=> <Date: 2012-03-04 (4911981/2,0,2299161)>
|
94
|
-
#
|
95
|
-
# Dates _must_ be in the YYYY-MM-DD format as specified in the todo.txt
|
96
|
-
# format. Dates in any other format will be classed as malformed and this
|
97
|
-
# attribute will be nil.
|
98
|
-
attr_reader :due_on
|
99
|
-
|
100
|
-
# Returns the priority, if any.
|
101
|
-
#
|
102
|
-
# Example:
|
103
|
-
#
|
104
|
-
# task = TodoCurses::Task.new "(A) Some task."
|
105
|
-
# task.priority #=> "A"
|
106
|
-
#
|
107
|
-
# task = TodoCurses::Task.new "Some task."
|
108
|
-
# task.priority #=> nil
|
109
|
-
attr_reader :priority
|
110
|
-
|
111
|
-
# Returns an array of all the @context annotations.
|
112
|
-
#
|
113
|
-
# Example:
|
114
|
-
#
|
115
|
-
# task = Todo:Task.new "(A) @context Testing!"
|
116
|
-
# task.context #=> ["@context"]
|
117
|
-
attr_reader :contexts
|
118
|
-
|
119
|
-
# Returns an array of all the +project annotations.
|
120
|
-
#
|
121
|
-
# Example:
|
122
|
-
#
|
123
|
-
# task = Todo:Task.new "(A) +test Testing!"
|
124
|
-
# task.projects #=> ["+test"]
|
125
|
-
attr_reader :projects
|
126
|
-
|
127
|
-
# Gets just the text content of the todo, without the priority, contexts
|
128
|
-
# and projects annotations.
|
129
|
-
#
|
130
|
-
# Example:
|
131
|
-
#
|
132
|
-
# task = TodoCurses::Task.new "(A) @test Testing!"
|
133
|
-
# task.text #=> "Testing!"
|
134
|
-
def text
|
135
|
-
@text ||= orig.
|
136
|
-
gsub(self.class.done_regex, '').
|
137
|
-
gsub(self.class.priority_regex, '').
|
138
|
-
gsub(self.class.created_on_regex, '').
|
139
|
-
gsub(self.class.contexts_regex, '').
|
140
|
-
gsub(self.class.projects_regex, '').
|
141
|
-
gsub(self.class.due_on_regex, '').
|
142
|
-
strip
|
143
|
-
end
|
144
|
-
|
145
|
-
# Returns the task's creation date, if any.
|
146
|
-
#
|
147
|
-
# Example:
|
148
|
-
#
|
149
|
-
# task = TodoCurses::Task.new "(A) 2012-03-04 Task."
|
150
|
-
# task.date
|
151
|
-
# #=> <Date: 2012-03-04 (4911981/2,0,2299161)>
|
152
|
-
#
|
153
|
-
# Dates _must_ be in the YYYY-MM-DD format as specified in the todo.txt
|
154
|
-
# format. Dates in any other format will be classed as malformed and this
|
155
|
-
# method will return nil.
|
156
|
-
#
|
157
|
-
# Deprecated
|
158
|
-
def date
|
159
|
-
logger.warn("Task#date is deprecated, use created_on instead.")
|
160
|
-
|
161
|
-
@created_on
|
162
|
-
end
|
163
|
-
|
164
|
-
# Returns whether a task's due date is in the past.
|
165
|
-
#
|
166
|
-
# Example:
|
167
|
-
#
|
168
|
-
# task = TodoCurses::Task.new("This task is overdue! due:#{Date.today - 1}")
|
169
|
-
# task.overdue?
|
170
|
-
# #=> true
|
171
|
-
def overdue?
|
172
|
-
return true if !due_on.nil? && due_on < Date.today
|
173
|
-
false
|
174
|
-
end
|
175
|
-
|
176
|
-
# Returns if the task is done.
|
177
|
-
#
|
178
|
-
# Example:
|
179
|
-
#
|
180
|
-
# task = TodoCurses::Task.new "x 2012-12-08 Task."
|
181
|
-
# task.done?
|
182
|
-
# #=> true
|
183
|
-
#
|
184
|
-
# task = TodoCurses::Task.new "Task."
|
185
|
-
# task.done?
|
186
|
-
# #=> false
|
187
|
-
def done?
|
188
|
-
!@completed_on.nil?
|
189
|
-
end
|
190
|
-
|
191
|
-
# Completes the task on the current date.
|
192
|
-
#
|
193
|
-
# Example:
|
194
|
-
#
|
195
|
-
# task = TodoCurses::Task.new "2012-12-08 Task."
|
196
|
-
# task.done?
|
197
|
-
# #=> false
|
198
|
-
#
|
199
|
-
# task.do!
|
200
|
-
# task.done?
|
201
|
-
# #=> true
|
202
|
-
# task.created_on
|
203
|
-
# #=> <Date: 2012-12-08 (4911981/2,0,2299161)>
|
204
|
-
# task.completed_on
|
205
|
-
# #=> # the current date
|
206
|
-
def do!
|
207
|
-
@completed_on = Date.today
|
208
|
-
@priority = nil
|
209
|
-
end
|
210
|
-
|
211
|
-
# Marks the task as incomplete and resets its original priority.
|
212
|
-
#
|
213
|
-
# Example:
|
214
|
-
#
|
215
|
-
# task = TodoCurses::Task.new "x 2012-12-08 2012-03-04 Task."
|
216
|
-
# task.done?
|
217
|
-
# #=> true
|
218
|
-
#
|
219
|
-
# task.undo!
|
220
|
-
# task.done?
|
221
|
-
# #=> false
|
222
|
-
# task.created_on
|
223
|
-
# #=> <Date: 2012-03-04 (4911981/2,0,2299161)>
|
224
|
-
# task.completed_on
|
225
|
-
# #=> nil
|
226
|
-
def undo!
|
227
|
-
@completed_on = nil
|
228
|
-
@priority = orig_priority
|
229
|
-
end
|
230
|
-
|
231
|
-
# Toggles the task from complete to incomplete or vice versa.
|
232
|
-
#
|
233
|
-
# Example:
|
234
|
-
#
|
235
|
-
# task = TodoCurses::Task.new "x 2012-12-08 Task."
|
236
|
-
# task.done?
|
237
|
-
# #=> true
|
238
|
-
#
|
239
|
-
# task.toggle!
|
240
|
-
# task.done?
|
241
|
-
# #=> false
|
242
|
-
#
|
243
|
-
# task.toggle!
|
244
|
-
# task.done?
|
245
|
-
# #=> true
|
246
|
-
def toggle!
|
247
|
-
done? ? undo! : do!
|
248
|
-
end
|
249
|
-
|
250
|
-
# Returns this task as a string.
|
251
|
-
#
|
252
|
-
# Example:
|
253
|
-
#
|
254
|
-
# task = TodoCurses::Task.new "(A) 2012-12-08 Task"
|
255
|
-
# task.to_s
|
256
|
-
# #=> "(A) 2012-12-08 Task"
|
257
|
-
def to_s
|
258
|
-
priority_string = priority ? "(#{priority}) " : ""
|
259
|
-
done_string = done? ? "x #{completed_on} " : ""
|
260
|
-
created_on_string = created_on ? "#{created_on} " : ""
|
261
|
-
contexts_string = contexts.empty? ? "" : " #{contexts.join ' '}"
|
262
|
-
projects_string = projects.empty? ? "" : " #{projects.join ' '}"
|
263
|
-
due_on_string = due_on.nil? ? "" : " due:#{due_on}"
|
264
|
-
"#{done_string}#{priority_string}#{created_on_string}#{text}#{contexts_string}#{projects_string}#{due_on_string}"
|
265
|
-
end
|
266
|
-
|
267
|
-
# Compares the priorities of two tasks.
|
268
|
-
#
|
269
|
-
# Example:
|
270
|
-
#
|
271
|
-
# task1 = TodoCurses::Task.new "(A) Priority A."
|
272
|
-
# task2 = TodoCurses::Task.new "(B) Priority B."
|
273
|
-
#
|
274
|
-
# task1 > task2
|
275
|
-
# # => true
|
276
|
-
#
|
277
|
-
# task1 == task2
|
278
|
-
# # => false
|
279
|
-
#
|
280
|
-
# task2 > task1
|
281
|
-
# # => false
|
282
|
-
def <=> other_task
|
283
|
-
if self.priority.nil? and other_task.priority.nil?
|
284
|
-
0
|
285
|
-
elsif other_task.priority.nil?
|
286
|
-
1
|
287
|
-
elsif self.priority.nil?
|
288
|
-
-1
|
289
|
-
else
|
290
|
-
other_task.priority <=> self.priority
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
# Decreases the priority until Z.
|
295
|
-
def priority_dec
|
296
|
-
return if @priority.nil?
|
297
|
-
@priority = @priority.next if @priority.ord < 90
|
298
|
-
end
|
299
|
-
|
300
|
-
# Increases the priority until A. If it's nil, it sets it to A.
|
301
|
-
def priority_inc
|
302
|
-
if @priority.nil?
|
303
|
-
@priority = 'A'
|
304
|
-
else
|
305
|
-
@priority = (@priority.ord-1).chr if @priority.ord > 65
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
private
|
310
|
-
|
311
|
-
def orig_priority
|
312
|
-
@orig.match(self.class.priority_regex)[1] if @orig =~ self.class.priority_regex
|
313
|
-
end
|
314
|
-
|
315
|
-
def orig_created_on
|
316
|
-
begin
|
317
|
-
if @orig =~ self.class.created_on_regex
|
318
|
-
date = @orig.match self.class.created_on_regex
|
319
|
-
return Date.parse(date[1]) unless date.nil?
|
320
|
-
end
|
321
|
-
rescue; end
|
322
|
-
nil
|
323
|
-
end
|
324
|
-
|
325
|
-
def get_completed_date
|
326
|
-
begin
|
327
|
-
return Date.parse(self.class.done_regex.match(@orig)[1])
|
328
|
-
rescue; end
|
329
|
-
nil
|
330
|
-
end
|
331
|
-
|
332
|
-
def get_due_on_date
|
333
|
-
begin
|
334
|
-
return Date.parse(self.class.due_on_regex.match(@orig)[1])
|
335
|
-
rescue; end
|
336
|
-
nil
|
337
|
-
end
|
338
|
-
end
|
339
|
-
end
|