intent 0.7.0 → 0.7.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a80e9d9082642b1f2325b40629ff95ffb096cdba644d0f2d5aa2af25541c2d2b
4
- data.tar.gz: 90ed06f5afbf84636fbeb70e6fab66a4868dc0d485b751178b2ff31568315237
3
+ metadata.gz: 1a78826427e690ed80d21f63d75c009a652d8f7e6152250a0259d21af5ec36d2
4
+ data.tar.gz: 04c84e824a0787fed413ca28155143e407d322a8a5dd4dac76e0a14ee569a790
5
5
  SHA512:
6
- metadata.gz: a4a23b8d4882af953e2d330c26388c91bb86513c1881192952998f6f74b5f49b682f4b609566ea18b0b6f0ad7517020ac15ccc22ce8756edc001ac5fc25c455b
7
- data.tar.gz: cfc14324613fc505a6ec0a591e73f667dd3360b4ec1d8ee7f05d86813fcbaf5e645f12b917579adc6b046223dbc251f665f65b0cd70087dac39d59cc7adfdccf
6
+ metadata.gz: 61ed11963ba4317356bdfef7d2213fe1f1b2b29153697a34c2d6bd2ce5a09a7f61c12a296c50879909f7f650b556ee7d4f0bce0ce11fc5de891c4a140264f546
7
+ data.tar.gz: 79ba7a74906c8607edffeafc5d8555afe5853212d47b7253f8d2788567d13e4a843234a3d6934adfc1118315f3ac513e6567a5056aad1748497b73f74babe452
data/intent.gemspec CHANGED
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_runtime_dependency "tty-table", "~> 0.12.0"
33
33
  spec.add_runtime_dependency "tty-tree", "~> 0.4.0"
34
34
  spec.add_runtime_dependency "nanoid", "~> 2.0.0"
35
+ spec.add_runtime_dependency "paint", "~> 2.3.0"
35
36
 
36
37
  spec.add_development_dependency "bundler"
37
38
  spec.add_development_dependency "rake"
@@ -35,7 +35,7 @@ module Intent
35
35
  private
36
36
 
37
37
  def inventory_tree
38
- pastel = Pastel.new
38
+ color = ::Intent::UI::TermColor.new
39
39
  root = {}
40
40
  documents.inventory.boxes.each do |box|
41
41
  color_code = case box.tags[:id][0].downcase.to_sym
@@ -46,21 +46,23 @@ module Intent
46
46
  else
47
47
  :white
48
48
  end
49
- box_key = "#{pastel.decorate(box.tags[:id], :bold, color_code)} #{box.text}"
49
+ box_key = "#{color.bold.decorate(box.tags[:id], color_code)} #{box.text}"
50
50
  child_items = documents.inventory.items_in(box.tags[:id]).map do |item|
51
- "#{pastel.decorate(item.tags[:id], :bold, color_code)} #{item.text}"
51
+ "#{color.bold.decorate(item.tags[:id], color_code)} #{item.text}"
52
52
  end
53
53
  root[box_key] = child_items
54
54
  end
55
55
  root
56
56
  end
57
57
 
58
+ # ui format reader
58
59
  def inventory_units_of(type)
59
60
  documents.inventory.units_of(type).map do |unit|
60
61
  [unit.text, unit.tags[:sku]]
61
62
  end.to_h
62
63
  end
63
64
 
65
+ # ui format reader
64
66
  def inventory_unassigned_folders
65
67
  folder_types = documents.inventory.units_of(:folder)
66
68
  documents.inventory.unassigned_folders.map do |folder|
@@ -69,6 +71,16 @@ module Intent
69
71
  end.to_h
70
72
  end
71
73
 
74
+ # ui format reader
75
+ def inventory_assigned_boxes
76
+ box_types = documents.inventory.units_of(:box)
77
+ documents.inventory.assigned_boxes.map do |box|
78
+ unit_label = box_types.find { |f| f.tags[:sku] == box.tags[:sku] }
79
+ ["#{box.text} #{box.tags[:id]} (#{unit_label.text})", box.tags[:id]]
80
+ end.to_h
81
+ end
82
+
83
+ # ui format reader
72
84
  def inventory_unassigned_boxes
73
85
  box_types = documents.inventory.units_of(:box)
74
86
  documents.inventory.unassigned_boxes.map do |box|
@@ -98,6 +110,7 @@ module Intent
98
110
 
99
111
  def add_folder(args, output)
100
112
  skus = inventory_units_of(:folder)
113
+ projects = documents.projects.all_tokens
101
114
  prompt = TTY::Prompt.new
102
115
  ref = self
103
116
 
@@ -105,12 +118,35 @@ module Intent
105
118
  key(:sku).select('sku:', skus, filter: true)
106
119
  key(:id).ask('id:', default: ref.generate_id)
107
120
  key(:label).ask('label:', default: '[Unlabelled Folder]')
108
- key(:active).yes?('is active:')
109
121
  end
110
-
111
- label = item[:active] ? "#{item[:label]} @active" : item[:label]
112
122
 
113
- documents.inventory.add_folder!(label, item[:id], item[:sku])
123
+ should_assign_projects = prompt.yes?('assign to projects:')
124
+
125
+ if should_assign_projects
126
+ assigned_projects = prompt.multi_select('projects:', projects, filter: true)
127
+ label = "#{item[:label]} #{assigned_projects.join(' ')}"
128
+ else
129
+ label = item[:label]
130
+ end
131
+
132
+ should_file_in = prompt.select('file in:', {
133
+ "Active, not in box" => :active,
134
+ "Unassigned box" => :unassigned,
135
+ "Assigned project box" => :assigned
136
+ })
137
+
138
+ case should_file_in
139
+ when :active
140
+ label << " @active"
141
+ in_box = nil
142
+ when :unassigned
143
+ in_box = prompt.select('box', inventory_unassigned_boxes)
144
+ when :assigned
145
+ # TODO: filter on selected projects only
146
+ in_box = prompt.select('box:', inventory_assigned_boxes)
147
+ end
148
+
149
+ documents.inventory.add_folder!(label, item[:id], item[:sku], in_box)
114
150
  end
115
151
 
116
152
  def add_box(args, output)
@@ -125,7 +161,7 @@ module Intent
125
161
  end
126
162
 
127
163
  # Repository write pattern
128
- documents.inventory.add_box!(label, item[:id], item[:sku])
164
+ documents.inventory.add_box!(item[:label], item[:id], item[:sku])
129
165
 
130
166
  # Alternative design
131
167
  # noun = create_noun(:box, label, tags)
data/lib/intent/core.rb CHANGED
@@ -105,14 +105,15 @@ module Intent
105
105
  @list.save!
106
106
  end
107
107
 
108
- def add_item!(description, id, type, sku)
108
+ def add_item!(description, id, type, sku, box=nil)
109
+ description << " in:#{box}" unless box.nil?
109
110
  record = Record.new("#{Date.today} #{description} id:#{id} is:#{type} sku:#{sku}")
110
111
  @list.append(record)
111
112
  @list.save!
112
113
  end
113
114
 
114
- def add_folder!(description, id, sku)
115
- add_item!(description, id, :folder, sku)
115
+ def add_folder!(description, id, sku, box=nil)
116
+ add_item!(description, id, :folder, sku, box)
116
117
  end
117
118
 
118
119
  def add_box!(description, id, sku)
@@ -0,0 +1,80 @@
1
+ module Intent
2
+ module UI
3
+ # Shim to convert between Pastel to Paint gems
4
+ # without needing to edit existing call sites.
5
+ #
6
+ # It might be helpful to normalize this convention with an API
7
+ # anyway as we generally want to use the 8/16 colour defaults
8
+ # as they pick up user terminal customisation properly, whereas
9
+ # going full 256 or 24 bit colour means generic RGB values are likely
10
+ # to look shit on customised terminal backgrounds.
11
+ #
12
+ # This way we get the benefits of *mostly* sticking to the terminal
13
+ # defaults, while extending the range of colours with a few carefully
14
+ # chosen values.
15
+ class TermColor
16
+ def initialize
17
+ @decoration_scope = []
18
+ end
19
+
20
+ def decorate(text, *args)
21
+ decoration_scope.push(*args)
22
+ return_decorator(text)
23
+ end
24
+
25
+ def bold(text=nil)
26
+ decoration_scope.push(:bold)
27
+ return_decorator(text)
28
+ end
29
+
30
+ def red(text=nil)
31
+ decoration_scope.push(:red)
32
+ return_decorator(text)
33
+ end
34
+
35
+ def green(text)
36
+ decoration_scope.push(:green)
37
+ return_decorator(text)
38
+ end
39
+
40
+ def blue(text)
41
+ decoration_scope.push(:blue)
42
+ return_decorator(text)
43
+ end
44
+
45
+ def yellow(text)
46
+ decoration_scope.push(:yellow)
47
+ return_decorator(text)
48
+ end
49
+
50
+ def cyan(text)
51
+ decoration_scope.push(:cyan)
52
+ return_decorator(text)
53
+ end
54
+
55
+ def orange(text)
56
+ decoration_scope.push('orange')
57
+ return_decorator(text)
58
+ end
59
+
60
+ def brown(text)
61
+ decoration_scope.push('tan')
62
+ return_decorator(text)
63
+ end
64
+
65
+ private
66
+
67
+ attr_reader :decoration_scope
68
+
69
+ def return_decorator(text)
70
+ if text.nil?
71
+ self
72
+ else
73
+ decorated = Paint[text, *decoration_scope]
74
+ decoration_scope.clear
75
+ decorated
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,3 +1,3 @@
1
1
  module Intent
2
- VERSION = '0.7.0'
2
+ VERSION = '0.7.1'
3
3
  end
data/lib/intent.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  #require 'random'
2
2
  require 'todo-txt'
3
3
  require 'pastel'
4
+ require 'paint'
4
5
  require 'tty-prompt'
5
6
  require 'tty-table'
6
7
  require 'tty-tree'
@@ -14,6 +15,7 @@ end
14
15
  require 'intent/version'
15
16
  require 'intent/core'
16
17
  require 'intent/commands'
18
+ require 'intent/ui/term_color'
17
19
  # require 'intent/todo'
18
20
  # require 'intent/review'
19
21
  # require 'intent/projects'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rickerby
@@ -206,6 +206,20 @@ dependencies:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
208
  version: 2.0.0
209
+ - !ruby/object:Gem::Dependency
210
+ name: paint
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: 2.3.0
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: 2.3.0
209
223
  - !ruby/object:Gem::Dependency
210
224
  name: bundler
211
225
  requirement: !ruby/object:Gem::Requirement
@@ -293,6 +307,7 @@ files:
293
307
  - lib/intent/text/projects.help.txt
294
308
  - lib/intent/text/todo.help.txt
295
309
  - lib/intent/todo.rb
310
+ - lib/intent/ui/term_color.rb
296
311
  - lib/intent/ui/ttyui.rb
297
312
  - lib/intent/verbs/add.rb
298
313
  - lib/intent/verbs/cite.rb