X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=sql-edition%2Fservers%2FHorizScroll.py;fp=sql-edition%2Fservers%2FHorizScroll.py;h=69644fb40277ae9ddfca9427aa9ccbef5e887259;hb=a640e08962027cc2e3a128b6ff9a5ec8faaea0cd;hp=0000000000000000000000000000000000000000;hpb=e032b6f992f16a61dad3700baa292c01fbc1f088;p=uccvend-vendserver.git diff --git a/sql-edition/servers/HorizScroll.py b/sql-edition/servers/HorizScroll.py new file mode 100644 index 0000000..69644fb --- /dev/null +++ b/sql-edition/servers/HorizScroll.py @@ -0,0 +1,46 @@ +#!/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, wraparound=False): + if len(self.text) <= 10: + return [text] + + if not padding: + padding = len(self.text) / 2 + 1 + + format = "%-" + str(padding) + "." + str(padding) + "s" + pad = string.replace(format % " "," ",paddingchar) + padtext = self.text + pad + if wraparound: + numiters = len(self.text) - 1 + else: + numiters = len(padtext) + + expansion = [] + + for x in range(0,numiters): + expansion.append("%-10.10s" % (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) +