timr 0.1.0 → 0.2.0

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.
@@ -1,5 +1,6 @@
1
1
 
2
2
  require 'time'
3
+ require 'uuid'
3
4
  require 'thefox-ext'
4
5
 
5
6
  module TheFox
@@ -7,10 +8,42 @@ module TheFox
7
8
 
8
9
  class Track
9
10
 
10
- def initialize(task = nil, begin_time = Time.now, end_time = nil)
11
+ def initialize
12
+ @id = UUID.new.generate
13
+ @parent = nil
14
+ @parent_id = nil
15
+ @task = nil
16
+ @begin_time = nil
17
+ @end_time = nil
18
+ @description = nil
19
+ end
20
+
21
+ def id=(id)
22
+ @id = id
23
+ end
24
+
25
+ def id
26
+ @id
27
+ end
28
+
29
+ def parent=(parent)
30
+ @parent = parent
31
+ end
32
+
33
+ def parent
34
+ @parent
35
+ end
36
+
37
+ def parent_id=(parent_id)
38
+ @parent_id = parent_id
39
+ end
40
+
41
+ def parent_id
42
+ @parent_id
43
+ end
44
+
45
+ def task=(task)
11
46
  @task = task
12
- @begin_time = begin_time
13
- @end_time = end_time
14
47
  end
15
48
 
16
49
  def task
@@ -43,6 +76,14 @@ module TheFox
43
76
  end
44
77
  end
45
78
 
79
+ def description
80
+ @description
81
+ end
82
+
83
+ def description=(descr_s)
84
+ @description = descr_s == '' ? nil : descr_s
85
+ end
86
+
46
87
  def diff
47
88
  if !@begin_time.nil? && !@end_time.nil?
48
89
  (@end_time - @begin_time).abs.to_i
@@ -53,16 +94,27 @@ module TheFox
53
94
 
54
95
  def to_h
55
96
  h = {
56
- 'b' => nil,
57
- 'e' => nil,
97
+ 'id' => @id,
98
+ #'p' => nil, # parent_id
99
+ #'b' => nil, # begin time
100
+ #'e' => nil, # end time
101
+ #'d' => nil, # description
58
102
  }
59
- h['b'] = @begin_time.utc.strftime(TIME_FORMAT) if !@begin_time.nil?
60
- h['e'] = @end_time.utc.strftime(TIME_FORMAT) if !@end_time.nil?
103
+ h['p'] = @parent.id if !@parent.nil?
104
+ h['p'] = @parent_id if !@parent_id.nil?
105
+
106
+ h['b'] = @begin_time.utc.strftime(TIME_FORMAT_FILE) if !@begin_time.nil?
107
+ h['e'] = @end_time.utc.strftime(TIME_FORMAT_FILE) if !@end_time.nil?
108
+
109
+ #h['d'] = @description if !@description.nil?
110
+ d = description
111
+ h['d'] = d if !d.nil?
112
+
61
113
  h
62
114
  end
63
115
 
64
116
  def to_s
65
- 'track'
117
+ @id
66
118
  end
67
119
 
68
120
  def to_list_s
@@ -85,14 +137,27 @@ module TheFox
85
137
  if !@task.nil?
86
138
  task_name = @task.to_list_s
87
139
  end
140
+ #task_name = @id[0..4]
88
141
 
89
- '%10s %5s - %5s %10s %s' % [begin_date_s, @begin_time.localtime.strftime('%R'), end_time_s, end_date_s, task_name]
142
+ descr_s = ''
143
+ if !@description.nil? && @description.length > 0
144
+ descr_s = ": #{@description}"
145
+ end
146
+
147
+ '%10s %5s - %5s %10s %s%s' % [
148
+ begin_date_s, @begin_time.localtime.strftime('%R'), end_time_s, end_date_s,
149
+ task_name, descr_s]
90
150
  end
91
151
 
92
152
  def self.from_h(task = nil, h)
93
- t = Track.new(task, nil)
153
+ t = Track.new
154
+ t.task = task
155
+ t.id = h['id'] if h.has_key?('id')
156
+ t.parent_id = h['p'] if h.has_key?('p')
94
157
  t.begin_time = Time.parse(h['b']) if h.has_key?('b')
95
158
  t.end_time = Time.parse(h['e']) if h.has_key?('e')
159
+ t.description = h['d'] if h.has_key?('d')
160
+
96
161
  t
