glark 1.10.0 → 1.10.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.
@@ -90,7 +90,7 @@ module Glark
90
90
  end
91
91
 
92
92
  if dir
93
- manfile = dir + "man/glark.1"
93
+ # manfile = dir + "man/glark.1"
94
94
  cmd = "gem man glark"
95
95
  ::IO.popen(cmd) do |io|
96
96
  puts io.readlines
@@ -7,7 +7,7 @@ require 'glark/util/options'
7
7
 
8
8
  module Glark
9
9
  PACKAGE = 'glark'
10
- VERSION = '1.10.0'
10
+ VERSION = '1.10.1'
11
11
 
12
12
  class InfoOptions < Options
13
13
  attr_reader :colors
@@ -21,7 +21,7 @@ module Glark
21
21
  end
22
22
 
23
23
  def config_fields
24
- fields = {
24
+ {
25
25
  "known-nontext-files" => FileType.nontext_extensions.sort.join(' '),
26
26
  "known-text-files" => FileType.text_extensions.sort.join(' '),
27
27
  "quiet" => Log.quiet,
@@ -30,7 +30,7 @@ module Glark
30
30
  end
31
31
 
32
32
  def dump_fields
33
- fields = {
33
+ {
34
34
  "explain" => @explain,
35
35
  "known_nontext_files" => FileType.nontext_extensions.join(", "),
36
36
  "known_text_files" => FileType.text_extensions.join(", "),
@@ -109,7 +109,7 @@ module Glark
109
109
  end
110
110
 
111
111
  def config_fields
112
- fields = {
112
+ {
113
113
  "local-config-files" => @local_config_files,
114
114
  }
115
115
  end
@@ -87,7 +87,7 @@ module Glark
87
87
  when ZIP_RE.match(fstr)
88
88
  search_read_archive_file fname, Glark::ZipFile
89
89
  else
90
- write "file '#{fname}' does not have a handled extension"
90
+ write "file '#{fstr}' does not have a handled extension for reading content"
91
91
  return
92
92
  end
93
93
  end
@@ -103,7 +103,7 @@ module Glark
103
103
  when TAR_GZ_RE.match(fstr)
104
104
  Glark::TarGzFile
105
105
  else
106
- write "file '#{fname}' does not have a handled extension"
106
+ write "file '#{fstr}' does not have a handled extension for reading a list"
107
107
  return
108
108
  end
109
109
 
@@ -120,7 +120,7 @@ module Glark
120
120
 
121
121
  if name == "-"
122
122
  write "reading standard input..."
123
- search_text name, $stdin
123
+ search_text nil, $stdin
124
124
  else
125
125
  case type
126
126
  when :binary
@@ -16,8 +16,7 @@ module Glark
16
16
  end
17
17
 
18
18
  def config_fields
19
- fields = {
20
- }
19
+ Hash.new
21
20
  end
22
21
 
23
22
  def dump_fields
@@ -25,7 +25,7 @@ module Glark
25
25
 
26
26
  def config_fields
27
27
  maxsize = (filter = find_by_class(:size, :negative, SizeLimitFilter)) && filter.max_size
28
- fields = {
28
+ {
29
29
  "size-limit" => maxsize
30
30
  }
31
31
  end
@@ -33,7 +33,7 @@ module Glark
33
33
  $/ = if sep && sep.to_i > 0
34
34
  begin
35
35
  sep.oct.chr
36
- rescue RangeError => e
36
+ rescue RangeError
37
37
  # out of range (e.g., 777) means nil:
38
38
  nil
39
39
  end
@@ -82,26 +82,26 @@ module Glark
82
82
  end
83
83
 
84
84
  def add_as_options optdata
85
- optdata << record_separator_option = {
85
+ optdata << {
86
86
  :res => [ Regexp.new('^ -0 (\d{1,3})? $ ', Regexp::EXTENDED) ],
87
87
  :set => Proc.new { |md| rs = md ? md[1] : 0; set_record_separator rs }
88
88
  }
89
89
 
90
90
  @range.add_as_option optdata
91
91
 
92
- optdata << recurse_option = {
92
+ optdata << {
93
93
  :tags => %w{ -r --recurse },
94
94
  :set => Proc.new { set_directory("recurse") }
95
95
  }
96
96
 
97
- optdata << directories_option = {
97
+ optdata << {
98
98
  :tags => %w{ --directories -d },
99
99
  :arg => [ :string ],
100
100
  :set => Proc.new { |val| set_directory val },
101
101
  }
102
102
 
103
103
  re = Regexp.new '^[\'\"]?(' + VALID_BINARY_FILE_TYPES.join('|') + ')[\'\"]?$'
104
- optdata << binary_files_option = {
104
+ optdata << {
105
105
  :tags => %w{ --binary-files },
106
106
  :arg => [ :required, :regexp, re ],
107
107
  :set => Proc.new { |md| @binary_files = md[1] },
@@ -74,22 +74,22 @@ module Glark
74
74
  end
75
75
 
76
76
  def add_as_option optdata
77
- optdata << range_after_option = {
78
- :tags => %w{ --after },
79
- :arg => [ :required, :regexp, %r{ (\d+%?) $ }x ],
80
- :set => Proc.new { |md| @from = md[1] }
77
+ optdata << {
78
+ :tags => %w{ --after },
79
+ :arg => [ :required, :regexp, %r{ (\d+%?) $ }x ],
80
+ :set => Proc.new { |md| @from = md[1] }
81
81
  }
82
82
 
83
- optdata << range_before_option = {
84
- :tags => %w{ --before },
85
- :arg => [ :required, :regexp, %r{ (\d+%?) $ }x ],
86
- :set => Proc.new { |md| @to = md[1] }
83
+ optdata << {
84
+ :tags => %w{ --before },
85
+ :arg => [ :required, :regexp, %r{ (\d+%?) $ }x ],
86
+ :set => Proc.new { |md| @to = md[1] }
87
87
  }
88
88
 
89
- optdata << range_option = {
90
- :tags => %w{ -R --range },
91
- :arg => [ :required, :regexp, Regexp.new('(\d+%?),(\d+%?)') ],
92
- :set => Proc.new do |md, opt, args|
89
+ optdata << {
90
+ :tags => %w{ -R --range },
91
+ :arg => [ :required, :regexp, Regexp.new('(\d+%?),(\d+%?)') ],
92
+ :set => Proc.new do |md, opt, args|
93
93
  if md && md[1] && md[2]
94
94
  @from = md[1]
95
95
  @to = md[2]
@@ -19,7 +19,7 @@ module Glark
19
19
  rescue LoadError => e
20
20
  msg = "error loading zip gem: #{e}\n"
21
21
  msg << "to install this dependency, run 'gem install rubyzip'"
22
- info "msg: #{msg}".on_red
22
+ info "msg: #{msg}".color(:red)
23
23
  raise msg
24
24
  end
25
25
  end
@@ -19,14 +19,14 @@ module Glark
19
19
  end
20
20
 
21
21
  def config_fields
22
- fields = {
22
+ {
23
23
  "ignore-case" => @ignorecase,
24
24
  "text-color" => text_colors.join(' '),
25
25
  }
26
26
  end
27
27
 
28
28
  def dump_fields
29
- fields = {
29
+ {
30
30
  "expr" => @expr,
31
31
  "extract_matches" => @extract_matches,
32
32
  "ignorecase" => @ignorecase,
@@ -51,7 +51,7 @@ module Glark
51
51
  add_opt_true optdata, :whole_lines, %w{ -x --line-regexp }
52
52
  add_opt_true optdata, :extended, %w{ --extended }
53
53
 
54
- optdata << expr_file_option = {
54
+ optdata << {
55
55
  :tags => %w{ -f --file },
56
56
  :arg => [ :string ],
57
57
  :set => Proc.new { |fname| @expr = create_expression_factory.read_file fname }
@@ -62,7 +62,7 @@ module Glark
62
62
  @expr = create_expression_factory.make_expression args
63
63
  end
64
64
 
65
- optdata << text_color_option = {
65
+ optdata << {
66
66
  :tags => %w{ --text-color },
67
67
  :arg => [ :string ],
68
68
  :set => Proc.new { |val| @colors.text_colors = [ @colors.create_color("text-color", val) ] }
@@ -30,7 +30,7 @@ module Glark
30
30
  end
31
31
 
32
32
  def add_as_option optdata
33
- optdata << context_option = {
33
+ optdata << {
34
34
  :tags => %w{ -C --context },
35
35
  :res => %r{ ^ - ([1-9]\d*) $ }x,
36
36
  :arg => [ :optional, :integer ],
@@ -38,14 +38,14 @@ module Glark
38
38
  :rc => %w{ context },
39
39
  }
40
40
 
41
- optdata << context_after_option = {
41
+ optdata << {
42
42
  :tags => %w{ --after-context -A },
43
43
  :arg => [ :integer ],
44
44
  :set => Proc.new { |val| @after = val },
45
45
  :rc => %w{ after-context },
46
46
  }
47
47
 
48
- optdata << context_before_option = {
48
+ optdata << {
49
49
  :tags => %w{ --before-context -B },
50
50
  :arg => [ :integer ],
51
51
  :set => Proc.new { |val| @before = val },
@@ -20,7 +20,7 @@ module Glark
20
20
  end
21
21
 
22
22
  def show_file_header
23
- if @show_file_name && @file_header.nil?
23
+ if @show_file_name && @file_header.nil? && displayed_name
24
24
  @file_header = FileHeader.new displayed_name, @fname_highlighter
25
25
  @file_header.print @out
26
26
  end
@@ -27,7 +27,7 @@ module Grep
27
27
  end
28
28
 
29
29
  def print_file_name
30
- if @show_file_name
30
+ if @show_file_name && displayed_name
31
31
  @out.print displayed_name, ":"
32
32
  end
33
33
  end
@@ -16,7 +16,7 @@ module Glark
16
16
  end
17
17
 
18
18
  def config_fields
19
- fields = {
19
+ {
20
20
  "after-context" => @context.after,
21
21
  "before-context" => @context.before,
22
22
  "filter" => @filter,
@@ -25,7 +25,7 @@ module Glark
25
25
  end
26
26
 
27
27
  def dump_fields
28
- fields = {
28
+ {
29
29
  "after" => @context.after,
30
30
  "before" => @context.before,
31
31
  "count" => @count,
@@ -76,7 +76,7 @@ module Glark
76
76
  add_opt_blk(optdata, %w{ -U --no-highlight }) { @colors.text_color_style = nil }
77
77
  add_opt_blk(optdata, %w{ -g --grep }) { self.style = "grep" }
78
78
 
79
- optdata << lnum_color_option = {
79
+ optdata << {
80
80
  :tags => %w{ --line-number-color },
81
81
  :arg => [ :string ],
82
82
  :set => Proc.new { |val| @colors.line_number_color = @colors.create_color "line-number-color", val },
@@ -87,13 +87,13 @@ module Glark
87
87
  add_opt_true optdata, :show_file_names, %w{ -H --with-filename }
88
88
  add_opt_false optdata, :show_file_names, %w{ -h --no-filename }
89
89
 
90
- optdata << highlight_option = {
90
+ optdata << {
91
91
  :tags => %w{ -u --highlight },
92
92
  :arg => [ :optional, :regexp, %r{ ^ (?:(multi|single)|none) $ }x ],
93
93
  :set => Proc.new { |md| val = md ? md[1] : "multi"; @colors.text_color_style = val }
94
94
  }
95
95
 
96
- optdata << file_color_option = {
96
+ optdata << {
97
97
  :tags => %w{ --file-color },
98
98
  :arg => [ :string ],
99
99
  :set => Proc.new { |val| @colors.file_name_color = @colors.create_color "file-color", val }
@@ -61,7 +61,6 @@ module Glark
61
61
 
62
62
  def multi_colors
63
63
  make_colors
64
- # [ make_rgb_color(4, 3, 2, :bg) + make_rgb_color(0, 2, 1, :fg) ]
65
64
  end
66
65
 
67
66
  def single_color
@@ -100,7 +99,7 @@ module Glark
100
99
  end
101
100
 
102
101
  def config_fields
103
- fields = {
102
+ {
104
103
  "file-color" => @file_name_color,
105
104
  "highlight" => @text_color_style,
106
105
  "line-number-color" => @line_number_color,
@@ -108,7 +107,7 @@ module Glark
108
107
  end
109
108
 
110
109
  def dump_fields
111
- fields = {
110
+ {
112
111
  "file_name_color" => colorize(@file_name_color, "filename"),
113
112
  "highlight" => @text_color_style,
114
113
  "line_number_color" => colorize(@line_number_color, "12345"),
@@ -117,7 +116,7 @@ module Glark
117
116
 
118
117
  def colorize field, str
119
118
  if field
120
- field + str + Text::Color::RESET
119
+ field + str + Sickill::Rainbow::TERM_EFFECTS[:reset]
121
120
  else
122
121
  str
123
122
  end
@@ -1,27 +1,15 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
- $rielold = false
5
-
6
4
  require 'rubygems'
7
5
  require 'rainbow'
8
6
  require 'singleton'
9
7
 
10
- if $rielold
11
- require 'riel/ansicolor'
12
- else
13
- require 'riel/text/ansi/ansi_highlight'
14
- end
15
-
16
8
  module Highlight
17
9
  RESET = "\x1b[0m"
18
10
 
19
11
  def adorn hl, str
20
- if $rielold
21
- hl.highlight str
22
- else
23
- hl + str + RESET
24
- end
12
+ hl + str + RESET
25
13
  end
26
14
  end
27
15
 
@@ -90,16 +78,11 @@ end
90
78
 
91
79
  class HlWrapper
92
80
  def initialize
93
- # @hl = $rielold ? Text::ANSIHighlighter : Text::ANSIHighlighter.instance
94
81
  @hl = RainbowHighlighter.instance
95
82
  end
96
83
 
97
84
  def make_color color
98
- if $rielold
99
- result = @hl.make color
100
- else
101
- @hl.to_codes color
102
- end
85
+ @hl.to_codes color
103
86
  end
104
87
 
105
88
  def make_rgb_color red, green, blue, fgbg
@@ -80,8 +80,6 @@ module Glark
80
80
 
81
81
  (0 ... @files.size).each do |idx|
82
82
  pn = @files[idx]
83
- type = FileType.type pn.to_s
84
-
85
83
  if stdin?
86
84
  blk.call [ :text, '-' ]
87
85
  next
@@ -85,8 +85,7 @@ module Glark
85
85
  # This is much easier. Just resplit the whole thing at end of line
86
86
  # sequences.
87
87
 
88
- eoline = "\n" # should be OS-dependent
89
- srclines = @lines
88
+ eoline = "\n" # should be OS-dependent
90
89
  reallines = @lines.join("").split ANY_END_OF_LINE
91
90
 
92
91
  # "\n" after all but the last line
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
- require 'riel/text/ansi/color'
4
+ require 'rubygems'
5
+ require 'rainbow'
5
6
 
6
7
  module Glark
7
8
  module OptionUtil
@@ -60,7 +61,7 @@ module Glark
60
61
 
61
62
  def colorize field, str
62
63
  if field
63
- field + str + Text::Color::RESET
64
+ field + str + Sickill::Rainbow::TERM_EFFECTS[:reset]
64
65
  else
65
66
  str
66
67
  end
@@ -28,31 +28,24 @@ module Glark
28
28
  end
29
29
 
30
30
  def assert_color opts, name, expval, args
31
- val = opts.method(name).call
32
- ### puts "val: #{val}"
33
- ### puts "expval: #{expval}"
34
- ###$$$ assert_equal expval, val, "args: #{args}"
31
+ opts.method(name).call
35
32
  end
36
33
 
37
34
  def assert_colors opts, exp, args
38
35
  return unless exp
39
36
  exp.each do |name, expval|
40
- ### puts "name: #{name}"
41
37
  val = opts.method(name).call
42
- ### puts "val: #{val}"
43
- ### puts "expval: #{expval}"
44
- ###$$$ assert_equal expval, val, "args: #{args}"
38
+ assert_equal expval, val, "args: #{args}"
45
39
  end
46
40
  end
47
41
 
48
42
  def run_test args, expected = Hash.new, &blk
49
43
  gopt = Glark::AppOptions.new
50
44
  gopt.run args + Array.new
51
- outputopts = gopt.output_options
52
45
 
53
46
  assert_method_values gopt, expected[:app], args
54
47
  assert_method_values gopt.match_spec, expected[:match], args
55
- # assert_method_values gopt.colors, expected[:colors], args
48
+ assert_method_values gopt.colors, expected[:colors], args
56
49
  assert_colors gopt.colors, expected[:colors], args
57
50
  assert_method_values gopt.output_options, expected[:output], args
58
51
  assert_method_values gopt.info_options, expected[:info], args
@@ -194,7 +187,7 @@ module Glark
194
187
  end
195
188
  end
196
189
 
197
- singlecolor = str_to_color_codes(Text::Highlighter::DEFAULT_COLORS[0])
190
+ singlecolor = str_to_color_codes(ColorOptions::DEFAULT_COLORS[0])
198
191
 
199
192
  %w{ single }.each do |val|
200
193
  [