hilight 0.1.1 → 0.2.0

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: 4736b1b4d3d3b76d3bc84247936fe4bcd5762170273a62a8eed4a3d26de7a536
4
- data.tar.gz: 60c160a0d8b15ae91d032a9dfadc49f58b64fc9dc975d4e0df4a77804c621ba1
3
+ metadata.gz: d3881b5345185548a788caf2cab5d3a727b7d6edb201bfb62398f151dca7eebe
4
+ data.tar.gz: a6c71e1428bc23aced4111ad5248a3b08311cbf9bf4ff1e3fc0ea5eb84279abb
5
5
  SHA512:
6
- metadata.gz: ee465264b4e58ba135f55689fcdb356c8cc0bd1f141828f6d0e655a8fa45e128bcc4ac03885b2b1b8490385a673f67c6e8e44101cbf8377610235d1fed2ec764
7
- data.tar.gz: db78510a6651751aa354a3af7acf1352a3076b1c19b625dd32e8688579c9046c53d9af2daf9153479bdde0badd07fb11d68db8d2fb3f09740342bf04f87eaee1
6
+ metadata.gz: 0dc73e7b18911d93db9cc214412edfc47ccd577b905241dc3a9d56bd64d923fea79d87fa93c82a718f23b0a25cd6613ee4efcb12012e196e8705ca89e279b79f
7
+ data.tar.gz: d36ebd749b4f0edb62f2a517fc497dedc0d6ac67e1bd7d097ccc692eca2313610d78dbd7e9147e15fa804421891c44540cc3d3114ad009babd6ea731149b7b84
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hilight (0.1.1)
4
+ hilight (0.2.0)
5
5
  term-ansicolor
6
6
 
7
7
  GEM
data/Guardfile CHANGED
@@ -2,7 +2,7 @@ clearing :on
2
2
  directories [".", "tmp"]
3
3
 
4
4
  guard(:shell, timeout: 30) do
5
- watch("exe/hilight") { puts `ruby exe/hilight` }
5
+ watch("exe/hilight") { puts `ruby exe/hilight rspec -h` }
6
6
  end
7
7
 
8
8
  group :main, halt_on_fail: true do
@@ -13,7 +13,7 @@ group :main, halt_on_fail: true do
13
13
  watch(rspec.spec_helper) { rspec.spec_dir }
14
14
  watch(rspec.spec_support) { rspec.spec_dir }
15
15
  watch(rspec.spec_files)
16
-
16
+ watch('exe/hilight') { rspec.spec_dir }
17
17
  ruby = dsl.ruby
18
18
  dsl.watch_spec_files_for(ruby.lib_files)
19
19
  end
data/README.md CHANGED
@@ -100,3 +100,29 @@ Everyone interacting in the Hilight project’s codebases, issue trackers, chat
100
100
  }
101
101
  ]
