Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- def boxes(title, text):
- t = []
- lines = text.split('\n')
- maxlen = max(len(line) for line in lines)
- t.append(' '+'_'*(len(title)+2))
- t.append('|'+' '*(len(title)+2)+'|')
- t.append('| '+title+' |')
- if len(title) < maxlen:
- t.append('|'+'_'*(len(title)+2)+'|'+'_'*(maxlen-len(title)-1))
- else:
- t.append('|'+'_'*(len(title)+2)+'|')
- t.append('|'+' '*(maxlen+2)+'|')
- for line in lines:
- t.append('| '+line+' '*(maxlen-len(line))+' |')
- t.append('|'+'_'*(maxlen+2)+'|')
- return t
- short_title = boxes(\
- 'this is a short title',\
- '''this is a bunch of text
- which takes up more space than the title
- and it goes on
- and on
- and on''')
- long_title = boxes(\
- 'this is a long title',\
- '''compared
- with the
- short text
- in here''')
- tablen = max(len(t) for t in short_title)+8
- for i in range(max(len(t) for t in [short_title, long_title])):
- if i < len(short_title):
- t = short_title[i]
- t += ' '*(tablen-len(short_title[i]))
- else:
- t = ' '*tablen
- if i < len(long_title):
- t += long_title[i]
- print(t)
- if 'win' in os.sys.platform:
- os.system('PAUSE')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement