Created
May 24, 2013 13:37
-
-
Save TobiX/5643558 to your computer and use it in GitHub Desktop.
Some crappy script I once did
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
#!/usr/bin/env ruby | |
# we do ECMA-48 / vt100 only - this may be portable or not... | |
TIOCGWINSZ = 0x5413 | |
Alternative = true | |
if !Alternative then | |
NormalPerson = [ | |
' o ', | |
'/O\\ ', | |
'/ \\ ' | |
] | |
LaolaPerson = [ | |
'\\o/ ', | |
' O ' | |
] | |
HalfPersonL = HalfPersonR = [ | |
' o ', | |
'~O~ ' | |
] | |
else | |
NormalPerson = [ | |
' o ', | |
'/O\\', | |
'/ \\' | |
] | |
LaolaPerson = [ | |
'\\o/', | |
' O ' | |
] | |
HalfPersonL = [ | |
' o/', | |
'/O ' | |
] | |
HalfPersonR = [ | |
'\\o ', | |
' O\\' | |
] | |
end | |
Save = "\e[s" | |
Restore = "\e[u" | |
NUp = "\e[%iA" | |
NDown = "\e[%iB" | |
NRight = "\e[%iC" | |
NLeft = "\e[%iD" | |
def termsize | |
size = nil | |
str = [ 0, 0, 0, 0 ].pack("SSSS") | |
if $stdin.ioctl(TIOCGWINSZ, str) >= 0 then | |
# Get rows, cols, xpixels, ypixels | |
size = str.unpack("SSSS") | |
else | |
raise "Unable to get window size" | |
end | |
size[0..1] | |
end | |
def draw_init | |
$stdout.sync = true | |
rows, cols = termsize | |
$nr = (cols - 1) / NormalPerson[0].length | |
NormalPerson.each do |line| | |
puts line * $nr | |
end | |
printf NUp + Save, NormalPerson.length | |
end | |
def draw_person(pers, pos) | |
return if pos < 0 || pos >= $nr | |
printf Restore | |
printf NRight, pos * pers[0].length if pos > 0 | |
pers.each do |line| | |
printf line + NLeft + NDown, line.length, 1 | |
end | |
end | |
draw_init | |
Signal.trap('WINCH') do | |
print Restore | |
draw_init | |
end | |
i = 0 | |
add = 1 | |
while true do | |
draw_person NormalPerson, i - 2 * add | |
draw_person HalfPersonL, i - 1 | |
draw_person LaolaPerson, i | |
draw_person HalfPersonR, i + 1 | |
i += add | |
sleep 0.25 | |
add = -add if i == ($nr - 1) || i == 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment