howzit 2.0.24 → 2.0.27

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: 4d5ddc7a4ec5cda133517d27dfef17d80299c17a68de2469e9dab66e81dffa33
4
- data.tar.gz: 78fed9d51d054f4c39d3bb6b9daed3709e6a7f7644e5a6368bb924bb0b042665
3
+ metadata.gz: 135c2149bfce9fb01705564408ded6052edef780b415d1b305e292c6d3701f57
4
+ data.tar.gz: c4cfbbd4a6517aa33078c69600f88656ec4c07547c5ff6dcc65cae1151feb47a
5
5
  SHA512:
6
- metadata.gz: 5427a3f6754462ae1311194407a3c6dfc71b084bb639afa29d961fad758ed554ce40ccdb21ec7b9175289343866da6d1ddb0f9db5fccb12f8224d206f9d53b98
7
- data.tar.gz: 6222c4a34783c842fc342a27b2167588578afefa3f45a2fc16637b5d3f266d99d11bbefada5dd4a586902f914566a86efcef4262396133e573cf520923cd468a
6
+ metadata.gz: 3981a7b2eba17397a7e7723105a7f80f7387b04d3a2fabc442fe63a7c27fa79d954801c4527f2168cb557c16e7da865228d8ffb5f7bff55c754c5623010390f6
7
+ data.tar.gz: 8cee197d4b84557bddcc5d2584c4784af88ade9424c06cf73d2efdd8735e7675db711d20cfcb98efc91fcb722d91b464aa8a45fa85e0c5c1dd8e8509100460e2
data/.travis.yml CHANGED
@@ -14,3 +14,4 @@ script: "bundle exec rspec spec --exclude-pattern 'cli*'"
14
14
  branches:
15
15
  only:
16
16
  - main
17
+ - develop
data/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ ### 2.0.27
2
+
3
+ 2022-08-23 12:25
4
+
5
+ #### IMPROVED
6
+
7
+ - Code cleanup
8
+
9
+ ### 2.0.26
10
+
11
+ 2022-08-23 11:36
12
+
13
+ #### IMPROVED
14
+
15
+ - Add ctrl-a/d bindings to fzf menu for select/deselect all
16
+
17
+ ### 2.0.25
18
+
19
+ 2022-08-09 12:46
20
+
21
+ #### FIXED
22
+
23
+ - Template metadata inheritence
24
+
1
25
  ### 2.0.24
2
26
 
3
27
  2022-08-09 09:04
@@ -12,7 +12,7 @@ module Howzit
12
12
  ##
13
13
  ## @param file [String] The path to the build note file
14
14
  ##
15
- def initialize(file: nil)
15
+ def initialize(file: nil, meta: nil)
16
16
  file ||= note_file
17
17
 
18
18
  @topics = []
@@ -21,7 +21,9 @@ module Howzit
21
21
  content = Util.read_file(file)
22
22
  raise "{br}No content found in build note (#{file}){x}".c if content.nil? || content.empty?
23
23
 
24
- @metadata = content.split(/^#/)[0].strip.get_metadata
24
+ this_meta = content.split(/^#/)[0].strip.get_metadata
25
+
26
+ @metadata = meta.nil? ? this_meta : meta.merge(this_meta)
25
27
 
26
28
  read_help(file)
27
29
  end
@@ -451,11 +453,12 @@ module Howzit
451
453
  ## @return [Array] extracted topics
452
454
  ##
453
455
  def read_template(template, file, subtopics = nil)
454
- note = BuildNote.new(file: file)
456
+ note = BuildNote.new(file: file, meta: @metadata)
455
457
 
456
458
  template_topics = subtopics.nil? ? note.topics : extract_subtopics(note, subtopics)
457
459
  template_topics.map do |topic|
458
460
  topic.parent = template
461
+ topic.content = topic.content.render_template(@metadata)
459
462
  topic
460
463
  end
461
464
  end
@@ -607,6 +610,7 @@ module Howzit
607
610
  end
608
611
  title = "#{short_path}:#{title}"
609
612
  end
613
+
610
614
  topic = Topic.new(title, prefix + lines.join("\n").strip.render_template(@metadata))
611
615
 
612
616
  topics.push(topic)
data/lib/howzit/prompt.rb CHANGED
@@ -87,59 +87,86 @@ module Howzit
87
87
  return [] if !$stdout.isatty || matches.count.zero?
88
88
 
89
89
  if Util.command_exist?('fzf')
90
- height = if height == :auto
91
- matches.count + 3
92
- else
93
- TTY::Screen.rows
94
- end
95
-
96
- settings = [
97
- '-0',
98
- '-1',
99
- '-m',
100
- "--height=#{height}",
101
- '--header="Use tab to mark multiple selections, enter to display/run"',
102
- '--prompt="Select a section > "',
103
- %(--preview="howzit --no-pager --header-format block --no-color --default --multiple first {}")
104
- ]
90
+ height = height == :auto ? matches.count + 3 : TTY::Screen.rows
91
+
92
+ settings = fzf_options(height)
105
93
  res = `echo #{Shellwords.escape(matches.join("\n"))} | fzf #{settings.join(' ')}`.strip
106
- if res.nil? || res.empty?
107
- Howzit.console.info 'Cancelled'
108
- Process.exit 0
109
- end
110
- return res.split(/\n/)
94
+ return fzf_result(res)
95
+ end
96
+
97
+ tty_menu(matches)
98
+ end
99
+
100
+ def fzf_result(res)
101
+ if res.nil? || res.empty?
102
+ Howzit.console.info 'Cancelled'
103
+ Process.exit 0
111
104
  end
105
+ return res.split(/\n/)
106
+ end
107
+
108
+ def fzf_options(height)
109
+ [
110
+ '-0',
111
+ '-1',
112
+ '-m',
113
+ "--height=#{height}",
114
+ '--header="Tab: add selection, ctrl-a/d: (de)select all, return: display/run"',
115
+ '--bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all',
116
+ '--prompt="Select a topic > "',
117
+ %(--preview="howzit --no-pager --header-format block --no-color --default --multiple first {}")
118
+ ]
119
+ end
112
120
 
121
+ ##
122
+ ## Display a numeric menu on the TTY
123
+ ##
124
+ ## @param matches The matches from which to select
125
+ ##
126
+ def tty_menu(matches)
113
127
  return matches if matches.count == 1
114
128
 
115
- res = matches[0..9]
116
- stty_save = `stty -g`.chomp
129
+ @stty_save = `stty -g`.chomp
117
130
 
118
131
  trap('INT') do
119
- system('stty', stty_save)
132
+ system('stty')
120
133
  exit
121
134
  end
122
135
 
123
136
  options_list(matches)
137
+ read_selection(matches)
138
+ end
124
139
 
125
- begin
126
- printf("Type 'q' to cancel, enter for first item", res.length)
127
- while (line = Readline.readline(': ', true))
128
- if line =~ /^[a-z]/i
129
- system('stty', stty_save) # Restore
130
- exit
131
- end
132
- line = line == '' ? 1 : line.to_i
140
+ ##
141
+ ## Read a single number response from the command line
142
+ ##
143
+ ## @param matches The matches
144
+ ##
145
+ def read_selection(matches)
146
+ printf "Type 'q' to cancel, enter for first item"
147
+ while (line = Readline.readline(': ', true))
148
+ line = read_num(line)
133
149
 
134
- return [matches[line - 1]] if line.positive? && line <= matches.length
150
+ return [matches[line - 1]] if line.positive? && line <= matches.length
135
151
 
136
- puts 'Out of range'
137
- options_list(matches)
138
- end
139
- ensure
140
- system('stty', stty_save)
152
+ puts 'Out of range'
153
+ read_selection(matches)
154
+ end
155
+ ensure
156
+ system('stty', @stty_save)
157
+ end
158
+
159
+ ##
160
+ ## Convert a response to an Integer
161
+ ##
162
+ ## @param line The response to convert
163
+ ##
164
+ def read_num(line)
165
+ if line =~ /^[a-z]/i
166
+ system('stty', @stty_save) # Restore
141
167
  exit
142
168
  end
169
+ line == '' ? 1 : line.to_i
143
170
  end
144
171
  end
145
172
  end
@@ -3,5 +3,5 @@
3
3
  # Primary module for this gem.
4
4
  module Howzit
5
5
  # Current Howzit version.
6
- VERSION = '2.0.24'
6
+ VERSION = '2.0.27'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: howzit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.24
4
+ version: 2.0.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-09 00:00:00.000000000 Z
11
+ date: 2022-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler