Fix the code to connect to the virtual vend thing again
[uccvend-vendserver.git] / sql-edition / servers / HorizScroll.py
1 #!/usr/bin/env python
2
3 import string
4 import sys
5 import time
6
7 class HorizScroll:
8         def __init__(self, text):
9                 self.text = text
10                 pass
11
12         def expand(self, padding=None, paddingchar=" ", dir=None, wraparound=False):
13                 if len(self.text) <= 10:
14                         return [text]
15
16                 if padding == None:
17                         padding = len(self.text) / 2 + 1
18
19                 format = "%-" + str(padding) + "." + str(padding) + "s"
20                 pad = string.replace(format % " "," ",paddingchar)
21                 padtext = self.text + pad
22                 if not wraparound:
23                         numiters = len(self.text) - 10
24                 else:
25                         numiters = len(padtext)
26
27                 expansion = []
28
29                 for x in range(0,numiters):
30                           expansion.append("%-10.10s" % (padtext[x:] + padtext[:x]))
31                 
32                 if dir == -1:
33                         expansion.reverse()
34
35                 return expansion
36
37 if __name__ == '__main__':
38         h = HorizScroll("hello cruel world")
39         eh = h.expand()
40         while 1:
41                 for x in eh:
42                         sys.stdout.write("\r")
43                         print "%-10.10s" % x,
44                         sys.stdout.flush()
45                         time.sleep(0.1)
46

UCC git Repository :: git.ucc.asn.au