Last active
May 20, 2024 08:41
-
-
Save tompng/cd9ac1094af96149cb1d6c907972de44 to your computer and use it in GitHub Desktop.
IRB theme RubyKaigi2024
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Reline::LineEditor.prepend Module.new { | |
eval <<~RUBY | |
def colorize_completion_dialog | |
#{(%W(d=@d ialogs[0]; (c=d&.cont ents | |
)&&(y=d.scroll _top ;f=R eline::Face[:c omplet | |
ion_di alog]; s=T ime .now.t o_f;c[ 0..]=c.i | |
nsta nce_ ev al{@o||=du p} .map {|t| e=t. inde | |
x(f[: en hanced]);x=0;l =t .gsub (/#e #[[^ | |
m]*m/,' ') .chars.map {" #e[48;5 ;${e ==0? | |
'210;1' :1 45+[(y +z =((4*s+ x+=1)/2).floor)% | |
2+z%5/3 <1? 0: 43, 6,41][( y%7-3)**2/4]};38 | |
;5;237m"+_1}*''; y+=1 ;t[1 ..][f[:scrollbar ]]&& | |
l[-1,0]="#e[38;5 ;203m";l}) )*'').tr'$#',?#+ ?\\} | |
end | |
RUBY | |
def update_dialogs(...) | |
super(...) | |
colorize_completion_dialog | |
end | |
def rerender | |
(@mutex ||= Mutex.new).synchronize { super } | |
end | |
} | |
Thread.new do | |
Reline.line_editor.instance_eval do | |
loop do | |
sleep 0.1 | |
colorize_completion_dialog && rerender | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
code = <<~'RUBY' | |
d=@dialogs[0]; | |
(c=d&.contents)&&( | |
y=d.scroll_top; | |
f=Reline::Face[:completion_dialog]; | |
s=Time.now.to_f; | |
c[0..]=c.instance_eval{@o||=dup}.map{|t| | |
e=t.index(f[:enhanced]); | |
x=0; | |
l=t.gsub(/\e\[[^m]*m/, '').chars.map{ | |
"\e[48;5;#{e==0?'210;1':145+[(y+z=((4*s+x+=1)/2).floor)%2+z%5/3<1?0:43,6,41][(y%7-3)**2/4]};38;5;237m"+_1 | |
}*''; | |
y+=1; | |
t[1..][f[:scrollbar]]&&l[-1,0]="\e[38;5;203m"; | |
l | |
} | |
) | |
RUBY | |
require 'ripper'; raise unless Ripper.sexp(code.split.join) | |
chars = ['#'] + "{(%W(#{code.tr("#\\",'$#')})*'').tr'$#',?#+?\\\\}".split.join.chars | |
puts DATA.read.gsub('#') { chars.shift||'#' } | |
__END__ | |
Reline::LineEditor.prepend Module.new { | |
eval <<~RUBY | |
def colorize_completion_dialog | |
########## ########## ########## #### | |
############## #### #### ############## ###### | |
###### ###### ### ### ###### ###### ######## | |
#### #### ## ########## ## #### #### #### #### | |
##### ## ############## ## ##### #### #### | |
####### ## ########## ## ####### #### #### | |
####### ## ###### ## ####### ################ | |
####### ### ## ### ####### ################ | |
################ #### #### ################ #### | |
################ ########## ################ #### | |
end | |
RUBY | |
def update_dialogs(...) | |
super(...) | |
colorize_completion_dialog | |
end | |
def rerender | |
(@mutex ||= Mutex.new).synchronize { super } | |
end | |
} | |
Thread.new do | |
Reline.line_editor.instance_eval do | |
loop do | |
sleep 0.1 | |
colorize_completion_dialog && rerender | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment