howzit 2.0.14 → 2.0.15

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: a4ce43666235573b6b74c77d0dcb6e1f4c1a45fb8b9cd516747698f56cc3723d
4
- data.tar.gz: c13702a3d4b7b2ad707890d3f9d8c2a75e92fba1c732689f1930b511254db742
3
+ metadata.gz: bb673909d87ac094a2111c1f6fa364fb54183059267e009886562c89a81310d7
4
+ data.tar.gz: ec766bf5d2f3b3454a289f429e28c12f19545a79dfe6f10d29f0afb04abdc9b2
5
5
  SHA512:
6
- metadata.gz: 586fcb6d9e5bfd901a3e4d33ff9044c57ae50a97cb0a19e8c2d9e5b57dec6771b432e0dc83e28a924824cc04a758ce4397d0f74b7efb2d343181c262f92c636b
7
- data.tar.gz: 5f0eac9f6e53ed64ea159630e0f979f9cc8d8734b95186316b924e1e75e752b7a189d02eb1c178c15050676988356b391cfbc19f3da9eacb61d21051b474188e
6
+ metadata.gz: b5f2e3624bad256848b1c2d8a4bc95dcbbee5d8cf0e2c63efa79b139ca3a330ce773edb2e68375ea72158de0ce69ffaedd7673f36cbee5cd937c255ccaa3e5fe
7
+ data.tar.gz: f024cd0ffb6b41ab6184cf36ef65e644e90f5ab7e5c57b8a2c9cc1be404802f992f708464a3a2ab984122fddb4880ec704cda85dd371aeee735b417e15d942c2
data/.travis.yml CHANGED
@@ -13,4 +13,4 @@ install:
13
13
  script: "bundle exec rspec spec --exclude-pattern 'cli*'"
14
14
  branches:
15
15
  only:
16
- - master
16
+ - main
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ### 2.0.15
2
+
3
+ 2022-08-05 17:16
4
+
5
+ #### IMPROVED
6
+
7
+ - -R can take an argument to filter results
8
+ - Show a topic preview when using fzf to select from available topics
9
+ - Paginate help output
10
+ - Refactor Topic.run
11
+
12
+ #### FIXED
13
+
14
+ - Invalid options for more pager
15
+ - Error running grep command
16
+ - Show method not accepting paginate option
17
+
1
18
  ### 2.0.14
2
19
 
3
20
  2022-08-05 13:24
data/bin/howzit CHANGED
@@ -49,7 +49,8 @@ OptionParser.new do |opts|
49
49
  Howzit.options[:list_topics] = true
50
50
  end
51
51
 
52
- opts.on('-R', '--list-runnable', 'List topics containing @ directives (verbose)') do
52
+ opts.on('-R', '--list-runnable [PATTERN]', 'List topics containing @ directives (verbose)') do |pat|
53
+ Howzit.options[:for_topic] = pat
53
54
  Howzit.options[:list_runnable] = true
54
55
  end
55
56
 
@@ -201,7 +202,7 @@ OptionParser.new do |opts|
201
202
  opts.separator("\n Misc:\n\n") #=================================================================== MISC
202
203
 
203
204
  opts.on('-h', '--help', 'Display this screen') do
204
- puts opts
205
+ Howzit::Util.page opts.to_s
205
206
  Process.exit 0
206
207
  end
207
208
 
@@ -32,6 +32,11 @@ module Howzit
32
32
  read_help(file)
33
33
  end
34
34
 
35
+ ##
36
+ ## Inspect
37
+ ##
38
+ ## @return description
39
+ ##
35
40
  def inspect
36
41
  puts "#<Howzit::BuildNote @topics=[#{@topics.count}]>"
37
42
  end
@@ -55,7 +60,8 @@ module Howzit
55
60
  ##
56
61
  ## @param term [String] The search term
57
62
  ##
58
- def find_topic(term)
63
+ def find_topic(term = nil)
64
+ return @topics if term.nil?
59
65
  @topics.filter do |topic|
60
66
  rx = term.to_rx
61
67
  topic.title.downcase =~ rx
@@ -127,7 +133,8 @@ module Howzit
127
133
  def list_runnable
128
134
  output = []
129
135
  output.push(%({bg}"Runnable" Topics:{x}\n).c)
130
- @topics.each do |topic|
136
+
137
+ find_topic(Howzit.options[:for_topic]).each do |topic|
131
138
  s_out = []
132
139
 
133
140
  topic.tasks.each do |task|
@@ -243,6 +250,11 @@ module Howzit
243
250
  Process.exit 0
244
251
  end
245
252
 
253
+ ##
254
+ ## Accessor method for note_file (path to located build note)
255
+ ##
256
+ ## @return [String] path
257
+ ##
246
258
  def note_file
247
259
  @note_file ||= find_note_file
248
260
  end
@@ -581,7 +593,7 @@ module Howzit
581
593
  ARGV.length.times do
582
594
  ARGV.shift
583
595
  end
584
- res = yn("No build notes file found, create one?", true)
596
+ res = yn("No build notes file found, create one?", false)
585
597
  create_note if res
586
598
  Process.exit 1
587
599
  end
@@ -620,15 +632,15 @@ module Howzit
620
632
 
621
633
  topic_matches = []
622
634
  if Howzit.options[:grep]
623
- matches = grep_topics(Howzit.options[:grep])
635
+ matches = grep(Howzit.options[:grep])
624
636
  case Howzit.options[:multiple_matches]
625
637
  when :all
626
- topic_matches.concat(matches.sort)
638
+ topic_matches.concat(matches.sort_by(&:title))
627
639
  else
628
- topic_matches.concat(Prompt.choose(matches))
640
+ topic_matches.concat(Prompt.choose(matches.map(&:title), height: :max))
629
641
  end
630
642
  elsif Howzit.options[:choose]
631
- titles = Prompt.choose(list_topics)
643
+ titles = Prompt.choose(list_topics, height: :max)
632
644
  titles.each { |title| topic_matches.push(find_topic(title)[0]) }
633
645
  # If there are arguments use those to search for a matching topic
634
646
  elsif !Howzit.cli_args.empty?
data/lib/howzit/colors.rb CHANGED
@@ -243,6 +243,7 @@ module Howzit
243
243
 
244
244
  ATTRIBUTES.each do |c, v|
245
245
  new_method = <<-EOSCRIPT
246
+ # Color string as #{c}
246
247
  def #{c}(string = nil)
247
248
  result = ''
248
249
  result << "\e[#{v}m" if Howzit::Color.coloring?
@@ -266,6 +267,7 @@ module Howzit
266
267
 
267
268
  # Accept brightwhite in addition to boldwhite
268
269
  new_method = <<-EOSCRIPT
270
+ # color string as #{c}
269
271
  def #{c.to_s.sub(/bold/, 'bright')}(string = nil)
270
272
  result = ''
271
273
  result << "\e[#{v}m" if Howzit::Color.coloring?
@@ -286,6 +288,13 @@ module Howzit
286
288
  module_eval(new_method)
287
289
  end
288
290
 
291
+ ##
292
+ ## Generate escape codes for hex colors
293
+ ##
294
+ ## @param hex [String] The hexadecimal color code
295
+ ##
296
+ ## @return [String] ANSI escape string
297
+ ##
289
298
  def rgb(hex)
290
299
  is_bg = hex.match(/^bg?#/) ? true : false
291
300
  hex_string = hex.sub(/^([fb]g?)?#/, '')
data/lib/howzit/config.rb CHANGED
@@ -89,6 +89,7 @@ module Howzit
89
89
  flags = {
90
90
  choose: false,
91
91
  default: false,
92
+ for_topic: nil,
92
93
  grep: nil,
93
94
  list_runnable: false,
94
95
  list_runnable_titles: false,
data/lib/howzit/prompt.rb CHANGED
@@ -78,15 +78,21 @@ module Howzit
78
78
  ##
79
79
  ## @return [Array] the selected results
80
80
  ##
81
- def choose(matches)
81
+ def choose(matches, height: :auto)
82
+ height = if height == :auto
83
+ matches.count + 3
84
+ else
85
+ TTY::Screen.rows
86
+ end
82
87
  if Util.command_exist?('fzf')
83
88
  settings = [
84
89
  '-0',
85
90
  '-1',
86
91
  '-m',
87
- "--height=#{matches.count + 3}",
92
+ "--height=#{height}",
88
93
  '--header="Use tab to mark multiple selections, enter to display/run"',
89
- '--prompt="Select a section > "'
94
+ '--prompt="Select a section > "',
95
+ '--preview="howzit {}"'
90
96
  ]
91
97
  res = `echo #{Shellwords.escape(matches.join("\n"))} | fzf #{settings.join(' ')}`.strip
92
98
  if res.nil? || res.empty?
data/lib/howzit/task.rb CHANGED
@@ -17,14 +17,160 @@ module Howzit
17
17
  @default = default
18
18
  end
19
19
 
20
+ ##
21
+ ## Inspect
22
+ ##
23
+ ## @return [String] description
24
+ ##
20
25
  def inspect
21
26
  %(<#Howzit::Task @type=:#{@type} @title="#{@title}" @block?=#{@action.split(/\n/).count > 1}>)
22
27
  end
23
28
 
29
+ ##
30
+ ## Output string representation
31
+ ##
32
+ ## @return [String] string representation of the object.
33
+ ##
24
34
  def to_s
25
35
  @title
26
36
  end
27
37
 
38
+ ##
39
+ ## Execute a block type
40
+ ##
41
+ def run_block
42
+ Howzit.console.info "{bg}Running block {bw}#{@title}{x}".c if Howzit.options[:log_level] < 2
43
+ block = @action
44
+ script = Tempfile.new('howzit_script')
45
+ begin
46
+ script.write(block)
47
+ script.close
48
+ File.chmod(0o777, script.path)
49
+ system(%(/bin/sh -c "#{script.path}"))
50
+ ensure
51
+ script.close
52
+ script.unlink
53
+ end
54
+ end
55
+
56
+ ##
57
+ ## Execute an include task
58
+ ##
59
+ ## @return [Integer] number of tasks executed
60
+ ##
61
+ def run_include
62
+ output = []
63
+ matches = Howzit.buildnote.find_topic(@action)
64
+ raise "Topic not found: #{@action}" if matches.empty?
65
+
66
+ $stderr.puts "{by}Running tasks from {bw}#{matches[0].title}{x}".c if Howzit.options[:log_level] < 2
67
+ output.concat(matches[0].run(nested: true))
68
+ $stderr.puts "{by}End include: #{matches[0].tasks.count} tasks{x}".c if Howzit.options[:log_level] < 2
69
+ [output, matches[0].tasks.count]
70
+ end
71
+
72
+ ##
73
+ ## Execute a run task
74
+ ##
75
+ def run_run
76
+ title = Howzit.options[:show_all_code] ? @action : @title
77
+ $stderr.puts "{bg}Running {bw}#{title}{x}".c if Howzit.options[:log_level] < 2
78
+ system(@action)
79
+ end
80
+
81
+ ##
82
+ ## Execute a copy task
83
+ ##
84
+ def run_copy
85
+ title = Howzit.options[:show_all_code] ? @action : @title
86
+ $stderr.puts "{bg}Copied {bw}#{title}{bg} to clipboard{x}".c if Howzit.options[:log_level] < 2
87
+ os_copy(@action)
88
+ end
89
+
90
+ ##
91
+ ## Platform-agnostic copy-to-clipboard
92
+ ##
93
+ ## @param string [String] The string to copy
94
+ ##
95
+ def os_copy(string)
96
+ os = RbConfig::CONFIG['target_os']
97
+ out = "{bg}Copying {bw}#{string}".c
98
+ case os
99
+ when /darwin.*/i
100
+ $stderr.puts "#{out} (macOS){x}".c if Howzit.options[:log_level].zero?
101
+ `echo #{Shellwords.escape(string)}'\\c'|pbcopy`
102
+ when /mingw|mswin/i
103
+ $stderr.puts "#{out} (Windows){x}".c if Howzit.options[:log_level].zero?
104
+ `echo #{Shellwords.escape(string)} | clip`
105
+ else
106
+ if 'xsel'.available?
107
+ $stderr.puts "#{out} (Linux, xsel){x}".c if Howzit.options[:log_level].zero?
108
+ `echo #{Shellwords.escape(string)}'\\c'|xsel -i`
109
+ elsif 'xclip'.available?
110
+ $stderr.puts "#{out} (Linux, xclip){x}".c if Howzit.options[:log_level].zero?
111
+ `echo #{Shellwords.escape(string)}'\\c'|xclip -i`
112
+ else
113
+ $stderr.puts out if Howzit.options[:log_level].zero?
114
+ $stderr.puts 'Unable to determine executable for clipboard.'
115
+ end
116
+ end
117
+ end
118
+
119
+ ##
120
+ ## Platform-agnostic open command
121
+ ##
122
+ ## @param command [String] The command
123
+ ##
124
+ def os_open(command)
125
+ os = RbConfig::CONFIG['target_os']
126
+ out = "{bg}Opening {bw}#{command}".c
127
+ case os
128
+ when /darwin.*/i
129
+ Howzit.console.debug "#{out} (macOS){x}".c if Howzit.options[:log_level] < 2
130
+ `open #{Shellwords.escape(command)}`
131
+ when /mingw|mswin/i
132
+ Howzit.console.debug "#{out} (Windows){x}".c if Howzit.options[:log_level] < 2
133
+ `start #{Shellwords.escape(command)}`
134
+ else
135
+ if 'xdg-open'.available?
136
+ Howzit.console.debug "#{out} (Linux){x}".c if Howzit.options[:log_level] < 2
137
+ `xdg-open #{Shellwords.escape(command)}`
138
+ else
139
+ Howzit.console.debug out if Howzit.options[:log_level] < 2
140
+ Howzit.console.debug 'Unable to determine executable for `open`.'
141
+ end
142
+ end
143
+ end
144
+
145
+ ##
146
+ ## Execute the task
147
+ ##
148
+ def run
149
+ output = []
150
+ tasks = 1
151
+ if @type == :block
152
+ run_block
153
+ else
154
+ case @type
155
+ when :include
156
+ output, tasks = run_include
157
+ when :run
158
+ run_run
159
+ when :copy
160
+ run_copy
161
+ when :open
162
+ os_open(@action)
163
+ end
164
+ end
165
+
166
+ [output, tasks]
167
+ end
168
+
169
+ ##
170
+ ## Output terminal-formatted list item
171
+ ##
172
+ ## @return [String] List representation of the object.
173
+ ##
28
174
  def to_list
29
175
  " * #{@type}: #{@title.preserve_escapes}"
30
176
  end
data/lib/howzit/topic.rb CHANGED
@@ -56,52 +56,16 @@ module Howzit
56
56
  task_count = Howzit.buildnote.find_topic(task.action)[0].tasks.count
57
57
  " (#{task_count} tasks)"
58
58
  else
59
- ""
59
+ ''
60
60
  end
61
61
  q = %({bg}#{task.type.to_s.capitalize} {xw}"{bw}#{task.title}{xw}"#{note}{x}).c
62
62
  res = Prompt.yn(q, default: task.default)
63
63
  next unless res
64
64
 
65
65
  end
66
-
67
- if task.type == :block
68
- Howzit.console.info "{bg}Running block {bw}#{title}{x}".c if Howzit.options[:log_level] < 2
69
- block = task.action
70
- script = Tempfile.new('howzit_script')
71
- begin
72
- script.write(block)
73
- script.close
74
- File.chmod(0777, script.path)
75
- system(%(/bin/sh -c "#{script.path}"))
76
- tasks += 1
77
- ensure
78
- script.close
79
- script.unlink
80
- end
81
- else
82
- title = Howzit.options[:show_all_code] ? task.action : task.title
83
- case task.type
84
- when :include
85
- matches = Howzit.buildnote.find_topic(task.action)
86
- raise "Topic not found: #{task.action}" if matches.empty?
87
-
88
- $stderr.puts "{by}Running tasks from {bw}#{matches[0].title}{x}".c if Howzit.options[:log_level] < 2
89
- output.push(matches[0].run(nested: true))
90
- $stderr.puts "{by}End include: #{matches[0].tasks.count} tasks{x}".c if Howzit.options[:log_level] < 2
91
- tasks += matches[0].tasks.count
92
- when :run
93
- $stderr.puts "{bg}Running {bw}#{title}{x}".c if Howzit.options[:log_level] < 2
94
- system(task.action)
95
- tasks += 1
96
- when :copy
97
- $stderr.puts "{bg}Copied {bw}#{title}{bg} to clipboard{x}".c if Howzit.options[:log_level] < 2
98
- os_copy(task.action)
99
- tasks += 1
100
- when :open
101
- os_open(task.action)
102
- tasks += 1
103
- end
104
- end
66
+ run_output, total = task.run
67
+ output.concat(run_output)
68
+ tasks += total
105
69
  end
106
70
  else
107
71
  Howzit.console.warn "{r}--run: No {br}@directive{xr} found in {bw}#{@title}{x}".c
@@ -113,61 +77,6 @@ module Howzit
113
77
  output
114
78
  end
115
79
 
116
- ##
117
- ## Platform-agnostic copy-to-clipboard
118
- ##
119
- ## @param string [String] The string to copy
120
- ##
121
- def os_copy(string)
122
- os = RbConfig::CONFIG['target_os']
123
- out = "{bg}Copying {bw}#{string}".c
124
- case os
125
- when /darwin.*/i
126
- $stderr.puts "#{out} (macOS){x}".c if Howzit.options[:log_level].zero?
127
- `echo #{Shellwords.escape(string)}'\\c'|pbcopy`
128
- when /mingw|mswin/i
129
- $stderr.puts "#{out} (Windows){x}".c if Howzit.options[:log_level].zero?
130
- `echo #{Shellwords.escape(string)} | clip`
131
- else
132
- if 'xsel'.available?
133
- $stderr.puts "#{out} (Linux, xsel){x}".c if Howzit.options[:log_level].zero?
134
- `echo #{Shellwords.escape(string)}'\\c'|xsel -i`
135
- elsif 'xclip'.available?
136
- $stderr.puts "#{out} (Linux, xclip){x}".c if Howzit.options[:log_level].zero?
137
- `echo #{Shellwords.escape(string)}'\\c'|xclip -i`
138
- else
139
- $stderr.puts out if Howzit.options[:log_level].zero?
140
- $stderr.puts 'Unable to determine executable for clipboard.'
141
- end
142
- end
143
- end
144
-
145
- ##
146
- ## Platform-agnostic open command
147
- ##
148
- ## @param command [String] The command
149
- ##
150
- def os_open(command)
151
- os = RbConfig::CONFIG['target_os']
152
- out = "{bg}Opening {bw}#{command}".c
153
- case os
154
- when /darwin.*/i
155
- Howzit.console.debug "#{out} (macOS){x}".c if Howzit.options[:log_level] < 2
156
- `open #{Shellwords.escape(command)}`
157
- when /mingw|mswin/i
158
- Howzit.console.debug "#{out} (Windows){x}".c if Howzit.options[:log_level] < 2
159
- `start #{Shellwords.escape(command)}`
160
- else
161
- if 'xdg-open'.available?
162
- Howzit.console.debug "#{out} (Linux){x}".c if Howzit.options[:log_level] < 2
163
- `xdg-open #{Shellwords.escape(command)}`
164
- else
165
- Howzit.console.debug out if Howzit.options[:log_level] < 2
166
- Howzit.console.debug 'Unable to determine executable for `open`.'
167
- end
168
- end
169
- end
170
-
171
80
  # Output a topic with fancy title and bright white text.
172
81
  #
173
82
  # @param options [Hash] The options
data/lib/howzit/util.rb CHANGED
@@ -4,7 +4,6 @@ module Howzit
4
4
  # Util class
5
5
  module Util
6
6
  class << self
7
-
8
7
  ##
9
8
  ## Read a file with UTF-8 encoding and
10
9
  ## leading/trailing whitespace removed
@@ -90,7 +89,7 @@ module Howzit
90
89
  args = case pg
91
90
  when 'delta'
92
91
  '--pager="less -FXr"'
93
- when /^(less|more)$/
92
+ when 'less'
94
93
  '-FXr'
95
94
  when 'bat'
96
95
  if Howzit.options[:highlight]
@@ -153,6 +152,7 @@ module Howzit
153
152
  options = {
154
153
  color: true,
155
154
  highlight: false,
155
+ paginate: true,
156
156
  wrap: 0
157
157
  }
158
158
 
@@ -168,7 +168,7 @@ module Howzit
168
168
 
169
169
  output = `echo #{Shellwords.escape(string.strip)}#{pipes}`.strip
170
170
 
171
- if Howzit.options[:paginate]
171
+ if options[:paginate] && Howzit.options[:paginate]
172
172
  page(output)
173
173
  else
174
174
  puts output
@@ -3,5 +3,5 @@
3
3
  # Primary module for this gem.
4
4
  module Howzit
5
5
  # Current Howzit version.
6
- VERSION = '2.0.14'
6
+ VERSION = '2.0.15'
7
7
  end
data/lib/howzit.rb CHANGED
@@ -55,18 +55,30 @@ module Howzit
55
55
  @config ||= Config.new
56
56
  end
57
57
 
58
+ ##
59
+ ## Array for tracking inclusions and avoiding duplicates in output
60
+ ##
58
61
  def inclusions
59
62
  @inclusions ||= []
60
63
  end
61
64
 
65
+ ##
66
+ ## Module storage for Howzit::Config.options
67
+ ##
62
68
  def options
63
69
  config.options
64
70
  end
65
71
 
72
+ ##
73
+ ## Module storage for buildnote
74
+ ##
66
75
  def buildnote
67
76
  @buildnote ||= BuildNote.new
68
77
  end
69
78
 
79
+ ##
80
+ ## Convenience method for logging with Howzit.console.warn, etc.
81
+ ##
70
82
  def console
71
83
  @console ||= Howzit::ConsoleLogger.new(options[:log_level])
72
84
  end
data/spec/task_spec.rb CHANGED
@@ -15,4 +15,10 @@ describe Howzit::Task do
15
15
  expect(task).to be_a Howzit::Task
16
16
  end
17
17
  end
18
+
19
+ describe ".to_s" do
20
+ it "outputs title string" do
21
+ expect(task.to_s).to match(/List Directory/)
22
+ end
23
+ end
18
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: howzit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.14
4
+ version: 2.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra