Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- class box:
- def __init__(self, text):
- t = []
- maxlen = []
- text = text.split("[b]")
- for i, p in enumerate(text):
- p = p.split('[s]')
- maxlen.append(max(len(line.replace('[r]', '').replace('[c]', '')) for line in p))
- t.append('')
- t.append(' \033[47;30m '+' '*maxlen[i]+' \033[0m')
- for line in p:
- if '[r]' in line:
- t.append(' \033[47;30m '+' '*(maxlen[i]-len(line)+3)+line.replace('[r]', '')+' \033[0m')
- elif '[c]' in line:
- t.append(' \033[47;30m '+line.replace('[c]', '').center(maxlen[i], ' ')+' \033[0m')
- else:
- t.append(' \033[47;30m '+line+' '*(maxlen[i]-len(line))+' \033[0m')
- t.append(' \033[47;30m '+' '*maxlen[i]+' \033[0m')
- t.append('')
- self.t = t
- del t, maxlen, i
- def output(self):
- for line in self.t:
- print line
- if __name__ == '__main__':
- a = box('this is the first box\
- [s]as you can see\
- [b]now you\'re reading the content from the second box\
- [b]we just switched to the third box\
- [s]not as large a box\
- [s]though slightly higher\
- [s]you can see that even though\
- [s]it goes on and on\
- [s]nothing broke yet\
- [s](well i hope so at least)\
- [b]anyway we reached the last box\
- [s]so it\'s time for good byes\
- [b][r]ACTUALLY, NO!\
- [s][r]you\'re getting treated with some sweet right align action :D\
- [s][c]PLUS mixing center align, whatever\
- [s][r]NOW, good night.')
- a.output()
- if 'win' in os.sys.platform:
- os.system('PAUSE')
Advertisement
Add Comment
Please, Sign In to add comment