Skip to content

Commit

Permalink
Show more easter_egg(dancing or logo) when Alt+d is pressed in autoco…
Browse files Browse the repository at this point in the history
…mplete mode
  • Loading branch information
tompng committed Oct 22, 2023
1 parent 1b2810e commit 7669d40
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/irb/input-method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,20 @@ def show_doc_dialog_proc
return nil if result.nil? or pointer.nil? or pointer < 0

name = doc_namespace.call(result[pointer])
show_easter_egg = name.match?(/\ARubyVM/) && !ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']

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

if key.match?(dialog.name)
begin
driver.display_names([name])
rescue RDoc::RI::Driver::NotFoundError
if show_easter_egg
IRB.__send__(:easter_egg)
else
begin
driver.display_names([name])
rescue RDoc::RI::Driver::NotFoundError
end
end
end

Expand Down Expand Up @@ -372,16 +377,18 @@ def show_doc_dialog_proc
end
formatter = RDoc::Markup::ToAnsi.new
formatter.width = width
if name =~ /\ARubyVM/ and not ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
dialog.trap_key = alt_d
mod_key = RUBY_PLATFORM.match?(/darwin/) ? "Option" : "Alt"
if show_easter_egg
type = STDOUT.external_encoding == Encoding::UTF_8 ? :unicode : :ascii
contents = IRB.send(:easter_egg_logo, type).split("\n").take(preferred_dialog_height)
contents = IRB.send(:easter_egg_logo, type).split("\n")
message = "Press #{mod_key}+d to see more"
contents[0][0, message.size] = message
else
dialog.trap_key = alt_d
mod_key = RUBY_PLATFORM.match?(/darwin/) ? "Option" : "Alt"
message = "Press #{mod_key}+d to read the full document"
contents = [message] + doc.accept(formatter).split("\n")
contents = contents.take(preferred_dialog_height)
end
contents = contents.take(preferred_dialog_height)

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

0 comments on commit 7669d40

Please sign in to comment.