mirror of
https://github.com/erkin/ponysay.git
synced 2024-11-22 12:27:59 +01:00
balloon class used for balloon style customisation
This commit is contained in:
parent
4a55d12917
commit
16763d07d3
1 changed files with 52 additions and 13 deletions
65
ponysay
65
ponysay
|
@ -683,6 +683,51 @@ class ArgParser():
|
|||
|
||||
|
||||
|
||||
'''
|
||||
Balloon format class
|
||||
'''
|
||||
class Balloon():
|
||||
'''
|
||||
Constructor
|
||||
'''
|
||||
def __init__(self, link, linkmirror, ww, ee, nw, nnw, n, nne, ne, nee, e, see, se, sse, s, ssw, sw, sww, w, nww):
|
||||
(self.link, self.linkmirror) = (link, linkmirror)
|
||||
(self.ww, self.ee) = (ww, ee)
|
||||
(self.nw, self.ne, self.se, self.sw) = (nw, ne, se, sw)
|
||||
(self.nnw, self.n, self.nne) = (nnw, n, nne)
|
||||
(self.nee, self.e, self.see) = (nee, e, see)
|
||||
(self.sse, self.s, self.ssw) = (sse, s, ssw)
|
||||
(self.sww, self.w, self.nww) = (sww, w, nww)
|
||||
|
||||
minE = len(max([ne, nee, e, see, se, ee], key = len))
|
||||
minW = len(max([nw, nww, e, sww, sw, ww], key = len))
|
||||
minN = len(max([ne, nne, n, nnw, nw], key = len))
|
||||
minS = len(max([se, sse, s, ssw, sw], key = len))
|
||||
|
||||
self.minwidth = minE + minE
|
||||
self.minheight = minN + minS
|
||||
|
||||
|
||||
'''
|
||||
Generates a balloon with a message
|
||||
'''
|
||||
def get(self, minw, minh, lines, lencalc):
|
||||
h = 4 + lencalc(lines)
|
||||
w = 6 + lencalc(max(lines, key = lencalc))
|
||||
if w < minw: w = minw
|
||||
if h < minh: h = minh
|
||||
|
||||
rc = '/' + '-' * (w - 2) + '\\\n'
|
||||
rc += '|' + ' ' * (w - 2) + '|\n'
|
||||
for line in lines:
|
||||
rc += '| ' + line + ' ' * (w - lencalc(line) - 6) + ' |\n'
|
||||
rc += '|' + ' ' * (w - 2) + '|\n'
|
||||
rc += '\\' + '-' * (w - 2) + '/'
|
||||
|
||||
return rc
|
||||
|
||||
|
||||
|
||||
'''
|
||||
Replacement for cowsay
|
||||
'''
|
||||
|
@ -697,7 +742,12 @@ class Backend():
|
|||
self.wrapcolumn = wrapcolumn
|
||||
self.width = width
|
||||
|
||||
self.link = {'\\' : '\\', '/' : '/'} if not isthink else {'\\' : 'o', '/' : 'o'}
|
||||
if isthink:
|
||||
self.balloon = Balloon('o', 'o', '( ', ' )', [' _'], ['_'], ['_'], ['_'], ['_ '], ' )', ' )', ' )', ['- '], ['-'], ['-'], ['-'], ['- '], '( ', '( ', '( ')
|
||||
else:
|
||||
self.balloon = Balloon('\\', '/', '< ', ' >', [' _'], ['_'], ['_'], ['_'], ['_ '], ' \\', ' |', ' //', ['- '], ['-'], ['-'], ['-'], ['- '], '\\ ', '| ', '/ ')
|
||||
|
||||
self.link = {'\\' : self.balloon.link, '/' : self.balloon.linkmirror}
|
||||
|
||||
self.output = ''
|
||||
self.pony = None
|
||||
|
@ -965,19 +1015,8 @@ class Backend():
|
|||
if wrap is not None:
|
||||
msg = self.__wrapMessage(msg, wrap)
|
||||
lines = msg.split('\n')
|
||||
h = 4 + len(lines)
|
||||
w = 6 + len(max(lines, key = len))
|
||||
if w < width: w = width
|
||||
if h < height: h = height
|
||||
|
||||
rc = '/' + '-' * (w - 2) + '\\\n'
|
||||
rc += '|' + ' ' * (w - 2) + '|\n'
|
||||
for line in lines:
|
||||
rc += '| ' + line + ' ' * (w - len(line) - 6) + ' |\n'
|
||||
rc += '|' + ' ' * (w - 2) + '|\n'
|
||||
rc += '\\' + '-' * (w - 2) + '/'
|
||||
|
||||
return rc
|
||||
return self.balloon.get(width, height, lines, self.__len)
|
||||
|
||||
|
||||
'''
|
||||
|
|
Loading…
Reference in a new issue