Skip to content

Instantly share code, notes, and snippets.

@tk3369
Created September 8, 2020 05:59
Show Gist options
  • Save tk3369/30e2d28852a7c599250975faf0027994 to your computer and use it in GitHub Desktop.
Save tk3369/30e2d28852a7c599250975faf0027994 to your computer and use it in GitHub Desktop.
Bounce text in a terminal!
using TerminalUserInterfaces
const TUI = TerminalUserInterfaces
function bounce(str; delay = 0.08)
TUI.initialize()
try
terminal = TUI.Terminal()
width, height = TUI.terminal_size()
len = length(str)
endcol = width - len - 1
row = height ÷ 2
str2 = " $str "
left_to_right = true
while true
range = left_to_right ? (1:endcol) : (endcol:-1:1)
for col in range
TUI.move_cursor(row, col)
print(str2)
sleep(delay)
TUI.get_event(terminal) !== nothing && return
end
left_to_right = !left_to_right
end
finally
TUI.cleanup()
end
end
bounce("Hello World")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment