pry 0.9.10 → 0.9.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. data/.travis.yml +3 -1
  2. data/CHANGELOG +60 -1
  3. data/CONTRIBUTORS +43 -25
  4. data/Gemfile +7 -0
  5. data/Guardfile +62 -0
  6. data/README.markdown +4 -4
  7. data/Rakefile +34 -35
  8. data/lib/pry.rb +107 -54
  9. data/lib/pry/cli.rb +34 -11
  10. data/lib/pry/code.rb +165 -182
  11. data/lib/pry/code/code_range.rb +70 -0
  12. data/lib/pry/code/loc.rb +92 -0
  13. data/lib/pry/code_object.rb +153 -0
  14. data/lib/pry/command.rb +160 -22
  15. data/lib/pry/command_set.rb +37 -26
  16. data/lib/pry/commands.rb +4 -27
  17. data/lib/pry/commands/amend_line.rb +99 -0
  18. data/lib/pry/commands/bang.rb +20 -0
  19. data/lib/pry/commands/bang_pry.rb +17 -0
  20. data/lib/pry/commands/cat.rb +53 -0
  21. data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  22. data/lib/pry/commands/cat/exception_formatter.rb +78 -0
  23. data/lib/pry/commands/cat/file_formatter.rb +84 -0
  24. data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  25. data/lib/pry/commands/cd.rb +30 -0
  26. data/lib/pry/commands/code_collector.rb +165 -0
  27. data/lib/pry/commands/deprecated_commands.rb +2 -0
  28. data/lib/pry/commands/disable_pry.rb +27 -0
  29. data/lib/pry/commands/easter_eggs.rb +112 -0
  30. data/lib/pry/commands/edit.rb +206 -0
  31. data/lib/pry/commands/edit/exception_patcher.rb +25 -0
  32. data/lib/pry/commands/edit/file_and_line_locator.rb +38 -0
  33. data/lib/pry/commands/edit/method_patcher.rb +122 -0
  34. data/lib/pry/commands/exit.rb +42 -0
  35. data/lib/pry/commands/exit_all.rb +29 -0
  36. data/lib/pry/commands/exit_program.rb +24 -0
  37. data/lib/pry/commands/find_method.rb +199 -0
  38. data/lib/pry/commands/fix_indent.rb +19 -0
  39. data/lib/pry/commands/gem_cd.rb +26 -0
  40. data/lib/pry/commands/gem_install.rb +29 -0
  41. data/lib/pry/commands/gem_list.rb +33 -0
  42. data/lib/pry/commands/gem_open.rb +29 -0
  43. data/lib/pry/commands/gist.rb +95 -0
  44. data/lib/pry/commands/help.rb +164 -0
  45. data/lib/pry/commands/hist.rb +161 -0
  46. data/lib/pry/commands/import_set.rb +22 -0
  47. data/lib/pry/commands/install_command.rb +51 -0
  48. data/lib/pry/commands/jump_to.rb +29 -0
  49. data/lib/pry/commands/ls.rb +339 -0
  50. data/lib/pry/commands/nesting.rb +25 -0
  51. data/lib/pry/commands/play.rb +69 -0
  52. data/lib/pry/commands/pry_backtrace.rb +26 -0
  53. data/lib/pry/commands/pry_version.rb +17 -0
  54. data/lib/pry/commands/raise_up.rb +32 -0
  55. data/lib/pry/commands/reload_code.rb +39 -0
  56. data/lib/pry/commands/reset.rb +18 -0
  57. data/lib/pry/commands/ri.rb +56 -0
  58. data/lib/pry/commands/save_file.rb +61 -0
  59. data/lib/pry/commands/shell_command.rb +43 -0
  60. data/lib/pry/commands/shell_mode.rb +27 -0
  61. data/lib/pry/commands/show_doc.rb +78 -0
  62. data/lib/pry/commands/show_info.rb +139 -0
  63. data/lib/pry/commands/show_input.rb +17 -0
  64. data/lib/pry/commands/show_source.rb +37 -0
  65. data/lib/pry/commands/simple_prompt.rb +22 -0
  66. data/lib/pry/commands/stat.rb +40 -0
  67. data/lib/pry/commands/switch_to.rb +23 -0
  68. data/lib/pry/commands/toggle_color.rb +20 -0
  69. data/lib/pry/commands/whereami.rb +114 -0
  70. data/lib/pry/commands/wtf.rb +57 -0
  71. data/lib/pry/completion.rb +120 -46
  72. data/lib/pry/config.rb +11 -0
  73. data/lib/pry/core_extensions.rb +27 -16
  74. data/lib/pry/editor.rb +129 -0
  75. data/lib/pry/helpers.rb +1 -0
  76. data/lib/pry/helpers/base_helpers.rb +89 -119
  77. data/lib/pry/helpers/command_helpers.rb +6 -121
  78. data/lib/pry/helpers/table.rb +100 -0
  79. data/lib/pry/helpers/text.rb +4 -4
  80. data/lib/pry/history_array.rb +5 -0
  81. data/lib/pry/hooks.rb +1 -3
  82. data/lib/pry/indent.rb +104 -30
  83. data/lib/pry/method.rb +66 -22
  84. data/lib/pry/module_candidate.rb +26 -15
  85. data/lib/pry/pager.rb +70 -0
  86. data/lib/pry/plugins.rb +1 -2
  87. data/lib/pry/pry_class.rb +63 -22
  88. data/lib/pry/pry_instance.rb +58 -37
  89. data/lib/pry/rubygem.rb +74 -0
  90. data/lib/pry/terminal_info.rb +43 -0
  91. data/lib/pry/test/helper.rb +185 -0
  92. data/lib/pry/version.rb +1 -1
  93. data/lib/pry/wrapped_module.rb +58 -24
  94. data/pry.gemspec +21 -37
  95. data/{test/test_cli.rb → spec/cli_spec.rb} +0 -0
  96. data/spec/code_object_spec.rb +277 -0
  97. data/{test/test_code.rb → spec/code_spec.rb} +19 -1
  98. data/{test/test_command_helpers.rb → spec/command_helpers_spec.rb} +0 -0
  99. data/{test/test_command_integration.rb → spec/command_integration_spec.rb} +38 -46
  100. data/{test/test_command_set.rb → spec/command_set_spec.rb} +18 -1
  101. data/{test/test_command.rb → spec/command_spec.rb} +250 -149
  102. data/spec/commands/amend_line_spec.rb +247 -0
  103. data/spec/commands/bang_spec.rb +19 -0
  104. data/spec/commands/cat_spec.rb +164 -0
  105. data/spec/commands/cd_spec.rb +250 -0
  106. data/spec/commands/disable_pry_spec.rb +25 -0
  107. data/spec/commands/edit_spec.rb +727 -0
  108. data/spec/commands/exit_all_spec.rb +34 -0
  109. data/spec/commands/exit_program_spec.rb +19 -0
  110. data/spec/commands/exit_spec.rb +34 -0
  111. data/{test/test_default_commands/test_find_method.rb → spec/commands/find_method_spec.rb} +27 -7
  112. data/spec/commands/gem_list_spec.rb +26 -0
  113. data/spec/commands/gist_spec.rb +75 -0
  114. data/{test/test_default_commands/test_help.rb → spec/commands/help_spec.rb} +8 -9
  115. data/spec/commands/hist_spec.rb +181 -0
  116. data/spec/commands/jump_to_spec.rb +15 -0
  117. data/spec/commands/ls_spec.rb +177 -0
  118. data/spec/commands/play_spec.rb +140 -0
  119. data/spec/commands/raise_up_spec.rb +56 -0
  120. data/spec/commands/save_file_spec.rb +177 -0
  121. data/spec/commands/show_doc_spec.rb +378 -0
  122. data/spec/commands/show_input_spec.rb +17 -0
  123. data/spec/commands/show_source_spec.rb +597 -0
  124. data/spec/commands/whereami_spec.rb +154 -0
  125. data/spec/completion_spec.rb +233 -0
  126. data/spec/control_d_handler_spec.rb +58 -0
  127. data/spec/editor_spec.rb +79 -0
  128. data/{test/test_exception_whitelist.rb → spec/exception_whitelist_spec.rb} +0 -0
  129. data/{test → spec/fixtures}/candidate_helper1.rb +0 -0
  130. data/{test → spec/fixtures}/candidate_helper2.rb +0 -0
  131. data/{test/test_default_commands → spec/fixtures}/example.erb +0 -0
  132. data/spec/fixtures/example_nesting.rb +33 -0
  133. data/spec/fixtures/show_source_doc_examples.rb +15 -0
  134. data/{test → spec/fixtures}/testrc +0 -0
  135. data/{test → spec/fixtures}/testrcbad +0 -0
  136. data/spec/helper.rb +34 -0
  137. data/spec/helpers/bacon.rb +86 -0
  138. data/spec/helpers/mock_pry.rb +43 -0
  139. data/spec/helpers/table_spec.rb +83 -0
  140. data/{test/test_history_array.rb → spec/history_array_spec.rb} +21 -19
  141. data/{test/test_hooks.rb → spec/hooks_spec.rb} +0 -0
  142. data/{test/test_indent.rb → spec/indent_spec.rb} +24 -0
  143. data/{test/test_input_stack.rb → spec/input_stack_spec.rb} +4 -0
  144. data/{test/test_method.rb → spec/method_spec.rb} +65 -1
  145. data/{test/test_prompt.rb → spec/prompt_spec.rb} +0 -0
  146. data/{test/test_pry_defaults.rb → spec/pry_defaults_spec.rb} +14 -14
  147. data/{test/test_pry_history.rb → spec/pry_history_spec.rb} +15 -0
  148. data/spec/pry_output_spec.rb +95 -0
  149. data/{test/test_pry.rb → spec/pry_spec.rb} +74 -32
  150. data/{test/test_sticky_locals.rb → spec/sticky_locals_spec.rb} +27 -25
  151. data/{test/test_syntax_checking.rb → spec/syntax_checking_spec.rb} +17 -1
  152. data/{test/test_wrapped_module.rb → spec/wrapped_module_spec.rb} +92 -5
  153. metadata +236 -112
  154. data/examples/example_basic.rb +0 -15
  155. data/examples/example_command_override.rb +0 -32
  156. data/examples/example_commands.rb +0 -36
  157. data/examples/example_hooks.rb +0 -9
  158. data/examples/example_image_edit.rb +0 -67
  159. data/examples/example_input.rb +0 -7
  160. data/examples/example_input2.rb +0 -29
  161. data/examples/example_output.rb +0 -11
  162. data/examples/example_print.rb +0 -6
  163. data/examples/example_prompt.rb +0 -9
  164. data/examples/helper.rb +0 -6
  165. data/lib/pry/default_commands/cd.rb +0 -81
  166. data/lib/pry/default_commands/commands.rb +0 -62
  167. data/lib/pry/default_commands/context.rb +0 -98
  168. data/lib/pry/default_commands/easter_eggs.rb +0 -95
  169. data/lib/pry/default_commands/editing.rb +0 -420
  170. data/lib/pry/default_commands/find_method.rb +0 -169
  171. data/lib/pry/default_commands/gems.rb +0 -84
  172. data/lib/pry/default_commands/gist.rb +0 -187
  173. data/lib/pry/default_commands/help.rb +0 -127
  174. data/lib/pry/default_commands/hist.rb +0 -120
  175. data/lib/pry/default_commands/input_and_output.rb +0 -306
  176. data/lib/pry/default_commands/introspection.rb +0 -410
  177. data/lib/pry/default_commands/ls.rb +0 -272
  178. data/lib/pry/default_commands/misc.rb +0 -38
  179. data/lib/pry/default_commands/navigating_pry.rb +0 -110
  180. data/lib/pry/default_commands/whereami.rb +0 -92
  181. data/lib/pry/extended_commands/experimental.rb +0 -7
  182. data/test/helper.rb +0 -223
  183. data/test/test_completion.rb +0 -62
  184. data/test/test_control_d_handler.rb +0 -45
  185. data/test/test_default_commands/test_cd.rb +0 -321
  186. data/test/test_default_commands/test_context.rb +0 -288
  187. data/test/test_default_commands/test_documentation.rb +0 -315
  188. data/test/test_default_commands/test_gems.rb +0 -18
  189. data/test/test_default_commands/test_input.rb +0 -428
  190. data/test/test_default_commands/test_introspection.rb +0 -511
  191. data/test/test_default_commands/test_ls.rb +0 -151
  192. data/test/test_default_commands/test_shell.rb +0 -343
  193. data/test/test_default_commands/test_show_source.rb +0 -432
  194. data/test/test_pry_output.rb +0 -41
