todo_txt_viewer 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8526fcfbd1454bcc870775a23bd2a4d329d9c383b21b5c1e1de4ff7a94875c29
4
- data.tar.gz: e031967fa019ecb04d05ea539c3f6b3b2e00dbc00094da03aed348460a967bcb
3
+ metadata.gz: a69fd8bd3e1b655560b79e099b77ca6929e009d7a6ded5e3678942a64fc9a4a9
4
+ data.tar.gz: 130056a1c4c8e7d81e15ecec1d6cb65a56d5fc4d758ad9ae219aee5a5192bafa
5
5
  SHA512:
6
- metadata.gz: 7ab92a1faa619acc813346642e323779b8796545104e95b7a0fb2c8501d00ae41b6bb238000a201f0232af5b14a042f39814612efaa79ddcfebb18e604906f63
7
- data.tar.gz: 1437dc5e3daeb46cedf7b2c9e80550513f2012244e76556332634428b6ec80234b5f95f6b124509324d1245ab3025a11552a099b6f624de65179002576160d95
6
+ metadata.gz: 93c84eb37bbec014b1a89c885952377a8b2744757926a0a30ed5cd527b7f801cc69a81b8da2aeecced436a7fac00fab609ccf1cf92fbb0b2fdce617346e92c28
7
+ data.tar.gz: db79b47882db96a94332866c696f45c4156057912725ada5076b9cea3772eb10704b5047dd97a1e538a7a9d3c44c9ca095c33d544d66215ea9c06fb1fabbd326
@@ -13,7 +13,7 @@ GEM
13
13
  rubocop-rspec (~> 1.30)
14
14
  ast (2.4.0)
15
15
  colorize (0.8.1)
16
- fullscreen_tui (0.1.0)
16
+ fullscreen_tui (0.1.1)
17
17
  colorize (~> 0.8)
18
18
  ruby-terminfo (~> 0.1)
19
19
  jaro_winkler (1.5.1)
@@ -14,6 +14,7 @@ module TodoTxtViewer
14
14
  @main_file = main_file.to_s
15
15
  @archive_file = archive_file.to_s
16
16
  load_file
17
+ self.selection += 1 if selected_line.is_a? HeaderLine
17
18
  end
18
19
 
19
20
  def key_press key # rubocop:disable Metrics/CyclomaticComplexity
@@ -31,15 +32,30 @@ module TodoTxtViewer
31
32
  end
32
33
  end
33
34
 
35
+ def go_up
36
+ super
37
+ selection.zero? ? go_down : super if selected_line.is_a? HeaderLine
38
+ end
39
+
40
+ def go_down
41
+ super
42
+ selection == lines.size - 1 ? go_up : super if selected_line.is_a? HeaderLine
43
+ end
44
+
34
45
  private
35
46
 
36
47
  def task_action action
48
+ return if selected_line.is_a? HeaderLine
49
+
50
+ task = selected_line.task
37
51
  selected_line.task_action action
38
52
  @list.save!
39
- load_lines
53
+ load_lines selected_task: task
40
54
  end
41
55
 
42
56
  def archive_task
57
+ return if selected_line.is_a? HeaderLine
58
+
43
59
  archive = Todo::List.new @archive_file
44
60
  task = selected_line.task
45
61
  @list.delete_if {|other| other.object_id == task.object_id }
@@ -47,16 +63,18 @@ module TodoTxtViewer
47
63
  archive.save!
48
64
  @list.save!
49
65
  load_lines
50
- @footer.message = "Archived the Task #{task}"
66
+ footer.message = "Archived the Task #{task}"
51
67
  end
52
68
 
53
69
  def select_priority key
70
+ return if selected_line.is_a? HeaderLine
71
+
54
72
  task = selected_line.task
55
73
  key = key.to_i
56
74
  priority = key.zero? ? nil : ('A'.ord + key - 1).chr
57
75
  task.instance_variable_set :@priority, priority
58
76
  @list.save!
59
- load_lines
77
+ load_lines selected_task: task
60
78
  end
61
79
 
62
80
  def create_task
@@ -65,8 +83,8 @@ module TodoTxtViewer
65
83
  task.instance_variable_set(:@created_on, Date.today) unless task.created_on
66
84
  @list << task
67
85
  @list.save!
68
- load_lines
69
- @footer.message = 'Task inserted'
86
+ load_lines selected_task: task
87
+ footer.message = 'Task inserted'
70
88
  end
71
89
 
72
90
  def help
@@ -76,17 +94,22 @@ module TodoTxtViewer
76
94
  def load_file
77
95
  @list = Todo::List.new @main_file
78
96
  load_lines
79
- @footer.message = "Loaded: #{@main_file}"
97
+ footer.message = "Loaded: #{@main_file}"
80
98
  end
81
99
 
82
- def load_lines
83
- @lines = []
100
+ def load_lines selected_task: nil
101
+ self.lines = []
102
+
103
+ lines << HeaderLine.new('# todo')
104
+ @list.by_not_done.sort.reverse_each {|t| lines << TaskLine.new(t) }
105
+
106
+ lines << HeaderLine.new('# done')
107
+ @list.by_done.sort.reverse_each {|t| lines << TaskLine.new(t) }
84
108
 
85
- @lines << HeaderLine.new('# todo')
86
- @list.by_not_done.sort.reverse_each {|t| @lines << TaskLine.new(t) }
109
+ return if selected_task.nil?
87
110
 
88
- @lines << HeaderLine.new('# done')
89
- @list.by_done.sort.reverse_each {|t| @lines << TaskLine.new(t) }
111
+ idx = lines.index {|l| l.respond_to?(:task) && l.task.object_id == selected_task.object_id }
112
+ self.selection = idx if idx
90
113
  end
91
114
  end
92
115
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TodoTxtViewer
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: todo_txt_viewer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Ganz