Skip to content

Commit fc1c656

Browse files
committed
Improved ri --interactive
1 parent 291a4c6 commit fc1c656

File tree

3 files changed

+211
-111
lines changed

3 files changed

+211
-111
lines changed

History.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
* X Major Enhancements
44
* RDoc now automatically loads rdoc/discover.rb files from installed gems.
55
* RDoc now uses Michael Granger's Darkfish generator by default.
6-
* Various RDoc speedups by Hongli Lai. Patches #22555, #22556, #22557,
7-
#22562, #22565.
8-
* Moved unmaintained CHM generator to it's own package.
9-
* Moved unmaintained extra HTML templates to their own package.
10-
* Removed experimental texinfo generator.
6+
* Various rdoc generation speedups by Hongli Lai. Patches #22555, #22556,
7+
#22557, #22562, #22565.
118

129
* Y Minor Enhancements
1310
* Added a space after the commas in ri class method lists. RubyForge
1411
enhancement #22182.
12+
* Improved ri --interactive
1513
* Generators can now override generated file locations.
14+
* Moved unmaintained CHM generator to it's own package.
15+
* Moved unmaintained extra HTML templates to their own package.
16+
* Removed experimental texinfo generator.
1617
* Converted to minitest.
1718

1819
* Z Bug Fixes

lib/rdoc/ri/display.rb

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
require 'rdoc/ri'
22

3-
# readline support might not be present, so be careful
4-
# when requiring it.
5-
begin
6-
require('readline')
7-
require('abbrev')
8-
CAN_USE_READLINE = true # HACK use an RDoc namespace constant
9-
rescue LoadError
10-
CAN_USE_READLINE = false
11-
end
12-
133
##
144
# This is a kind of 'flag' module. If you want to write your own 'ri' display
155
# module (perhaps because you're writing an IDE), you write a class which
@@ -42,6 +32,8 @@ class RDoc::RI::DefaultDisplay
4232

4333
include RDoc::RI::Display
4434

35+
attr_reader :formatter
36+
4537
def initialize(formatter, width, use_stdout, output = $stdout)
4638
@use_stdout = use_stdout
4739
@formatter = formatter.new output, width, " "
@@ -126,51 +118,6 @@ def display_class_info(klass)
126118
# the methods.
127119

128120
def get_class_method_choice(method_map)
129-
if CAN_USE_READLINE then
130-
# prepare abbreviations for tab completion
131-
abbreviations = method_map.keys.abbrev
132-
Readline.completion_proc = proc do |string|
133-
abbreviations.values.uniq.grep(/^#{string}/)
134-
end
135-
end
136-
137-
@formatter.raw_print_line "\nEnter the method name you want.\n"
138-
@formatter.raw_print_line "Class methods can be preceeded by '::' and instance methods by '#'.\n"
139-
140-
if CAN_USE_READLINE
141-
@formatter.raw_print_line "You can use tab to autocomplete.\n"
142-
@formatter.raw_print_line "Enter a blank line to exit.\n"
143-
144-
choice_string = Readline.readline(">> ").strip
145-
else
146-
@formatter.raw_print_line "Enter a blank line to exit.\n"
147-
@formatter.raw_print_line ">> "
148-
choice_string = $stdin.gets.strip
149-
end
150-
151-
if choice_string == ''
152-
return nil
153-
else
154-
class_or_instance = method_map[choice_string]
155-
156-
if class_or_instance
157-
# If the user's choice is not preceeded by a '::' or a '#', figure
158-
# out whether they want a class or an instance method and decorate
159-
# the choice appropriately.
160-
if(choice_string =~ /^[a-zA-Z]/)
161-
if(class_or_instance == :class)
162-
choice_string = "::#{choice_string}"
163-
else
164-
choice_string = "##{choice_string}"
165-
end
166-
end
167-
168-
return choice_string
169-
else
170-
@formatter.raw_print_line "No method matched '#{choice_string}'.\n"
171-
return nil
172-
end
173-
end
174121
end
175122

176123
##
@@ -326,7 +273,7 @@ def display_params(method)
326273
# List the classes in +classes+.
327274

328275
def list_known_classes(classes)
329-
if classes.empty?
276+
if classes.empty? then
330277
warn_no_database
331278
else
332279
page do

0 commit comments

Comments
 (0)