Skip to content

Commit aaae70d

Browse files
committed
Show more easter_egg(dancing or logo) when Alt+d is pressed in autocomplete mode
1 parent 1b2810e commit aaae70d

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lib/irb/input-method.rb

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,20 @@ def show_doc_dialog_proc
303303
return nil if result.nil? or pointer.nil? or pointer < 0
304304

305305
name = doc_namespace.call(result[pointer])
306+
show_easter_egg = name.match?(/\ARubyVM/) and not ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
306307

307308
options = {}
308309
options[:extra_doc_dirs] = IRB.conf[:EXTRA_DOC_DIRS] unless IRB.conf[:EXTRA_DOC_DIRS].empty?
309310
driver = RDoc::RI::Driver.new(options)
310311

311312
if key.match?(dialog.name)
312-
begin
313-
driver.display_names([name])
314-
rescue RDoc::RI::Driver::NotFoundError
313+
if show_easter_egg
314+
IRB.__send__(:easter_egg)
315+
else
316+
begin
317+
driver.display_names([name])
318+
rescue RDoc::RI::Driver::NotFoundError
319+
end
315320
end
316321
end
317322

@@ -372,16 +377,18 @@ def show_doc_dialog_proc
372377
end
373378
formatter = RDoc::Markup::ToAnsi.new
374379
formatter.width = width
375-
if name =~ /\ARubyVM/ and not ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
380+
dialog.trap_key = alt_d
381+
mod_key = RUBY_PLATFORM.match?(/darwin/) ? "Option" : "Alt"
382+
if show_easter_egg
376383
type = STDOUT.external_encoding == Encoding::UTF_8 ? :unicode : :ascii
377-
contents = IRB.send(:easter_egg_logo, type).split("\n").take(preferred_dialog_height)
384+
contents = IRB.send(:easter_egg_logo, type).split("\n")
385+
message = "Press #{mod_key}+d to see more"
386+
contents[0][0, message.size] = message
378387
else
379-
dialog.trap_key = alt_d
380-
mod_key = RUBY_PLATFORM.match?(/darwin/) ? "Option" : "Alt"
381388
message = "Press #{mod_key}+d to read the full document"
382389
contents = [message] + doc.accept(formatter).split("\n")
383-
contents = contents.take(preferred_dialog_height)
384390
end
391+
contents = contents.take(preferred_dialog_height)
385392

386393
y = cursor_pos_to_render.y
387394
Reline::DialogRenderInfo.new(pos: Reline::CursorPos.new(x, y), contents: contents, width: width, bg_color: '49')

0 commit comments

Comments
 (0)