97
162
  end
98
163
 
@@ -2,8 +2,8 @@
2
2
  module TheFox
3
3
  module Timr
4
4
  NAME = 'Timr'
5
- VERSION = '0.1.0'
6
- DATE = '2016-05-15'
5
+ VERSION = '0.2.0'
6
+ DATE = '2016-05-22'
7
7
  HOMEPAGE = 'https://github.com/TheFox/timr'
8
8
 
9
9
  COL = 1
@@ -16,8 +16,8 @@ module TheFox
16
16
  # - Status Text Line
17
17
  RESERVED_LINES = 3
18
18
 
19
- TIME_FORMAT = '%FT%T%z'
19
+ TIME_FORMAT_FILE = '%FT%T%z'
20
20
 
21
- TASK_NO_TASK_LOADED_C = ?-
21
+ TASK_NO_TASK_LOADED_CHAR = ?-
22
22
  end
23
23
  end
@@ -218,6 +218,35 @@ module TheFox
218
218
  end
219
219
  end
220
220
 
221
+ def cursor_border_top
222
+ previous_page? ? 3 : 1
223
+ end
224
+
225
+ def cursor_border_bottom
226
+ #next_page? ? @content_length - 2 : -1
227
+ next_page? ? @content_length - 2 : @content_length
228
+ end
229
+
230
+ def cursor_on_inner_range?
231
+ if previous_page?
232
+ if next_page?
233
+ # Middle
234
+ @cursor > cursor_border_top && @cursor < cursor_border_bottom
235
+ else
236
+ # Bottom
237
+ @cursor >= cursor_border_top
238
+ end
239
+ else
240
+ if next_page?
241
+ # First page.
242
+ @cursor <= cursor_border_bottom
243
+ else
244
+ # Only one page, so middle.
245
+ true
246
+ end
247
+ end
248
+ end
249
+
221
250
  end
222
251
 
223
252
  end
@@ -8,27 +8,29 @@ module TheFox
8
8
  [
9
9
  '#### Help ####',
10
10
  '',
11
- ' n .. Create a New Task',
12
- ' c .. Current Task: Start/Continue',
13
- ' x .. Current Task: Stop',
14
- ' v .. Current Task: Stop and Pop from Stack',
15
- ' f .. Stop and deselect all Tasks on the Stack',
16
- ' p, b .. Push and start selected Task.',
17
- ' r .. Refresh Window',
18
- ' w .. Write all changes.',
19
- ' q .. Exit',
20
- ' h .. Help',
21
- ' 1 .. Timeline Window',
22
- ' 2 .. Tasks Window',
23
- ' RETURN .. Start selected task.',
24
- ' KEY UP .. Move Cursor up.',
25
- ' KEY DOWN .. Move Cursor down.',
11
+ ' n .. Create a new Task and start',
12
+ ' t .. Create a new Task',
13
+ ' c .. Current Task: Start/Continue',
14
+ ' x .. Current Task: Stop',
15
+ ' v .. Current Task: Stop and Pop from Stack',
16
+ ' f .. Stop and deselect all Tasks on the Stack',
17
+ ' p, b .. Push and start selected Task.',
18
+ ' r .. Refresh Window',
19
+ ' w .. Write all changes.',
20
+ ' q .. Exit',
21
+ ' h .. Help',
22
+ ' 1 .. Timeline Window',
23
+ ' 2 .. Tasks Window',
24
+ ' RETURN .. Start selected Task.',
25
+ ' # .. Start selected Task, edit Track Description.',
26
+ ' KEY UP .. Move Cursor up.',
27
+ ' KEY DOWN .. Move Cursor down.',
26
28
  '',
27
29
  'Current Task Status',
28
30
  '',
29
- " #{TASK_NO_TASK_LOADED_C} .. No task loaded.",
30
- ' | .. Task stopped.',
31
- ' > .. Task is running.',
31
+ " #{TASK_NO_TASK_LOADED_CHAR} .. No Task loaded.",
32
+ ' | .. Task stopped.',
33
+ ' > .. Task is running.',
32
34
  ]
33
35
  end
34
36
 
@@ -8,6 +8,10 @@ module TheFox
8
8
 
9
9
  @tasks = nil
10
10
 
11
+ def setup
12
+ @tasks = nil
13
+ end
14
+
11
15
  def tasks=(tasks)
