glark 1.10.0 → 1.10.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/glark/app/help.rb +1 -1
- data/lib/glark/app/info/options.rb +3 -3
- data/lib/glark/app/options.rb +1 -1
- data/lib/glark/app/runner.rb +3 -3
- data/lib/glark/input/filter/criteria_opts.rb +1 -2
- data/lib/glark/input/filter/file_criteria_opts.rb +1 -1
- data/lib/glark/input/options.rb +5 -5
- data/lib/glark/input/range.rb +12 -12
- data/lib/glark/io/file/zip_file.rb +1 -1
- data/lib/glark/match/options.rb +4 -4
- data/lib/glark/output/context.rb +3 -3
- data/lib/glark/output/glark_format.rb +1 -1
- data/lib/glark/output/grep_lines.rb +1 -1
- data/lib/glark/output/options.rb +5 -5
- data/lib/glark/util/colors/options.rb +3 -4
- data/lib/glark/util/highlight.rb +2 -19
- data/lib/glark/util/io/fileset.rb +0 -2
- data/lib/glark/util/io/lines.rb +1 -2
- data/lib/glark/util/optutil.rb +3 -2
- data/test/glark/app/options_test.rb +4 -11
- data/test/glark/app/stdin_test.rb +65 -0
- data/test/glark/app/tc.rb +2 -4
- data/test/glark/match_test.rb +0 -2
- data/test/glark/tc.rb +3 -2
- metadata +155 -173
- data/man/glark.1 +0 -1134
- data/test/glark/app/dump_test.rb +0 -16
- data/test/glark/input/filter/filter_spec_test.rb +0 -27
data/lib/glark/app/help.rb
CHANGED
@@ -7,7 +7,7 @@ require 'glark/util/options'
|
|
7
7
|
|
8
8
|
module Glark
|
9
9
|
PACKAGE = 'glark'
|
10
|
-
VERSION = '1.10.
|
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
|
-
|
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
|
-
|
33
|
+
{
|
34
34
|
"explain" => @explain,
|
35
35
|
"known_nontext_files" => FileType.nontext_extensions.join(", "),
|
36
36
|
"known_text_files" => FileType.text_extensions.join(", "),
|
data/lib/glark/app/options.rb
CHANGED
data/lib/glark/app/runner.rb
CHANGED
@@ -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 '#{
|
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 '#{
|
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
|
123
|
+
search_text nil, $stdin
|
124
124
|
else
|
125
125
|
case type
|
126
126
|
when :binary
|
data/lib/glark/input/options.rb
CHANGED
@@ -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
|
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 <<
|
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 <<
|
92
|
+
optdata << {
|
93
93
|
:tags => %w{ -r --recurse },
|
94
94
|
:set => Proc.new { set_directory("recurse") }
|
95
95
|
}
|
96
96
|
|
97
|
-
optdata <<
|
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 <<
|
104
|
+
optdata << {
|
105
105
|
:tags => %w{ --binary-files },
|
106
106
|
:arg => [ :required, :regexp, re ],
|
107
107
|
:set => Proc.new { |md| @binary_files = md[1] },
|
data/lib/glark/input/range.rb
CHANGED
@@ -74,22 +74,22 @@ module Glark
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def add_as_option optdata
|
77
|
-
optdata <<
|
78
|
-
:tags
|
79
|
-
:arg
|
80
|
-
:set
|
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 <<
|
84
|
-
:tags
|
85
|
-
:arg
|
86
|
-
:set
|
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 <<
|
90
|
-
:tags
|
91
|
-
:arg
|
92
|
-
:set
|
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]
|
data/lib/glark/match/options.rb
CHANGED
@@ -19,14 +19,14 @@ module Glark
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def config_fields
|
22
|
-
|
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
|
-
|
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 <<
|
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 <<
|
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) ] }
|
data/lib/glark/output/context.rb
CHANGED
@@ -30,7 +30,7 @@ module Glark
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def add_as_option optdata
|
33
|
-
optdata <<
|
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 <<
|
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 <<
|
48
|
+
optdata << {
|
49
49
|
:tags => %w{ --before-context -B },
|
50
50
|
:arg => [ :integer ],
|
51
51
|
:set => Proc.new { |val| @before = val },
|
data/lib/glark/output/options.rb
CHANGED
@@ -16,7 +16,7 @@ module Glark
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def config_fields
|
19
|
-
|
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
|
-
|
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 <<
|
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 <<
|
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 <<
|
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
|
-
|
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
|
-
|
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 +
|
119
|
+
field + str + Sickill::Rainbow::TERM_EFFECTS[:reset]
|
121
120
|
else
|
122
121
|
str
|
123
122
|
end
|
data/lib/glark/util/highlight.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
data/lib/glark/util/io/lines.rb
CHANGED
@@ -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
|
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
|
data/lib/glark/util/optutil.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/ruby -w
|
2
2
|
# -*- ruby -*-
|
3
3
|
|
4
|
-
require '
|
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 +
|
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
|
-
|
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
|
-
|
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
|
-
|
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(
|
190
|
+
singlecolor = str_to_color_codes(ColorOptions::DEFAULT_COLORS[0])
|
198
191
|
|
199
192
|
%w{ single }.each do |val|
|
200
193
|
[
|