From e89bbaedaa6bce8be525cec4d19ca1521b86d6ab Mon Sep 17 00:00:00 2001 From: Mark Tearle Date: Sun, 27 Jun 2004 13:12:33 +0000 Subject: [PATCH] horizontal scrolling snippet --- codesnippets/horizscroll.py | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 codesnippets/horizscroll.py diff --git a/codesnippets/horizscroll.py b/codesnippets/horizscroll.py new file mode 100644 index 0000000..5dca529 --- /dev/null +++ b/codesnippets/horizscroll.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +import string +import sys +import time + +class HorizScroll: + def __init__(self, text): + self.text = text + pass + + def expand(self, padding=None, paddingchar=" ", dir=None): + if len(self.text) <= 10: + return [text] + + if not padding: + padding = len(self.text) / 2 + + format = "%-" + str(padding) + "." + str(padding) + "s" + pad = string.replace(format % " "," ",paddingchar) + padtext = self.text + pad + expansion = [] + + for x in range(0,len(padtext)): + expansion.append(padtext[x:] + padtext[:x]) + + if dir == -1: + expansion.reverse() + + return expansion + +if __name__ == '__main__': + h = HorizScroll("hello cruel world") + eh = h.expand() + while 1: + for x in eh: + sys.stdout.write("\r") + print "%-10.10s" % x, + sys.stdout.flush() + time.sleep(0.1) + -- 2.20.1