Created
September 8, 2020 05:59
-
-
Save tk3369/30e2d28852a7c599250975faf0027994 to your computer and use it in GitHub Desktop.
Bounce text in a terminal!
This file contains hidden or 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
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