102
102
  }```
103
+
104
+
105
+ (pick our input from cmd matching)
106
+ ->(input)->(select our pattern[])->(stringify input)
107
+ ->(add colors)->(stringify output)
108
+
109
+
110
+ ### Pattern selection / cmdline matching
111
+ filter => Struct[:filter_regexp, :selected_patterns]
112
+ .find(input_string) (patterns)
113
+
114
+
115
+ ### String IO Arch
116
+ pattern => Struct[:regexp, :replacement_pattern]
117
+ .transform(input_string) (String)
118
+ .transform_stream(IO) (IO)
119
+ .match?(input_string) (Boolean)
120
+
121
+ patterns => pattern[]
122
+ .transform(input_string, stop_on_first: false) (String)
123
+ .transform_stream(IO) (IO)
124
+
125
+ # major things to do
126
+ # remove need for termansi by wiring up my own color lambda's
127
+ # wire up themes via lamdas
128
+ # wire up loading (selective or otherwise) of a set of default hilight's
@@ -3,54 +3,53 @@
3
3
  require "hilight"
4
4
  require 'term/ansicolor'
5
5
  require 'open3'
6
+ require 'optparse'
6
7
 
7
8
  include Hilight #rubocop:disable all
9
+ def split_opts(array)
10
+ cmd_start_index = array.find_index { |e| !e.start_with? "-" }
11
+ return [[], array] if !cmd_start_index || cmd_start_index.zero?
8
12
 
9
- Filter = Struct.new(:cmd, :patterns)
10
-
11
- filters = [
12
- Filter["rspec", Patterns[[
13
- Pattern[/(?<green>\d+) examples, (?<red>\d+) failures, (?<yellow>\d+) pending/, '\k<green> examples, \k<red> failures, \k<yellow> pending'],
14
- Pattern[/(?<blue>\d+\.\d+)/, '\k<blue>'],
15
- Pattern[/\"(?<green>.*?)\"|\'(?<green>.*?)\'/, '\k<green>'],
16
- Pattern[/# (?<red>.*):(?<yellow>\d+)/, '\k<red>:\k<yellow>']
17
- ]]],
18
- Filter[/-h|--help|help/, Patterns[[
19
- Pattern[%r{(?<yellow>\B-{1,2}[\w-]+)|(?<blue>[\[\]\(\)\{\}\<\>])|(?<green>["'].*?["'])}, '\k<yellow>\k<blue>\k<green>']
20
- ]]],
21
- Filter["git", Patterns[[Pattern[/(?<green>'.*')|(?<blue>".*")/, '\k<green>\k<blue>']]]],
22
- Filter["ruby", Patterns[[
23
- Pattern[/(.*from |)(?<red>.*):(?<blue>\d+)(?::in )(?<yellow>`.*')/, '\k<red>\k<blue>\k<yellow>']
24
- ]]],
25
- Filter["default", Patterns[[
26
- Pattern[/(?<green>'.*')|(?<blue>".*")/, '\k<green>\k<blue>']
27
- ]]]
28
- ]
29
-
30
- Filter.define_method(:match?) do |string|
31
- case cmd
32
- when (String || Symbol) then (cmd.to_s == string.to_s)
33
- when Regexp then (cmd.match? string.to_s)
34
- else false
35
- end
13
+ [array[0..cmd_start_index - 1], array[cmd_start_index..-1]]
36
14
  end
37
15
 
38
- filters.define_singleton_method(:find) do |string|
39
- each { |f| return f if f.match? string }
40
- filters.find "default"
16
+ rspec = Fabric['rspec', [
17
+ /(?<green>\d+) examples, (?<red>\d+) failures?, (?<yellow>\d+) pending/,
18
+ /(?<blue>\d+\.\d+)/,
19
+ /\"(?<green>.*?)\"|\'(?<green>.*?)\'/,
20
+ /# (?<red>.*):(?<yellow>\d+)/
21
+ ]]
22
+
23
+ help = Fabric[/-h|--help|help/, /(?<yellow>\B-{1,2}[\w-]+)|(?<blue>[\[\]\(\)\{\}\<\>])|(?<green>["'].*?["'])/]
24
+ git = Fabric["git", /(?<green>'.*?')|(?<blue>".*?")/]
25
+ ruby = Fabric['ruby', /(.*from |)(?<red>.*):(?<blue>\d+)(?::in )(?<yellow>`.*')/]
26
+ default = Fabric['default', /(?<green>\d+\.\d+)|(?<blue>".*")/]
27
+
28
+ fabrics = [rspec, git, ruby, help, default]
29
+
30
+ options = {}
31
+
32
+ parser = OptionParser.new do |opts|
33
+ opts.banner = "Usage: hilight <cmd>"
34
+
35
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
36
+ options[:verbose] = v
37
+ end
41
38
  end
42
39
 
43
- filters.define_singleton_method(:run) do
44
- arg_string = ARGV.join(' ')
40
+ arguments, cmd = split_opts ARGV
41
+ parser.parse arguments
45
42
 
46
- f = filters.find arg_string
43
+ if cmd.any?
44
+ cmd_string = cmd.join(' ')
47
45
 
48
- output, process = Open3.capture2e(arg_string)
46
+ fabric = fabrics.find { |f| f.match? cmd_string }
47
+ fabric ||= default
49
48
 
50
- puts f.patterns.output(output)
49
+ output, process = Open3.capture2e(cmd_string)
50
+ print fabric.transform output
51
51
 
52
52
  exit process.exitstatus
53
+ else
54
+ $stdout << default.transform($stdin.readline) until $stdin.eof?
53
55
  end
54
-
55
- abort 'hilight <cmd>' unless ARGV.any?
56
- filters.run
@@ -1,22 +1,58 @@
1
1
  require "hilight/version"
2
2
  require 'term/ansicolor'
3
3
 
4
- Hilight::Pattern = Struct.new :regexp, :replacement
5
- Hilight::Pattern.define_method(:output) do |input|
6
- # map our colors in to the matches
7
- regexp.names.map { |n| replacement.gsub!("\\k<#{n}>") { |s| Term::ANSIColor.color(n, s) } }
8
- # map our input into the output, return the original if it doesn't map (replace) anything.
9
- input.gsub!(regexp, replacement) || input
4
+ Hilight.define_singleton_method(:load) do |filename|
5
+ return Kernel.load filename if File.exist? filename
6
+
7
+ Kernel.load "#{Dir.home}/.config/hilight/patterns/#{filename}"
10
8
  end
11
9
 
12
- Hilight::Patterns = Struct.new :patterns
13
- Hilight::Patterns.define_method(:output) do |input|
14
- patterns.each { |pattern| input = pattern.output(input) }
15
- input
10
+ Hilight.define_singleton_method(:transform) do |input, regexps = []|
11
+ raise ArgumentError, "#{input} is not a kind of String" unless input.is_a? String
12
+ raise ArgumentError, "#{input} is not a kind of Array or Regexp" unless regexps.is_a?(Array) || regexps.is_a?(Regexp)
13
+
14
+ regexp = Regexp.union regexps
15
+
16
+ match = regexp.match input
17
+ return input unless match
18
+
19
+ output = []
20
+ while match
21
+ output.push match.pre_match unless match.pre_match.empty?
22
+
23
+ captured_string = match.to_a[0]
24
+ color_lookup_list = match.named_captures.invert
25
+
26
+ match.to_a[1..-1].each do |s|
27
+ next unless s
28
+
29
+ color = color_lookup_list[s]
30
+ captured_string.gsub!(s, Term::ANSIColor.color(color, s))
31
+ end
32
+
33
+ output.push captured_string if captured_string
34
+
35
+ post_match = match.post_match
36
+ match = regexp.match(match.post_match)
37
+
38
+ output.push post_match unless match
39
+ end
40
+
41
+ output.join("")
16
42
  end
17
43
 
18
- Hilight.define_singleton_method(:load) do |filename|
19
- return Kernel.load filename if File.exist? filename
44
+ Hilight::Fabric = Struct.new :pattern, :regexps
45
+ Hilight::Fabric.define_method(:match?) do |string|
46
+ raise ArgumentError, "#{string} is not a kind of String" unless string.is_a? String
20
47
 
21
- Kernel.load "#{Dir.home}/.config/hilight/patterns/#{filename}"
48
+ case pattern
49
+ when Symbol then (pattern.to_s == string)
50
+ when String then (pattern == string)
51
+ when Regexp then (pattern.match? string.to_s)
52
+ else false
53
+ end
54
+ end
55
+
56
+ Hilight::Fabric.define_method(:transform) do |string|
57
+ Hilight.transform string, regexps
22
58
  end
@@ -1,3 +1,3 @@
1
1
  module Hilight
2
- VERSION = "0.1.1".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hilight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernie Brodeur
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-07 00:00:00.000000000 Z
11
+ date: 2019-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: term-ansicolor