Skip to content

Instantly share code, notes, and snippets.

@justinian
Created July 1, 2015 23:51
Show Gist options
  • Save justinian/c56a803829232f9e2a54 to your computer and use it in GitHub Desktop.
Save justinian/c56a803829232f9e2a54 to your computer and use it in GitHub Desktop.
Python rainbow marquee
#!/usr/bin/env python
import sys
colors = [160, 196, 202, 208, 214, 220, 226, 190, 154, 118, 46, 47, 48, 49, 51, 39, 27, 21, 57, 93]
ncolors = len(colors)
def reset():
sys.stdout.write("\033[?25h")
sys.stdout.write("\033[m")
def colorize(s, color):
sys.stdout.write("\033[38;5;%d;01m%s" % (color, s))
def scroll_iteration(i, width, message):
messagelen = len(message)
trail = width - (messagelen + i)
out = " " * i + message + " " * trail
sys.stdout.write("\r")
for i in range(width):
colorize(out[i], colors[i%ncolors])
import time
time.sleep(0.05)
def scroll(width, message):
sys.stdout.write("\033[?25l")
messagelen = len(message)
for i in range(width - messagelen, -1, -1):
scroll_iteration(i, width, message)
if __name__ == "__main__":
cols = int(sys.argv[1])
message = " ".join(sys.argv[2:])
try:
scroll(cols, message)
finally:
reset()
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment