Skip to content

Commit a8e5cc7

Browse files
authored
Easter egg for autocomplete mode (#737)
* Show easter-egg inside document dialog in autocomplete mode * Show more easter_egg(dancing or logo) when Alt+d is pressed in autocomplete mode
1 parent 4b7dcdf commit a8e5cc7

File tree

3 files changed

+71
-10
lines changed

3 files changed

+71
-10
lines changed

lib/irb/easter-egg.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,21 @@ def render_frame(i)
9898
end
9999
end
100100

101+
private def easter_egg_logo(type)
102+
@easter_egg_logos ||= File.read(File.join(__dir__, 'ruby_logo.aa'), encoding: 'UTF-8:UTF-8')
103+
.split(/TYPE: ([A-Z]+)\n/)[1..]
104+
.each_slice(2)
105+
.to_h
106+
@easter_egg_logos[type.to_s.upcase]
107+
end
108+
101109
private def easter_egg(type = nil)
102110
type ||= [:logo, :dancing].sample
103111
case type
104112
when :logo
105-
File.open(File.join(__dir__, 'ruby_logo.aa')) do |f|
106-
require "rdoc"
107-
RDoc::RI::Driver.new.page do |io|
108-
IO.copy_stream(f, io)
109-
end
113+
require "rdoc"
114+
RDoc::RI::Driver.new.page do |io|
115+
io.write easter_egg_logo(:large)
110116
end
111117
when :dancing
112118
STDOUT.cooked do

lib/irb/input-method.rb

Lines changed: 17 additions & 5 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/) && !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

@@ -374,8 +379,15 @@ def show_doc_dialog_proc
374379
formatter.width = width
375380
dialog.trap_key = alt_d
376381
mod_key = RUBY_PLATFORM.match?(/darwin/) ? "Option" : "Alt"
377-
message = "Press #{mod_key}+d to read the full document"
378-
contents = [message] + doc.accept(formatter).split("\n")
382+
if show_easter_egg
383+
type = STDOUT.external_encoding == Encoding::UTF_8 ? :unicode : :ascii
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
387+
else
388+
message = "Press #{mod_key}+d to read the full document"
389+
contents = [message] + doc.accept(formatter).split("\n")
390+
end
379391
contents = contents.take(preferred_dialog_height)
380392

381393
y = cursor_pos_to_render.y

lib/irb/ruby_logo.aa

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
TYPE: LARGE
12

23
-+smJYYN?mm-
34
HB"BBYT TQg NggT
@@ -35,3 +36,45 @@
3536
m7 NW H N HSVO1z=?11-
3637
NgTH bB kH WBHWWHBHWmQgg&gggggNNN
3738
NNggggggNN
39+
TYPE: ASCII
40+
,,,;;;;''''';;;'';,
41+
,,;'' ';;,;;; ',
42+
,,'' ;;'';'''';;;;;;
43+
,;' ;; ',, ;
44+
,;' ,;' ';, ;
45+
;' ,;; ',,,;
46+
,' ,;;,,,,,,,,,,,;;;;
47+
;' ;;';;;; ,;;
48+
;' ,;' ;; '',, ,;;;
49+
;; ,;' ; '';, ,; ;'
50+
;; ,;;' ;; ;; ;;
51+
;;, ,,;;' ; ;'; ;;
52+
;';;,,,,;;;;;;;,,, ;; ,' ; ;;
53+
; ;;''' ,;'; ''';,,, ; ,;' ;;;;
54+
;;;;, ; '; ''';;;' ';;;
55+
;'; ;, ;' '; ,;' ', ;;;
56+
;;; ; ,; '; ,,' ',, ;;
57+
;;; '; ;' ';,,'' ';,;;
58+
'; ';,; ,,;''''''''';;;;;;,,;;;
59+
';,,;;,,;;;;;;;;;;''''''''''''''
60+
TYPE: UNICODE
61+
⣀⣤⣴⣾⣿⣿⣿⡛⠛⠛⠛⠛⣻⣿⠿⠛⠛⠶⣤⡀
62+
⣀⣴⠾⠛⠉⠁ ⠙⣿⣶⣤⣶⣟⣉ ⠈⠻⣦
63+
⣀⣴⠟⠋ ⢸⣿⠟⠻⣯⡙⠛⠛⠛⠶⠶⠶⢶⣽⣇
64+
⣠⡾⠋⠁ ⣾⡿ ⠈⠛⢦⣄ ⣿
65+
⣠⡾⠋ ⣰⣿⠃ ⠙⠷⣤⡀ ⣿
66+
⢀⡾⠋ ⣰⣿⡏ ⠈⠻⣦⣄⢠⣿
67+
⣰⠟⠁ ⣴⣿⣿⣁⣀⣠⣤⣤⣤⣤⣤⣤⣤⣴⠶⠿⣿⡏
68+
⣼⠏ ⢀⣾⣿⠟⣿⠿⣯⣍⠁ ⣰⣿⡇
69+
⢀⣼⠋ ⢀⣴⣿⠟⠁ ⢸⡇ ⠙⠻⢦⣄⡀ ⢠⡿⣿⡇
70+
⢀⣾⡏ ⢀⣴⣿⠟⠁ ⣿ ⠉⠻⢶⣄⡀⣰⡟ ⣿⠃
71+
⣾⣿⠁ ⣠⣶⡿⠋⠁ ⢹⡇ ⠈⣿⡏ ⢸⣿
72+
⣿⣿⡆ ⢀⣠⣴⣿⡿⠋ ⠈⣿ ⢀⡾⠋⣿ ⢸⣿
73+
⣿⠸⣿⣶⣤⣤⣤⣤⣶⣾⠿⠿⣿⣿⠶⣤⣤⣀⡀ ⢹⡇ ⣴⠟⠁ ⣿⡀⢸⣿
74+
⣿⢀⣿⣟⠛⠋⠉⠁ ⢰⡟⠹⣧ ⠈⠉⠛⠻⠶⢦⣤⣀⡀ ⠈⣿ ⣠⡾⠃ ⢸⡇⢸⡇
75+
⣿⣾⣿⢿⡄ ⣿⠁ ⠘⣧ ⠉⠙⠛⠷⣿⣿⡋ ⠸⣇⣸⡇
76+
⣿⠃⣿⠈⢿⡄ ⣸⠇ ⠘⣧ ⢀⣤⠾⠋⠈⠻⣦⡀ ⣿⣿⡇
77+
⣿⢸⡏ ⠈⣷⡀ ⢠⡿ ⠘⣧⡀ ⣠⡴⠟⠁ ⠈⠻⣦⣀ ⢿⣿⠁
78+
⢻⣾⡇ ⠘⣷ ⣼⠃ ⠘⣷⣠⣴⠟⠋ ⠙⢷⣄⢸⣿
79+
⠻⣧⡀ ⠘⣧⣰⡏ ⢀⣠⣤⠶⠛⠉⠛⠛⠛⠛⠛⠛⠻⢶⣶⣶⣶⣶⣶⣤⣤⣽⣿⣿
80+
⠈⠛⠷⢦⣤⣽⣿⣥⣤⣶⣶⡿⠿⠿⠶⠶⠶⠶⠾⠛⠛⠛⠛⠛⠛⠛⠋⠉⠉⠉⠉⠉⠉⠁

0 commit comments

Comments
 (0)