pry 0.8.4pre1-java → 0.9.0pre1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.markdown +1 -1
- data/Rakefile +11 -5
- data/TODO +28 -2
- data/bin/pry +5 -9
- data/examples/example_basic.rb +2 -4
- data/examples/example_command_override.rb +2 -5
- data/examples/example_commands.rb +1 -4
- data/examples/example_hooks.rb +2 -5
- data/examples/example_image_edit.rb +4 -8
- data/examples/example_input.rb +1 -4
- data/examples/example_input2.rb +1 -4
- data/examples/example_output.rb +1 -4
- data/examples/example_print.rb +2 -5
- data/examples/example_prompt.rb +2 -5
- data/examples/helper.rb +6 -0
- data/lib/pry.rb +61 -4
- data/lib/pry/command_context.rb +10 -9
- data/lib/pry/command_processor.rb +29 -68
- data/lib/pry/command_set.rb +79 -28
- data/lib/pry/commands.rb +10 -121
- data/lib/pry/completion.rb +30 -29
- data/lib/pry/config.rb +93 -0
- data/lib/pry/default_commands/basic.rb +37 -0
- data/lib/pry/default_commands/context.rb +15 -15
- data/lib/pry/default_commands/documentation.rb +49 -48
- data/lib/pry/default_commands/easter_eggs.rb +1 -20
- data/lib/pry/default_commands/gems.rb +32 -41
- data/lib/pry/default_commands/input.rb +95 -19
- data/lib/pry/default_commands/introspection.rb +54 -60
- data/lib/pry/default_commands/ls.rb +2 -2
- data/lib/pry/default_commands/shell.rb +29 -39
- data/lib/pry/extended_commands/experimental.rb +48 -0
- data/lib/pry/extended_commands/user_command_api.rb +22 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +9 -106
- data/lib/pry/helpers/command_helpers.rb +96 -59
- data/lib/pry/helpers/text.rb +83 -0
- data/lib/pry/plugins.rb +79 -0
- data/lib/pry/pry_class.rb +96 -111
- data/lib/pry/pry_instance.rb +87 -55
- data/lib/pry/version.rb +1 -1
- data/test/helper.rb +56 -7
- data/test/test_command_processor.rb +99 -0
- data/test/{test_commandset.rb → test_command_set.rb} +18 -12
- data/test/test_default_commands.rb +59 -0
- data/test/test_default_commands/test_context.rb +64 -0
- data/test/test_default_commands/test_documentation.rb +31 -0
- data/test/test_default_commands/test_input.rb +157 -0
- data/test/test_default_commands/test_introspection.rb +146 -0
- data/test/test_pry.rb +430 -313
- metadata +25 -9
- data/lib/pry/hooks.rb +0 -17
- data/lib/pry/print.rb +0 -16
- data/lib/pry/prompts.rb +0 -31
@@ -1,26 +1,25 @@
|
|
1
1
|
class Pry
|
2
2
|
module DefaultCommands
|
3
3
|
|
4
|
-
Introspection = Pry::CommandSet.new
|
4
|
+
Introspection = Pry::CommandSet.new do
|
5
5
|
|
6
6
|
command "show-method", "Show the source for METH. Type `show-method --help` for more info. Aliases: $, show-source" do |*args|
|
7
7
|
target = target()
|
8
8
|
|
9
|
-
opts = Slop.parse!(args) do |
|
10
|
-
|
11
|
-
Show the source for method METH. Tries instance methods first and then methods by default
|
12
|
-
e.g: show-method hello_method
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
opts.on :c, :context, "Select object context to run under.", true do |context|
|
9
|
+
opts = Slop.parse!(args) do |opt|
|
10
|
+
opt.banner "Usage: show-method [OPTIONS] [METH]\n" \
|
11
|
+
"Show the source for method METH. Tries instance methods first and then methods by default.\n" \
|
12
|
+
"e.g: show-method hello_method"
|
13
|
+
|
14
|
+
opt.on :l, "line-numbers", "Show line numbers."
|
15
|
+
opt.on :M, "instance-methods", "Operate on instance methods."
|
16
|
+
opt.on :m, :methods, "Operate on methods."
|
17
|
+
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
|
18
|
+
opt.on :c, :context, "Select object context to run under.", true do |context|
|
20
19
|
target = Pry.binding_for(target.eval(context))
|
21
20
|
end
|
22
|
-
|
23
|
-
output.puts
|
21
|
+
opt.on :h, :help, "This message." do
|
22
|
+
output.puts opt
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
@@ -53,54 +52,46 @@ e.g: show-method hello_method
|
|
53
52
|
alias_command "$", "show-method", ""
|
54
53
|
|
55
54
|
command "show-command", "Show the source for CMD. Type `show-command --help` for more info." do |*args|
|
56
|
-
options = {}
|
57
55
|
target = target()
|
58
|
-
command_name = nil
|
59
|
-
|
60
|
-
OptionParser.new do |opts|
|
61
|
-
opts.banner = %{Usage: show-command [OPTIONS] [CMD]
|
62
|
-
Show the source for command CMD.
|
63
|
-
e.g: show-command show-method
|
64
|
-
--
|
65
|
-
}
|
66
|
-
opts.on("-l", "--line-numbers", "Show line numbers.") do |line|
|
67
|
-
options[:l] = true
|
68
|
-
end
|
69
56
|
|
70
|
-
|
71
|
-
|
72
|
-
|
57
|
+
opts = Slop.parse!(args) do |opt|
|
58
|
+
opt.banner = "Usage: show-command [OPTIONS] [CMD]\n" \
|
59
|
+
"Show the source for command CMD.\n" \
|
60
|
+
"e.g: show-command show-method"
|
73
61
|
|
74
|
-
|
75
|
-
|
76
|
-
|
62
|
+
opt.on :l, "line-numbers", "Show line numbers."
|
63
|
+
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
|
64
|
+
opt.on :h, :help, "This message." do
|
65
|
+
output.puts opt
|
77
66
|
end
|
78
|
-
end.order(args) do |v|
|
79
|
-
command_name = v
|
80
67
|
end
|
81
68
|
|
82
|
-
next if
|
69
|
+
next if opts.help?
|
83
70
|
|
71
|
+
command_name = args.shift
|
84
72
|
if !command_name
|
85
73
|
output.puts "You must provide a command name."
|
86
74
|
next
|
87
75
|
end
|
88
76
|
|
89
|
-
if
|
90
|
-
|
77
|
+
if find_command(command_name)
|
78
|
+
block = find_command(command_name).block
|
91
79
|
|
92
|
-
code =
|
93
|
-
|
94
|
-
set_file_and_dir_locals(file)
|
95
|
-
check_for_dynamically_defined_method(meth)
|
80
|
+
code, _ = code_and_code_type_for(block)
|
81
|
+
next if !code
|
96
82
|
|
97
|
-
output.puts make_header(
|
83
|
+
output.puts make_header(block, :ruby, code)
|
98
84
|
|
99
85
|
if Pry.color
|
100
86
|
code = CodeRay.scan(code, :ruby).term
|
101
87
|
end
|
102
88
|
|
103
|
-
|
89
|
+
start_line = false
|
90
|
+
if opts.l?
|
91
|
+
start_line = block.source_location ? block.source_location.last : 1
|
92
|
+
end
|
93
|
+
|
94
|
+
render_output(opts.flood?, opts.l? ? block.source_location.last : false, code)
|
104
95
|
code
|
105
96
|
else
|
106
97
|
output.puts "No such command: #{command_name}."
|
@@ -110,22 +101,21 @@ e.g: show-command show-method
|
|
110
101
|
command "edit-method", "Edit a method. Type `edit-method --help` for more info." do |*args|
|
111
102
|
target = target()
|
112
103
|
|
113
|
-
opts = Slop.parse!(args) do |
|
114
|
-
|
115
|
-
Edit the method METH in an editor
|
116
|
-
Ensure #{bold("Pry.editor")} is set to your editor of choice
|
117
|
-
e.g: edit-method hello_method
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
opts.on :c, :context, "Select object context to run under.", true do |context|
|
104
|
+
opts = Slop.parse!(args) do |opt|
|
105
|
+
opt.banner "Usage: edit-method [OPTIONS] [METH]\n" \
|
106
|
+
"Edit the method METH in an editor.\n" \
|
107
|
+
"Ensure #{text.bold("Pry.editor")} is set to your editor of choice.\n" \
|
108
|
+
"e.g: edit-method hello_method"
|
109
|
+
|
110
|
+
opt.on :M, "instance-methods", "Operate on instance methods."
|
111
|
+
opt.on :m, :methods, "Operate on methods."
|
112
|
+
opt.on "no-reload", "Do not automatically reload the method's file after editting."
|
113
|
+
opt.on :n, "no-jump", "Do not fast forward editor to first line of method."
|
114
|
+
opt.on :c, :context, "Select object context to run under.", true do |context|
|
125
115
|
target = Pry.binding_for(target.eval(context))
|
126
116
|
end
|
127
|
-
|
128
|
-
output.puts
|
117
|
+
opt.on :h, :help, "This message." do
|
118
|
+
output.puts opt
|
129
119
|
end
|
130
120
|
end
|
131
121
|
|
@@ -137,7 +127,7 @@ e.g: edit-method hello_method
|
|
137
127
|
next
|
138
128
|
end
|
139
129
|
|
140
|
-
next output.puts "Error: No editor set!\nEnsure that #{bold("Pry.editor")} is set to your editor of choice." if !Pry.editor
|
130
|
+
next output.puts "Error: No editor set!\nEnsure that #{text.bold("Pry.editor")} is set to your editor of choice." if !Pry.editor
|
141
131
|
|
142
132
|
if is_a_c_method?(meth)
|
143
133
|
output.puts "Error: Can't edit a C method."
|
@@ -146,7 +136,12 @@ e.g: edit-method hello_method
|
|
146
136
|
|
147
137
|
# editor is invoked here
|
148
138
|
else
|
149
|
-
|
139
|
+
if rbx_core?(meth)
|
140
|
+
file, line = rbx_core_path_line_for(meth)
|
141
|
+
else
|
142
|
+
file, line = meth.source_location
|
143
|
+
end
|
144
|
+
|
150
145
|
set_file_and_dir_locals(file)
|
151
146
|
|
152
147
|
if Pry.editor.respond_to?(:call)
|
@@ -164,7 +159,6 @@ e.g: edit-method hello_method
|
|
164
159
|
end
|
165
160
|
end
|
166
161
|
|
167
|
-
|
168
162
|
helpers do
|
169
163
|
|
170
164
|
def start_line_for_editor(line_number)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class Pry
|
2
2
|
module DefaultCommands
|
3
3
|
|
4
|
-
Ls = Pry::CommandSet.new
|
4
|
+
Ls = Pry::CommandSet.new do
|
5
5
|
|
6
6
|
command "ls", "Show the list of vars and methods in the current scope. Type `ls --help` for more info." do |*args|
|
7
7
|
options = {}
|
@@ -194,6 +194,6 @@ Shows local and instance variables by default.
|
|
194
194
|
end
|
195
195
|
|
196
196
|
|
197
|
-
end
|
198
197
|
end
|
199
198
|
end
|
199
|
+
end
|
@@ -1,10 +1,22 @@
|
|
1
1
|
class Pry
|
2
2
|
module DefaultCommands
|
3
3
|
|
4
|
-
Shell = Pry::CommandSet.new
|
4
|
+
Shell = Pry::CommandSet.new do
|
5
|
+
|
6
|
+
command /\.(.*)/, "All text following a '.' is forwarded to the shell.", :listing => ".<shell command>" do |cmd|
|
7
|
+
if cmd =~ /^cd\s+(.+)/i
|
8
|
+
dest = $1
|
9
|
+
begin
|
10
|
+
Dir.chdir File.expand_path(dest)
|
11
|
+
rescue Errno::ENOENT
|
12
|
+
output.puts "No such directory: #{dest}"
|
13
|
+
end
|
5
14
|
|
6
|
-
|
7
|
-
|
15
|
+
else
|
16
|
+
if !system(cmd)
|
17
|
+
output.puts "Error: there was a problem executing system command: #{cmd}"
|
18
|
+
end
|
19
|
+
end
|
8
20
|
end
|
9
21
|
|
10
22
|
command "shell-mode", "Toggle shell mode. Bring in pwd prompt and file completion." do
|
@@ -22,50 +34,30 @@ class Pry
|
|
22
34
|
|
23
35
|
alias_command "file-mode", "shell-mode", ""
|
24
36
|
|
25
|
-
|
26
37
|
command "cat", "Show output of file FILE. Type `cat --help` for more information." do |*args|
|
27
|
-
options= {}
|
28
|
-
file_name = nil
|
29
38
|
start_line = 0
|
30
39
|
end_line = -1
|
31
|
-
file_type = nil
|
32
|
-
|
33
|
-
OptionParser.new do |opts|
|
34
|
-
opts.banner = %{Usage: cat [OPTIONS] FILE
|
35
|
-
Cat a file. Defaults to displaying whole file. Syntax highlights file if type is recognized.
|
36
|
-
e.g: cat hello.rb
|
37
|
-
--
|
38
|
-
}
|
39
|
-
opts.on("-l", "--line-numbers", "Show line numbers.") do |line|
|
40
|
-
options[:l] = true
|
41
|
-
end
|
42
40
|
|
43
|
-
|
44
|
-
|
41
|
+
opts = Slop.parse!(args) do |opt|
|
42
|
+
opt.on :s, :start, "Start line (defaults to start of file)Line 1 is the first line.", true, :as => Integer do |line|
|
43
|
+
start_line = line - 1
|
45
44
|
end
|
46
45
|
|
47
|
-
|
48
|
-
end_line = line
|
46
|
+
opt.on :e, :end, "End line (defaults to end of file). Line -1 is the last line", true, :as => Integer do |line|
|
47
|
+
end_line = line - 1
|
49
48
|
end
|
50
49
|
|
51
|
-
|
52
|
-
|
50
|
+
opt.on :l, "line-numbers", "Show line numbers."
|
51
|
+
opt.on :t, :type, "The specific file type for syntax higlighting (e.g ruby, python)", true, :as => Symbol
|
52
|
+
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
|
53
|
+
opt.on :h, :help, "This message." do
|
54
|
+
output.puts opt
|
53
55
|
end
|
54
|
-
|
55
|
-
opts.on("-f", "--flood", "Do not use a pager to view text longer than one screen.") do
|
56
|
-
options[:f] = true
|
57
|
-
end
|
58
|
-
|
59
|
-
opts.on_tail("-h", "--help", "This message.") do
|
60
|
-
output.puts opts
|
61
|
-
options[:h] = true
|
62
|
-
end
|
63
|
-
end.order(args) do |v|
|
64
|
-
file_name = v
|
65
56
|
end
|
66
57
|
|
67
|
-
next if
|
58
|
+
next if opts.help?
|
68
59
|
|
60
|
+
file_name = args.shift
|
69
61
|
if !file_name
|
70
62
|
output.puts "Must provide a file name."
|
71
63
|
next
|
@@ -74,15 +66,13 @@ e.g: cat hello.rb
|
|
74
66
|
contents, normalized_start_line, _ = read_between_the_lines(file_name, start_line, end_line)
|
75
67
|
|
76
68
|
if Pry.color
|
77
|
-
contents = syntax_highlight_by_file_type_or_specified(contents, file_name,
|
69
|
+
contents = syntax_highlight_by_file_type_or_specified(contents, file_name, opts[:type])
|
78
70
|
end
|
79
71
|
|
80
72
|
set_file_and_dir_locals(file_name)
|
81
|
-
render_output(
|
73
|
+
render_output(opts.flood?, opts.l? ? normalized_start_line + 1 : false, contents)
|
82
74
|
contents
|
83
75
|
end
|
84
|
-
|
85
|
-
|
86
76
|
end
|
87
77
|
|
88
78
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class Pry
|
2
|
+
module ExtendedCommands
|
3
|
+
|
4
|
+
Experimental = Pry::CommandSet.new do
|
5
|
+
|
6
|
+
|
7
|
+
command "reload-method", "Reload the source specifically for a method", :requires_gem => "method_reload" do |meth_name|
|
8
|
+
if (meth = get_method_object(meth_name, target, {})).nil?
|
9
|
+
output.puts "Invalid method name: #{meth_name}."
|
10
|
+
next
|
11
|
+
end
|
12
|
+
|
13
|
+
meth.reload
|
14
|
+
end
|
15
|
+
|
16
|
+
command "play", "Play a string as input" do |*args|
|
17
|
+
Slop.parse!(args) do |opt|
|
18
|
+
opt.banner "Usage: play-method [--replay START..END] [--clear] [--grep PATTERN] [--help]\n"
|
19
|
+
|
20
|
+
opt.on :l, :lines, 'The line (or range of lines) to replay.', true, :as => Range
|
21
|
+
opt.on :m, :method, 'Play a method.', true do |meth_name|
|
22
|
+
if (meth = get_method_object(meth_name, target, {})).nil?
|
23
|
+
output.puts "Invalid method name: #{meth_name}."
|
24
|
+
next
|
25
|
+
end
|
26
|
+
code, code_type = code_and_code_type_for(meth)
|
27
|
+
next if !code
|
28
|
+
|
29
|
+
range = opt.l? ? opt[:l] : (0..-1)
|
30
|
+
|
31
|
+
Pry.active_instance.input = StringIO.new(code[range])
|
32
|
+
end
|
33
|
+
|
34
|
+
opt.on :f, "file", 'The line (or range of lines) to replay.', true do |file_name|
|
35
|
+
text = File.read File.expand_path(file_name)
|
36
|
+
range = opt.l? ? opt[:l] : (0..-1)
|
37
|
+
|
38
|
+
Pry.active_instance.input = StringIO.new(text[range])
|
39
|
+
end
|
40
|
+
|
41
|
+
opt.on :h, :help, "This message." do
|
42
|
+
output.puts opt
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Pry
|
2
|
+
module ExtendedCommands
|
3
|
+
|
4
|
+
UserCommandAPI = Pry::CommandSet.new do
|
5
|
+
|
6
|
+
command "define-command", "To honor Mon-Ouie" do |arg|
|
7
|
+
next output.puts("Provide an arg!") if arg.nil?
|
8
|
+
|
9
|
+
prime_string = "command #{arg_string}\n"
|
10
|
+
command_string = Pry.active_instance.r(target, prime_string)
|
11
|
+
|
12
|
+
eval_string.replace <<-HERE
|
13
|
+
_pry_.commands.instance_eval do
|
14
|
+
#{command_string}
|
15
|
+
end
|
16
|
+
HERE
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/pry/helpers.rb
CHANGED
@@ -14,18 +14,16 @@ class Pry
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
ensure
|
23
|
-
Pry.color = old_color_state
|
17
|
+
def find_command(name)
|
18
|
+
command_match = commands.find { |_, command| command.options[:listing] == name }
|
19
|
+
|
20
|
+
return command_match.last if command_match
|
21
|
+
nil
|
24
22
|
end
|
25
23
|
|
26
24
|
def gem_installed?(gem_name)
|
27
25
|
require 'rubygems'
|
28
|
-
|
26
|
+
Gem::Specification.respond_to?(:find_all_by_name) ? !Gem::Specification.find_all_by_name(gem_name).empty? : Gem.source_index.find_name(gem_name).first
|
29
27
|
end
|
30
28
|
|
31
29
|
def command_dependencies_met?(options)
|
@@ -47,8 +45,10 @@ class Pry
|
|
47
45
|
gems_needed = Array(options[:requires_gem])
|
48
46
|
gems_not_installed = gems_needed.select { |g| !gem_installed?(g) }
|
49
47
|
proc do
|
50
|
-
output.puts "\
|
48
|
+
output.puts "\nThe command '#{name}' requires the following gems to be installed: #{(gems_needed.join(", "))}"
|
49
|
+
output.puts "-"
|
51
50
|
output.puts "Command not available due to dependency on gems: `#{gems_not_installed.join(", ")}` not being met."
|
51
|
+
output.puts "-"
|
52
52
|
output.puts "Type `install #{name}` to install the required gems and activate this command."
|
53
53
|
end
|
54
54
|
end
|
@@ -63,103 +63,6 @@ class Pry
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
#
|
67
|
-
# Color helpers:
|
68
|
-
# gray, red, green, yellow, blue, purple, cyan, white,
|
69
|
-
# and bright_red, bright_green, etc...
|
70
|
-
#
|
71
|
-
# ANSI color codes:
|
72
|
-
# \033 => escape
|
73
|
-
# 30 => color base
|
74
|
-
# 1 => bright
|
75
|
-
# 0 => normal
|
76
|
-
#
|
77
|
-
|
78
|
-
COLORS = {
|
79
|
-
"black" => 0,
|
80
|
-
"red" => 1,
|
81
|
-
"green" => 2,
|
82
|
-
"yellow" => 3,
|
83
|
-
"blue" => 4,
|
84
|
-
"purple" => 5,
|
85
|
-
"magenta" => 5,
|
86
|
-
"cyan" => 6,
|
87
|
-
"white" => 7
|
88
|
-
}
|
89
|
-
|
90
|
-
COLORS.each do |color, i|
|
91
|
-
define_method color do |str|
|
92
|
-
Pry.color ? "\033[0;#{30+i}m#{str}\033[0m" : str
|
93
|
-
end
|
94
|
-
|
95
|
-
define_method "bright_#{color}" do |str|
|
96
|
-
Pry.color ? "\033[1;#{30+i}m#{str}\033[0m" : str
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
alias_method :grey, :bright_black
|
101
|
-
alias_method :gray, :bright_black
|
102
|
-
|
103
|
-
require 'set'
|
104
|
-
VALID_COLORS = Set.new(
|
105
|
-
COLORS.keys +
|
106
|
-
COLORS.keys.map{|k| "bright_#{k}" } +
|
107
|
-
["grey", "gray"]
|
108
|
-
)
|
109
|
-
|
110
|
-
def bold(text)
|
111
|
-
Pry.color ? "\e[1m#{text}\e[0m" : text
|
112
|
-
end
|
113
|
-
|
114
|
-
#
|
115
|
-
# Colorize a string that has "color tags".
|
116
|
-
#
|
117
|
-
# Examples:
|
118
|
-
# puts colorize("<light_green><magenta>*</magenta> Hey mom! I am <light_blue>SO</light_blue> colored right now.</light_green>")
|
119
|
-
#
|
120
|
-
def colorize(string)
|
121
|
-
stack = []
|
122
|
-
|
123
|
-
# split the string into tags and literal strings
|
124
|
-
tokens = string.split(/(<\/?[\w\d_]+>)/)
|
125
|
-
tokens.delete_if { |token| token.size == 0 }
|
126
|
-
|
127
|
-
result = ""
|
128
|
-
|
129
|
-
tokens.each do |token|
|
130
|
-
|
131
|
-
# token is an opening tag!
|
132
|
-
|
133
|
-
if /<([\w\d_]+)>/ =~ token and VALID_COLORS.include?($1) #valid_tag?($1)
|
134
|
-
stack.push $1
|
135
|
-
|
136
|
-
# token is a closing tag!
|
137
|
-
|
138
|
-
elsif /<\/([\w\d_]+)>/ =~ token and VALID_COLORS.include?($1) # valid_tag?($1)
|
139
|
-
|
140
|
-
# if this color is on the stack somwehere...
|
141
|
-
if pos = stack.rindex($1)
|
142
|
-
# close the tag by removing it from the stack
|
143
|
-
stack.delete_at pos
|
144
|
-
else
|
145
|
-
raise "Error: tried to close an unopened color tag -- #{token}"
|
146
|
-
end
|
147
|
-
|
148
|
-
# token is a literal string!
|
149
|
-
|
150
|
-
else
|
151
|
-
|
152
|
-
color = (stack.last || "white")
|
153
|
-
#color = BBS_COLOR_TABLE[color.to_i] if color =~ /^\d+$/
|
154
|
-
result << send(color, token) # colorize the result
|
155
|
-
|
156
|
-
end
|
157
|
-
|
158
|
-
end
|
159
|
-
|
160
|
-
result
|
161
|
-
end
|
162
|
-
|
163
66
|
def highlight(string, regexp, highlight_color=:bright_yellow)
|
164
67
|
highlighted = string.gsub(regexp) { |match| "<#{highlight_color}>#{match}</#{highlight_color}>" }
|
165
68
|
end
|