12
16
  content_changed
13
17
  @tasks = tasks
@@ -18,9 +22,10 @@ module TheFox
18
22
  @has_cursor = false
19
23
  [
20
24
  '',
21
- '#### NO TASKS YET ####',
25
+ '#### NO TASKS YET ####',
22
26
  '',
23
27
  "Press 'n' to create a new task.",
28
+ " Or 'h' to jump to the help page.",
24
29
  ]
25
30
  else
26
31
  @has_cursor = true
@@ -6,6 +6,10 @@ module TheFox
6
6
 
7
7
  @tasks = nil
8
8
 
9
+ def setup
10
+ @tasks = nil
11
+ end
12
+
9
13
  def tasks=(tasks)
10
14
  content_changed
11
15
  @tasks = tasks
@@ -16,9 +20,10 @@ module TheFox
16
20
  @has_cursor = false
17
21
  [
18
22
  '',
19
- '#### NO TASKS YET ####',
23
+ '#### NO TRACKS YET ####',
20
24
  '',
21
25
  "Press 'n' to create a new task.",
26
+ " Or 'h' to jump to the help page.",
22
27
  ]
23
28
  else
24
29
  @has_cursor = true
@@ -6,14 +6,14 @@ require 'timr'
6
6
 
7
7
  class TestStack < MiniTest::Test
8
8
  def test_class_name
9
- stack = TheFox::Timr::Stack.new
9
+ stack1 = TheFox::Timr::Stack.new
10
10
 
11
- assert_equal('TheFox::Timr::Stack', stack.class.to_s)
11
+ assert_equal('TheFox::Timr::Stack', stack1.class.to_s)
12
12
  end
13
13
 
14
14
  def test_has_task
15
- stack = TheFox::Timr::Stack.new
16
- assert_equal(false, stack.has_task?)
15
+ stack1 = TheFox::Timr::Stack.new
16
+ assert_equal(false, stack1.has_task?)
17
17
  end
18
18
 
19
19
  def test_push_pop
@@ -22,75 +22,97 @@ class TestStack < MiniTest::Test
22
22
  task2 = TheFox::Timr::Task.new
23
23
  task2.name = 'task2'
24
24
 
25
- stack = TheFox::Timr::Stack.new
26
- assert_equal([], stack.tasks_texts)
27
- assert_equal(nil, stack.task)
28
- assert_equal(0, stack.length)
25
+ stack1 = TheFox::Timr::Stack.new
26
+ assert_equal([], stack1.tasks_texts)
27
+ assert_equal(nil, stack1.task)
28
+ assert_equal(0, stack1.size)
29
29
 
30
- push_res = stack.push(task1)
30
+ push_res = stack1.push(task1)
31
31
  assert_equal(true, push_res)
32
- assert_equal(task1, stack.task)
33
- assert_equal(1, stack.length)
32
+ assert_equal(task1, stack1.task)
33
+ assert_equal(1, stack1.size)
34
34
  assert_equal(true, task1.running?)
35
- assert_equal(['* task1'], stack.tasks_texts)
35
+ assert_equal(['* task1'], stack1.tasks_texts)
36
36
 
37
- push_res = stack.push(task2)
37
+ push_res = stack1.push(task2)
38
38
  assert_equal(true, push_res)
39
- assert_equal(task2, stack.task)
40
- assert_equal(2, stack.length)
39
+ assert_equal(task2, stack1.task)
40
+ assert_equal(2, stack1.size)
41
41
  assert_equal(true, task2.running?)
42
42
  assert_equal(false, task1.running?)
43
- assert_equal(['| task1', '* task2'], stack.tasks_texts)
43
+ assert_equal(['# task1', '* task2'], stack1.tasks_texts)
44
44
 
45
45
  # if !@tasks.include?(task)
46
- push_res = stack.push(task2)
46
+ push_res = stack1.push(task2)
47
47
  assert_equal(false, push_res)
48
- assert_equal(2, stack.length)
48
+ assert_equal(2, stack1.size)
49
49
 
50
- pop_res = stack.pop
50
+ pop_res = stack1.pop
51
51
  assert_equal(true, pop_res)
52
- assert_equal(task1, stack.task)
53
- assert_equal(1, stack.length)
52
+ assert_equal(task1, stack1.task)
53
+ assert_equal(1, stack1.size)
54
54
  assert_equal(true, task1.running?)
