howzit 1.2.5 → 1.2.6

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: 5f2fa88b6f75dba8846894028f457fa1515d104bb41c77307bd0b22835afeed8
4
- data.tar.gz: 64a7169ae4968d94f0193d784924a6a36bf36d3389cefdd8dc15a1d916292548
3
+ metadata.gz: ca091b1137f05559c0e53738d8cf283e3e301bbd434b3241a54592ded4aac39a
4
+ data.tar.gz: 99f0a601a6d2655954da642621df18573f15bcefe44ccb458b3ef61f397ec92b
5
5
  SHA512:
6
- metadata.gz: 52e107f32837a775c115a9f2051a8347458e9194972f36fd1af42888e70d567ddc48bc51411335ad037d497c0d86abe38171f7b1064945c7b77671cb4a7a3afb
7
- data.tar.gz: 9c67de8ad8748e365753194d59f4cbc1a73a590f0291289ab20e1558077114d531fe3b6b957d38204dfaace53e7d5e84a2c4743ee3ae33d4fa160828d97478fb
6
+ metadata.gz: 24215ee9b271df785dedee31da6f2bf3ecbc4be69231635ee0d77a6e9a76b5fa1507e4125ee9b896cc15559842d7546302f25a789b726a87a7a4a3531a6a49bf
7
+ data.tar.gz: a1754b95775992055ba92a294215bc9680e296f932cf2d2664a0e00e9d5442742469ac2f51e8acd741f788b49a9b39053083c4cd0d271d7aa2db167394fb343e
data/README.md CHANGED
@@ -2,10 +2,6 @@
2
2
 
3
3
  [![Gem](https://img.shields.io/gem/v/howzit.svg)](https://rubygems.org/gems/howzit)
4
4
  [![GitHub license](https://img.shields.io/github/license/ttscoff/howzit.svg)](./LICENSE.txt)
5
- [![Gemnasium](https://img.shields.io/gemnasium/ttscoff/howzit.svg)](https://gemnasium.com/ttscoff/howzit)
6
- [![Travis](https://img.shields.io/travis/ttscoff/howzit.svg)](https://travis-ci.org/ttscoff/howzit)
7
- [![Codecov](https://img.shields.io/codecov/c/github/ttscoff/howzit.svg)](https://codecov.io/github/ttscoff/howzit)
8
- [![Code Climate](https://img.shields.io/codeclimate/github/ttscoff/howzit.svg)](https://codeclimate.com/github/ttscoff/howzit)
9
5
 
10
6
  A command-line reference tool for tracking project build systems
11
7
 
data/howzit.gemspec CHANGED
@@ -39,4 +39,5 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency 'github-markup', '~> 1.3'
40
40
 
41
41
  spec.add_runtime_dependency 'mdless', '~> 1.0', '>= 1.0.28'
42
+ spec.add_runtime_dependency 'tty-screen', '~> 0.8'
42
43
  end
@@ -1,6 +1,8 @@
1
1
  module Howzit
2
2
  # Primary Class for this module
3
3
  class BuildNotes
4
+ include Prompt
5
+
4
6
  attr_accessor :arguments, :metadata
5
7
 
6
8
  def topics
@@ -108,7 +110,6 @@ module Howzit
108
110
  options = {
109
111
  color: true,
110
112
  highlight: false,
111
- paginate: false,
112
113
  wrap: 0
113
114
  }
114
115
 
@@ -124,14 +125,17 @@ module Howzit
124
125
 
125
126
  output = `echo #{Shellwords.escape(string.strip)}#{pipes}`
126
127
 
127
- if options[:paginate]
128
+ if @options[:paginate]
128
129
  page(output)
129
130
  else
130
- output.gsub!(/^╌/, '\e]1337;SetMark\a╌') if ENV['TERM_PROGRAM'] =~ /^iTerm/ && !options[:run]
131
131
  puts output
132
132
  end
133
133
  end
134
134
 
135
+ def iterm_marker
136
+ "\e]1337;SetMark\a\n" if ENV['TERM_PROGRAM'] =~ /^iTerm/ && !@options[:run] && !@options[:paginate]
137
+ end
138
+
135
139
  def color_single_options(choices = %w[y n])
136
140
  out = []
137
141
  choices.each do |choice|
@@ -153,16 +157,9 @@ module Howzit
153
157
  end
154
158
  # First make sure there isn't already a buildnotes file
155
159
  if note_file
156
- system 'stty cbreak'
157
160
  fname = "\e[1;33m#{note_file}\e[1;37m"
158
- yn = color_single_options(%w[y N])
159
- $stdout.syswrite "#{fname} exists and appears to be a build note, continue anyway #{yn}\e[1;37m? \e[0m"
160
- res = $stdin.sysread 1
161
- res.chomp!
162
- puts
163
- system 'stty cooked'
164
-
165
- unless res =~ /y/i
161
+ res = yn("#{fname} exists and appears to be a build note, continue anyway?", false)
162
+ unless res
166
163
  puts 'Canceled'
167
164
  Process.exit 0
168
165
  end
@@ -209,16 +206,10 @@ module Howzit
209
206
  EOBUILDNOTES
210
207
 
211
208
  if File.exist?(filename)
212
- system 'stty cbreak'
213
- yn = color_single_options(%w[y N])
214
209
  file = "\e[1;33m#{filename}"
215
- $stdout.syswrite "\e[1;37mAre you absolutely sure you want to overwrite #{file} #{yn}\e[1;37m? \e[0m"
216
- res = $stdin.sysread 1
217
- res.chomp!
218
- puts
219
- system 'stty cooked'
210
+ res = yn("Are you absolutely sure you want to overwrite #{file}", false)
220
211
 
221
- unless res =~ /y/i
212
+ unless res
222
213
  puts 'Canceled'
223
214
  Process.exit 0
224
215
  end
@@ -240,11 +231,11 @@ module Howzit
240
231
 
241
232
  options.merge!(opts)
242
233
 
243
- cols = `tput cols`.strip.to_i
234
+ cols = TTY::Screen.columns
244
235
  cols = @options[:wrap] if (@options[:wrap]).positive? && cols > @options[:wrap]
245
236
  title = "\e[#{options[:border]}m#{options[:hr]}#{options[:hr]}( \e[#{options[:color]}m#{title}\e[#{options[:border]}m )"
246
237
  tail = options[:hr] * (cols - title.uncolor.length)
247
- "#{title}#{tail}\e[0m"
238
+ options[:hr] =~ /╌/ ? "#{iterm_marker}#{title}#{tail}\e[0m" : "#{title}#{tail}\e[0m"
248
239
  end
249
240
 
250
241
  def os_open(command)
@@ -283,6 +274,15 @@ module Howzit
283
274
  output = []
284
275
  tasks = 0
285
276
  if topics[key] =~ /(@(include|run|copy|open|url)\((.*?)\)|`{3,}run)/i
277
+ prereqs = topics[key].scan(/(?<=@before\n).*?(?=\n@end)/im).map(&:strip)
278
+ postreqs = topics[key].scan(/(?<=@after\n).*?(?=\n@end)/im).map(&:strip)
279
+
280
+ unless prereqs.empty?
281
+ puts prereqs.join("\n\n")
282
+ res = yn('This task has prerequisites, have they been met?', true)
283
+ Process.exit 1 unless res
284
+
285
+ end
286
286
  directives = topics[key].scan(/(?:@(include|run|copy|open|url)\((.*?)\)|(`{3,})run(?: +([^\n]+))?(.*?)\3)/mi)
287
287
 
288
288
  tasks += directives.length
@@ -333,6 +333,8 @@ module Howzit
333
333
  warn "\e[0;31m--run: No \e[1;31m@directive\e[0;31;40m found in \e[1;37m#{key}\e[0m"
334
334
  end
335
335
  output.push("Ran #{tasks} #{tasks == 1 ? 'task' : 'tasks'}") if @options[:log_level] < 2
336
+
337
+ puts postreqs.join("\n\n")
336
338
  end
337
339
 
338
340
  # Output a topic with fancy title and bright white text.
@@ -349,6 +351,8 @@ module Howzit
349
351
  topic.gsub!(/(?mi)^(`{3,})run *([^\n]*)[\s\S]*?\n\1\s*$/, '@@@run \2') unless @options[:show_all_code]
350
352
  topic.split(/\n/).each do |l|
351
353
  case l
354
+ when /@(before|after|prereq|end)/
355
+ next
352
356
  when /@include\((.*?)\)/
353
357
 
354
358
  m = Regexp.last_match
@@ -837,14 +841,9 @@ module Howzit
837
841
  raise 'No EDITOR variable defined in environment' if ENV['EDITOR'].nil?
838
842
 
839
843
  if note_file.nil?
840
- system 'stty cbreak'
841
- yn = color_single_options(%w[Y n])
842
- $stdout.syswrite "No build notes file found, create one #{yn}? "
843
- res = $stdin.sysread 1
844
- puts
845
- system 'stty cooked'
846
-
847
- create_note if res.chomp =~ /^y?$/i
844
+ res = yn("No build notes file found, create one?", true)
845
+
846
+ create_note if res
848
847
  edit_note
849
848
  else
850
849
  `#{ENV['EDITOR']} "#{note_file}"`
@@ -1064,14 +1063,8 @@ module Howzit
1064
1063
  ARGV.length.times do
1065
1064
  ARGV.shift
1066
1065
  end
1067
- system 'stty cbreak'
1068
- yn = color_single_options(%w[Y n])
1069
- $stdout.syswrite "No build notes file found, create one #{yn}? "
1070
- res = $stdin.sysread 1
1071
- puts
1072
- system 'stty cooked'
1073
-
1074
- create_note if res.chomp =~ /^y?$/i
1066
+ res = yn("No build notes file found, create one?", true)
1067
+ create_note if res
1075
1068
  Process.exit 1
1076
1069
  end
1077
1070
 
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Howzit
4
+ module Prompt
5
+ def yn(prompt, default = true)
6
+ system 'stty cbreak'
7
+ yn = color_single_options(default ? %w[Y n] : %w[y N])
8
+ $stdout.syswrite "\e[1;37m#{prompt} #{yn}\e[1;37m? \e[0m"
9
+ res = $stdin.sysread 1
10
+ res.chomp!
11
+ puts
12
+ system 'stty cooked'
13
+ res =~ /y/i
14
+ end
15
+ end
16
+ end
@@ -5,7 +5,7 @@ module Howzit
5
5
  module StringUtils
6
6
  # Just strip out color codes when requested
7
7
  def uncolor
8
- gsub(/\e\[[\d;]+m/, '')
8
+ gsub(/\e\[[\d;]+m/, '').gsub(/\e]1337;SetMark/,'')
9
9
  end
10
10
 
11
11
  # Adapted from https://github.com/pazdera/word_wrap/,
@@ -2,5 +2,5 @@
2
2
  # Primary module for this gem.
3
3
  module Howzit
4
4
  # Current Howzit version.
5
- VERSION = '1.2.5'.freeze
5
+ VERSION = '1.2.6'.freeze
6
6
  end
data/lib/howzit.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'howzit/version'
2
+ require 'howzit/prompt'
2
3
  require 'howzit/buildnotes'
3
4
  require 'howzit/stringutils'
4
5
  require 'optparse'
@@ -8,6 +9,8 @@ require 'readline'
8
9
  require 'tempfile'
9
10
  require 'yaml'
10
11
 
12
+ require 'tty/screen'
13
+
11
14
  CONFIG_DIR = '~/.config/howzit'
12
15
  CONFIG_FILE = 'howzit.yaml'
13
16
  IGNORE_FILE = 'ignore.yaml'
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: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
@@ -240,6 +240,20 @@ dependencies:
240
240
  - - ">="
241
241
  - !ruby/object:Gem::Version
242
242
  version: 1.0.28
243
+ - !ruby/object:Gem::Dependency
244
+ name: tty-screen
245
+ requirement: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - "~>"
248
+ - !ruby/object:Gem::Version
249
+ version: '0.8'
250
+ type: :runtime
251
+ prerelease: false
252
+ version_requirements: !ruby/object:Gem::Requirement
253
+ requirements:
254
+ - - "~>"
255
+ - !ruby/object:Gem::Version
256
+ version: '0.8'
243
257
  description: Command line project documentation and task runner
244
258
  email:
245
259
  - me@brettterpstra.com
@@ -269,6 +283,7 @@ files:
269
283
  - lib/.rubocop.yml
270
284
  - lib/howzit.rb
271
285
  - lib/howzit/buildnotes.rb
286
+ - lib/howzit/prompt.rb
272
287
  - lib/howzit/stringutils.rb
273
288
  - lib/howzit/version.rb
274
289
  - spec/.rubocop.yml