jgtrosh

boxesminusspacious.py

Aug 5th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. import os
  2. class box:
  3.     def __init__(self, text):
  4.         t = []
  5.         maxlen = []
  6.         text = text.split("[p]")
  7.         for i, p in enumerate(text):
  8.             p = p.split('[l]')
  9.             maxlen.append(max(len(line) for line in p))
  10.             t.append('')
  11.             t.append(' \033[47;30m '+' '*maxlen[i]+' \033[0m')
  12.             for line in p:
  13.                 t.append(' \033[47;30m '+line+' '*(maxlen[i]-len(line))+' \033[0m')
  14.             t.append(' \033[47;30m '+' '*maxlen[i]+' \033[0m')
  15.         t.append('')
  16.         self.t = t
  17.         del t, maxlen, i
  18.     def output(self):
  19.         print('\n'.join(self.t))
  20.  
  21. if __name__ == '__main__':
  22.     a = box('this is the first box\
  23. [l]as you can see\
  24. [p]now you\'re reading the content from the second box\
  25. [p]we just switched to the third box\
  26. [l]not as large a box\
  27. [l]though slightly higher\
  28. [l]you can see that even though\
  29. [l]it goes on and on\
  30. [l]nothing broke yet\
  31. [l](well i hope so at least)\
  32. [p]anyway we reached the last box\
  33. [l]so it\'s time for good byes')
  34.     a.output()
  35.     if 'win' in os.sys.platform:
  36.         os.system('PAUSE')
Advertisement
Add Comment
Please, Sign In to add comment