@@ -0,0 +1,84 @@
1
+ class Pry
2
+ class Command::Cat
3
+ class FileFormatter < AbstractFormatter
4
+ attr_accessor :file_with_embedded_line
5
+ attr_accessor :opts
6
+ attr_accessor :_pry_
7
+
8
+ def initialize(file_with_embedded_line, _pry_, opts)
9
+ @file_with_embedded_line = file_with_embedded_line
10
+ @opts = opts
11
+ @_pry_ = _pry_
12
+ end
13
+
14
+ def format
15
+ raise CommandError, "Must provide a filename, --in, or --ex." if !file_with_embedded_line
16
+
17
+ set_file_and_dir_locals(file_name, _pry_, _pry_.current_context)
18
+ decorate(Pry::Code.from_file(file_name))
19
+ end
20
+
21
+ private
22
+
23
+ def file_and_line
24
+ file_name, line_num = file_with_embedded_line.split(':')
25
+
26
+ [File.expand_path(file_name), line_num ? line_num.to_i : nil]
27
+ end
28
+
29
+ def file_name
30
+ file_and_line.first
31
+ end
32
+
33
+ def line_number
34
+ file_and_line.last
35
+ end
36
+
37
+ def code_window_size
38
+ Pry.config.default_window_size || 7
39
+ end
40
+
41
+ def decorate(content)
42
+ line_number ? super.around(line_number, code_window_size) : super
43
+ end
44
+
45
+ def code_type
46
+ opts[:type] || detect_code_type_from_file(file_name)
47
+ end
48
+
49
+ def detect_code_type_from_file(file_name)
50
+ name, ext = File.basename(file_name).split('.', 2)
51
+
52
+ if ext
53
+ case ext
54
+ when "py"
55
+ :python
56
+ when "rb", "gemspec", "rakefile", "ru", "pryrc", "irbrc"
57
+ :ruby
58
+ when "js"
59
+ return :javascript
60
+ when "yml", "prytheme"
61
+ :yaml
62
+ when "groovy"
63
+ :groovy
64
+ when "c"
65
+ :c
66
+ when "cpp"
67
+ :cpp
68
+ when "java"
69
+ :java
70
+ else
71
+ :text
72
+ end
73
+ else
74
+ case name
75
+ when "Rakefile", "Gemfile"
76
+ :ruby
77
+ else
78
+ :text
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,43 @@
1
+ class Pry
2
+ class Command::Cat
3
+ class InputExpressionFormatter < AbstractFormatter
4
+ attr_accessor :input_expressions
5
+ attr_accessor :opts
6
+
7
+ def initialize(input_expressions, opts)
8
+ @input_expressions = input_expressions
9
+ @opts = opts
10
+ end
11
+
12
+ def format
13
+ raise CommandError, "No input expressions!" if numbered_input_items.length < 1
14
+
15
+ if numbered_input_items.length > 1
16
+ content = ""
17
+ numbered_input_items.each do |i, s|
18
+ content << "#{Helpers::Text.bold(i.to_s)}:\n" << decorate(Pry::Code(s).with_indentation(2)).to_s
19
+ end
20
+
21
+ content
22
+ else
23
+ decorate(Pry::Code(selected_input_items.first)).to_s
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def selected_input_items
30
+ input_expressions[normalized_expression_range] || []
31
+ end
32
+
33
+ def numbered_input_items
34
+ @numbered_input_items ||= normalized_expression_range.zip(selected_input_items).
35
+ reject { |_, s| s.nil? || s == "" }
36
+ end
37
+
38
+ def normalized_expression_range
39
+ absolute_index_range(opts[:i], input_expressions.length)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,30 @@
1
+ class Pry
2
+ class Command::Cd < Pry::ClassCommand
3
+ match 'cd'
4
+ group 'Context'
5
+ description 'Move into a new context (object or scope).'
6
+
7
+ banner <<-'BANNER'
8
+ Usage: cd [OPTIONS] [--help]
9
+
10
+ Move into new context (object or scope). As in UNIX shells use `cd ..` to go
11
+ back, `cd /` to return to Pry top-level and `cd -` to toggle between last two
12
+ scopes. Complex syntax (e.g `cd ../@x/y`) also supported.
13
+
14
+ cd @x
15
+ cd ..
16
+ cd /
17
+ cd -
18
+
19
+ https://github.com/pry/pry/wiki/State-navigation#wiki-Changing_scope
20
+ BANNER
21
+
22
+ def process
23
+ state.old_stack ||= []
24
+ stack, state.old_stack = context_from_object_path(arg_string, _pry_, state.old_stack)
25
+ _pry_.binding_stack = stack if stack
26
+ end
27
+ end
28
+
29
+ Pry::Commands.add_command(Pry::Command::Cd)
30
+ end
@@ -0,0 +1,165 @@
1
+ class Pry
2
+ class Command::CodeCollector
3
+ include Helpers::CommandHelpers
4
+
5
+ attr_accessor :args
6
+ attr_accessor :opts
7
+ attr_accessor :_pry_
8
+
9
+ # The name of the explicitly given file (if any).
10
+ attr_accessor :file
11
+
12
+ class << self
13
+ attr_accessor :input_expression_ranges
14
+ attr_accessor :output_result_ranges
15
+ end
16
+
17
+ @input_expression_ranges = []
18
+ @output_result_ranges = []
19
+
20
+ def initialize(args, opts, _pry_)
21
+ @args = args
22
+ @opts = opts
23
+ @_pry_ = _pry_
24
+ end
25
+
26
+ # Add the `--lines`, `-o`, `-i`, `-s`, `-d` options.
27
+ def self.inject_options(opt)
28
+ @input_expression_ranges = []
29
+ @output_result_ranges = []
30
+
31
+ opt.on :l, :lines, "Restrict to a subset of lines. Takes a line number or range",
32
+ :optional_argument => true, :as => Range, :default => 1..-1
33
+ opt.on :o, :out, "Select lines from Pry's output result history. Takes an index or range",
34
+ :optional_argument => true, :as => Range, :default => -5..-1 do |r|
35
+ output_result_ranges << (r || (-5..-1))
36
+ end
37
+ opt.on :i, :in, "Select lines from Pry's input expression history. Takes an index or range",
38
+ :optional_argument => true, :as => Range, :default => -5..-1 do |r|
39
+ input_expression_ranges << (r || (-5..-1))
40
+ end
41
+ opt.on :s, :super, "Select the 'super' method. Can be repeated to traverse the ancestors",
42
+ :as => :count
43
+ opt.on :d, :doc, "Select lines from the code object's documentation"
44
+ end
45
+
46
+ # The content (i.e code/docs) for the selected object.
47
+ # If the user provided a bare code object, it returns the source.
48
+ # If the user provided the `-i` or `-o` switches, it returns the
49
+ # selected input/output lines joined as a string. If the user used
50
+ # `-d CODE_OBJECT` it returns the docs for that code object.
51
+ #
52
+ # @return [String]
53
+ def content
54
+ return @content if @content
55
+ raise CommandError, "Only one of --out, --in, --doc and CODE_OBJECT may be specified." if bad_option_combination?
56
+
57
+ content = case
58
+ when opts.present?(:o)
59
+ pry_output_content
60
+ when opts.present?(:i)
61
+ pry_input_content
62
+ when opts.present?(:d)
63
+ code_object_doc
64
+ else
65
+ code_object_source_or_file
66
+ end
67
+
68
+ @content ||= restrict_to_lines(content, line_range)
69
+ end
70
+
71
+ # The code object
72
+ #
73
+ # @return [Pry::WrappedModule, Pry::Method, Pry::Command]
74
+ def code_object
75
+ Pry::CodeObject.lookup(obj_name, _pry_, :super => opts[:super])
76
+ end
77
+
78
+ # Given a string and a range, return the `range` lines of that
79
+ # string.
80
+ #
81
+ # @param [String] content
82
+ # @param [Range, Fixnum] range
83
+ # @return [String] The string restricted to the given range
84
+ def restrict_to_lines(content, range)
85
+ Array(content.lines.to_a[range]).join
86
+ end
87
+
88
+ # The selected `_pry_.output_array` as a string, as specified by
89
+ # the `-o` switch.
90
+ #
91
+ # @return [String]
92
+ def pry_output_content
93
+ pry_array_content_as_string(_pry_.output_array, self.class.output_result_ranges) do |v|
94
+ Pry.config.gist.inspecter.call(v)
95
+ end
96
+ end
97
+
98
+ # The selected `_pry_.input_array` as a string, as specified by
99
+ # the `-i` switch.
100
+ #
101
+ # @return [String]
102
+ def pry_input_content
103
+ pry_array_content_as_string(_pry_.input_array, self.class.input_expression_ranges) { |v| v }
104
+ end
105
+
106
+ # The line range passed to `--lines`, converted to a 0-indexed range.
107
+ def line_range
108
+ opts.present?(:lines) ? one_index_range_or_number(opts[:lines]) : 0..-1
109
+ end
110
+
111
+ # Name of the object argument
112
+ def obj_name
113
+ @obj_name ||= args.empty? ? no_arg : args.join(" ")
114
+ end
115
+
116
+ private
117
+
118
+ def bad_option_combination?
119
+ [opts.present?(:in), opts.present?(:out),
120
+ !args.empty?].count(true) > 1
121
+ end
122
+
123
+ def pry_array_content_as_string(array, ranges, &block)
124
+ all = ''
125
+ ranges.each do |range|
126
+ raise CommandError, "Minimum value for range is 1, not 0." if convert_to_range(range).first == 0
127
+
128
+ ranged_array = Array(array[range]) || []
129
+ ranged_array.compact.each { |v| all << block.call(v) }
130
+ end
131
+
132
+ all
133
+ end
134
+
135
+ def code_object_doc
136
+ (code_object && code_object.doc) or could_not_locate(obj_name)
137
+ end
138
+
139
+ def code_object_source_or_file
140
+ (code_object && code_object.source) || file_content
141
+ end
142
+
143
+ def file_content
144
+ if File.exists?(obj_name)
145
+ # Set the file accessor.
146
+ self.file = obj_name
147
+ File.read(obj_name)
148
+ else
149
+ could_not_locate(obj_name)
150
+ end
151
+ end
152
+
153
+ def could_not_locate(name)
154
+ raise CommandError, "Cannot locate: #{name}!"
155
+ end
156
+
157
+ def convert_to_range(n)
158
+ if !n.is_a?(Range)
159
+ (n..n)
160
+ else
161
+ n
162
+ end
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,2 @@
1
+ Pry::Commands.deprecated_command("edit-method", "Use `edit` instead.")
2
+ Pry::Commands.deprecated_command("show-command", "Use show-source [command_name] instead.")
@@ -0,0 +1,27 @@
1
+ class Pry
2
+ class Command::DisablePry < Pry::ClassCommand
3
+ match 'disable-pry'
4
+ group 'Navigating Pry'
5
+ description 'Stops all future calls to pry and exits the current session.'
6
+
7
+ banner <<-'BANNER'
8
+ Usage: disable-pry
9
+
10
+ After this command is run any further calls to pry will immediately return `nil`
11
+ without interrupting the flow of your program. This is particularly useful when
12
+ you've debugged the problem you were having, and now wish the program to run to
13
+ the end.
14
+
15
+ As alternatives, consider using `exit!` to force the current Ruby process
16
+ to quit immediately; or using `edit-method -p` to remove the `binding.pry`
17
+ from the code.
18
+ BANNER
19
+
20
+ def process
21
+ ENV['DISABLE_PRY'] = 'true'
22
+ _pry_.run_command "exit"
23
+ end
24
+ end
25
+
26
+ Pry::Commands.add_command(Pry::Command::DisablePry)
27
+ end
@@ -0,0 +1,112 @@
1
+ class Pry
2
+ Pry::Commands.instance_eval do
3
+ command "nyan-cat", "", :requires_gem => ["nyancat"] do
4
+ run ".nyancat"
5
+ end
6
+
7
+ command(/!s\/(.*?)\/(.*?)/, "") do |source, dest|
8
+ eval_string.gsub!(/#{source}/) { dest }
9
+ run "show-input"
10
+ end
11
+
12
+ command "get-naked", "" do
13
+ text = %{
14
+ --
15
+ We dont have to take our clothes off to have a good time.
16
+ We could dance & party all night And drink some cherry wine.
17
+ -- Jermaine Stewart }
18
+ output.puts text
19
+ text
20
+ end
21
+
22
+ command "east-coker", "" do
23
+ text = %{
24
+ --
25
+ Now the light falls
26
+ Across the open field, leaving the deep lane
27
+ Shuttered with branches, dark in the afternoon,
28
+ Where you lean against a bank while a van passes,
29
+ And the deep lane insists on the direction
30
+ Into the village, in the electric heat
31
+ Hypnotised. In a warm haze the sultry light
32
+ Is absorbed, not refracted, by grey stone.
33
+ The dahlias sleep in the empty silence.
34
+ Wait for the early owl.
35
+ -- T.S Eliot
36
+ }
37
+ output.puts text
38
+ text
39
+ end
40
+
41
+ command "cohen-poem", "" do
42
+ text = %{
43
+ --
44
+ When this American woman,
45
+ whose thighs are bound in casual red cloth,
46
+ comes thundering past my sitting place
47
+ like a forest-burning Mongol tribe,
48
+ the city is ravished
49
+ and brittle buildings of a hundred years
50
+ splash into the street;
51
+ and my eyes are burnt
52
+ for the embroidered Chinese girls,
53
+ already old,
54
+ and so small between the thin pines
55
+ on these enormous landscapes,
56
+ that if you turn your head
57
+ they are lost for hours.
58
+ -- Leonard Cohen
59
+ }
60
+ output.puts text
61
+ text
62
+ end
63
+
64
+ command "pessoa-poem", "" do
65
+ output.puts <<-TEXT
66
+ --
67
+ I've gone to bed with every feeling,
68
+ I've been the pimp of every emotion,
69
+ All felt sensations have bought me drinks,
70
+ I've traded glances with every motive for every act,
71
+ I've held hands with every urge to depart,
72
+ ..
73
+ Rage, foam, the vastness that doesn't fit in my handkerchief,
74
+ The dog in heat howling in the night,
75
+ The pond from the farm going in circles around my insomnia,
76
+ The woods as they were, on our late-afternoon walks, the rose,
77
+ The indifferent tuft of hair, the moss, the pines,
78
+ The rage of not containing all this, not retaining all this,
79
+ O abstract hunger for things, impotent libido for moments,
80
+ Intellectual orgy of feeling life!
81
+ -- Fernando Pessoa
82
+ TEXT
83
+ end
84
+
85
+ command "test-ansi", "" do
86
+ prev_color = Pry.color
87
+ Pry.color = true
88
+
89
+ picture = unindent <<-'EOS'.gsub(/[[:alpha:]!]/) { |s| text.red(s) }
90
+ ____ _______________________
91
+ / \ | A W G |
92
+ / O O \ | N I O N ! |
93
+ | | | S S R I ! |
94
+ \ \__/ / __| I K ! |
95
+ \____/ \________________________|
96
+ EOS
97
+
98
+ if windows_ansi?
99
+ move_up = proc { |n| "\e[#{n}F" }
100
+ else
101
+ move_up = proc { |n| "\e[#{n}A\e[0G" }
102
+ end
103
+
104
+ output.puts "\n" * 6
105
+ output.puts picture.lines.map(&:chomp).reverse.join(move_up[1])
106
+ output.puts "\n" * 6
107
+ output.puts "** ENV['TERM'] is #{ENV['TERM']} **\n\n"
108
+
109
+ Pry.color = prev_color
110
+ end
111
+ end
112
+ end