55
55
  assert_equal(false, task2.running?)
56
- assert_equal(['* task1'], stack.tasks_texts)
56
+ assert_equal(['* task1'], stack1.tasks_texts)
57
57
 
58
- pop_res = stack.pop
58
+ pop_res = stack1.pop
59
59
  assert_equal(true, pop_res)
60
- assert_equal([], stack.tasks_texts)
61
- assert_equal(nil, stack.task)
62
- assert_equal(0, stack.length)
60
+ assert_equal([], stack1.tasks_texts)
61
+ assert_equal(nil, stack1.task)
62
+ assert_equal(0, stack1.size)
63
63
 
64
64
  # if !old.nil?
65
- pop_res = stack.pop
65
+ pop_res = stack1.pop
66
66
  assert_equal(false, pop_res)
67
-
68
-
69
- # Pop All
67
+ end
68
+
69
+ def test_pop_all
70
70
  task3 = TheFox::Timr::Task.new
71
- task3.name = 'task3'
71
+ #task3.name = 'task3'
72
72
  task4 = TheFox::Timr::Task.new
73
- task4.name = 'task4'
73
+ #task4.name = 'task4'
74
74
  task5 = TheFox::Timr::Task.new
75
- task5.name = 'task5'
75
+ #task5.name = 'task5'
76
+
77
+ stack1 = TheFox::Timr::Stack.new
78
+
79
+ stack1.push(task3)
80
+ assert_equal(true, task3.running?)
81
+ assert_equal(false, task4.running?)
82
+ assert_equal(false, task5.running?)
83
+
84
+ stack1.push(task4)
85
+ assert_equal(2, stack1.size)
86
+ assert_equal(false, task3.running?)
87
+ assert_equal(true, task4.running?)
88
+ assert_equal(false, task5.running?)
89
+
90
+ assert_equal(true, stack1.pop_all(task5))
91
+ assert_equal(1, stack1.size)
76
92
 
77
- stack.push(task3)
78
- stack.push(task4)
79
- assert_equal(2, stack.length)
80
- pop_all_res = stack.pop_all(task5)
81
- assert_equal(true, pop_all_res)
82
- assert_equal(1, stack.length)
93
+ assert_equal(false, stack1.pop_all(task5))
94
+ assert_equal(1, stack1.size)
95
+ assert_equal(false, task3.running?)
96
+ assert_equal(false, task4.running?)
97
+ assert_equal(true, task5.running?)
83
98
 
84
- pop_all_res = stack.pop_all(task5)
85
- assert_equal(false, pop_all_res)
86
- assert_equal(1, stack.length)
99
+ task5_track = task5.track
100
+ assert_equal(false, task5_track.nil?)
87
101
 
102
+ assert_equal(false, stack1.pop_all(task5))
88
103
  assert_equal(false, task3.running?)
89
104
  assert_equal(false, task4.running?)
90
105
  assert_equal(true, task5.running?)
91
106
 
92
- pop_all_res = stack.pop_all
93
- assert_equal(true, pop_all_res)
94
- assert_equal(0, stack.length)
107
+ task5_track = task5.track
108
+ assert_equal(false, task5_track.nil?)
109
+ assert_equal(false, stack1.pop_all(task5, task5_track))
110
+
111
+ # Pop All with no new Task.
112
+ assert_equal(true, stack1.pop_all)
113
+ assert_equal(0, stack1.size)
114
+ assert_equal(false, task3.running?)
115
+ assert_equal(false, task4.running?)
116
+ assert_equal(false, task5.running?)
95
117
  end
96
118
  end
@@ -8,9 +8,9 @@ require 'timr'
8
8
 
9
9
  class TestTask < MiniTest::Test
10
10
  def test_class_name
11
- task = TheFox::Timr::Task.new
11
+ task1 = TheFox::Timr::Task.new
12
12
 
13
- assert_equal('TheFox::Timr::Task', task.class.to_s)
13
+ assert_equal('TheFox::Timr::Task', task1.class.to_s)
14
14
  end
15
15
 
16
16
  def test_save_load
@@ -20,7 +20,7 @@ class TestTask < MiniTest::Test
20
20
  assert_equal(false, File.exist?(file_path))
21
21
 
22
22
  task1.name = 'task1'
23
- task1.description = 'description2'
23
+ task1.description = 'hello world1'
24
24
  file_path = task1.save_to_file('tmp')
25
25
  assert_equal(true, File.exist?(file_path))
26
26
 
@@ -29,12 +29,12 @@ class TestTask < MiniTest::Test
29
29
 
30
30
  assert_equal(task1.id, task2.id)
31
31
  assert_equal('task1', task2.name)
32
- assert_equal('description2', task2.description)
32
+ assert_equal('hello world1', task2.description)
33
33
 
34
34
  FileUtils.rm_r(file_path)
35
35
  end
36
36
 
37
- def test_running
37
+ def test_status
38
38
  task1 = TheFox::Timr::Task.new
39
39
  assert_equal(false, task1.running?)
40
40
  assert_equal(?|, task1.status)
@@ -46,44 +46,90 @@ class TestTask < MiniTest::Test
46
46
  task1.stop
47
47
  assert_equal(false, task1.running?)
48
48
  assert_equal(?|, task1.status)
49
+
50
+ task1.start
51
+ assert_equal(true, task1.running?)
52
+ assert_equal(?>, task1.status)
53
+
54
+ task1.pause
55
+ assert_equal(false, task1.running?)
56
+ assert_equal(true, task1.paused?)
57
+ assert_equal(?#, task1.status)
58
+
59
+ task1.stop
60
+ assert_equal(false, task1.running?)
61
+ assert_equal(?|, task1.status)
49
62
  end
50
63
 
51
- def test_track
64
+ def test_start_stop
52
65
  task1 = TheFox::Timr::Task.new
66
+ assert_equal(false, task1.running?)
53
67
  assert_equal(false, task1.has_track?)
54
68
  assert_equal(0, task1.timeline.length)
55
69
 
56
- task1.start
70
+ assert_equal(true, task1.start)
71
+ assert_equal(true, task1.running?)
57
72
  assert_equal(true, task1.has_track?)
58
73
  assert_equal(1, task1.timeline.length)
59
74
 
60
75
  task1.stop
76
+ assert_equal(false, task1.running?)
61
77
  assert_equal(false, task1.has_track?)
62
78
  assert_equal(1, task1.timeline.length)
63
79
 
64
- task1.start
80
+ assert_equal(true, task1.start)
81
+ assert_equal(true, task1.running?)
82
+ assert_equal(true, task1.has_track?)
83
+ assert_equal(2, task1.timeline.length)
84
+
85
+ assert_equal(false, task1.start)
86
+ assert_equal(true, task1.running?)
65
87
  assert_equal(true, task1.has_track?)
66
88
  assert_equal(2, task1.timeline.length)
67
89
 
68
90
  task1.stop
91
+ assert_equal(false, task1.running?)
69
92
  assert_equal(false, task1.has_track?)
70
93
  assert_equal(2, task1.timeline.length)
71
94
 
72
95
  task1.toggle
96
+ assert_equal(true, task1.running?)
73
97
  assert_equal(true, task1.has_track?)
74
98
  assert_equal(3, task1.timeline.length)
75
99
 
76
100
  task1.toggle
101
+ assert_equal(false, task1.running?)
77
102
  assert_equal(false, task1.has_track?)
78
103
  assert_equal(3, task1.timeline.length)
104
+
105
+ # Track
106
+ assert_equal(true, task1.start)
107
+
108
+ track1 = TheFox::Timr::Track.new
109
+ track1.description = 'hello world1'
110
+ track2 = TheFox::Timr::Track.new
111
+ track2.description = 'hello world2'
112
+
113
+ assert_equal(true, task1.start(track1))
114
+ assert_equal(false, task1.start(track1))
115
+ assert_equal(true, task1.start(track2))
79
116
  end
80
117
 
81
118
  def test_to_s
82
119
  task1 = TheFox::Timr::Task.new
83
- assert_equal(nil, task1.to_s)
120
+ assert_equal('', task1.to_s)
84
121
 
85
122
  task1.name = 'task1'
86
123
  assert_equal('task1', task1.to_s)
124
+
125
+ track1 = TheFox::Timr::Track.new
126
+ track1.description = 'hello world1'
127
+
128
+ task1.start(track1)
129
+ assert_equal('task1: hello world1', task1.to_s)
130
+
131
+ task1.stop
132
+ assert_equal('task1', task1.to_s)
87
133
  end
88
134
 
89
135
  def test_run_time_track