Merge branch 'develop'

This commit is contained in:
Mattias Andrée 2012-08-21 17:52:18 +02:00
commit ac6b4ef166
11 changed files with 319 additions and 72 deletions

View file

@ -7,6 +7,9 @@ Version 2.2
Support for colours in the message. Support for colours in the message.
Support custom balloon styles using the option '-b', '-B' will list all
available. This list depends on whether you are invoking `ponysay` or `ponythink`
Version 2.1.1 Version 2.1.1

View file

@ -7,7 +7,7 @@ w:|
e: | e: |
ww:< ww:<
ee:> ee: >
nw: _ nw: _
ne:_ ne:_
@ -20,6 +20,6 @@ ssw:-
sse:- sse:-
nww:/ nww:/
nee:\ nee: \
sww:\ sww:\
see:/ see: /

View file

@ -9,10 +9,10 @@ e: )
ww:( ww:(
ee: ) ee: )
nw:) nw:(
ne:( ne:)
sw:) sw:(
se:( se:)
nnw:⁀ nnw:⁀
nne:⁀ nne:⁀

View file

@ -5,7 +5,7 @@ _ponysay()
local cur prev words cword local cur prev words cword
_init_completion -n = || return _init_completion -n = || return
options='--version --help --list --altlist --pony --wrap --quote' options='--version --help --list --altlist --pony --wrap --quote --balloonlist --balloon'
COMPREPLY=( $( compgen -W "$options" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
if [ $prev = "-f" ] || [ $prev = "--pony" ]; then if [ $prev = "-f" ] || [ $prev = "--pony" ]; then
@ -16,6 +16,10 @@ _ponysay()
quoters=$('/usr/bin/ponysay' --quoters) quoters=$('/usr/bin/ponysay' --quoters)
COMPREPLY=( $( compgen -W "$quoters" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$quoters" -- "$cur" ) )
elif [ $prev = "-b" ] || [ $prev = "--balloon" ]; then
balloons=$('/usr/bin/ponysay' --balloonlist)
COMPREPLY=( $( compgen -W "$balloons" -- "$cur" ) )
elif [ $prev = "-W" ] || [ $prev = "--wrap" ]; then elif [ $prev = "-W" ] || [ $prev = "--wrap" ]; then
cols=$(( `stty size | cut -d ' ' -f 2` - 10 )) cols=$(( `stty size | cut -d ' ' -f 2` - 10 ))
COMPREPLY=( $cols $(( $cols / 2 )) 100 60 ) COMPREPLY=( $cols $(( $cols / 2 )) 100 60 )

View file

@ -5,17 +5,20 @@
set -g ponies ('/usr/bin/ponysay' --onelist) set -g ponies ('/usr/bin/ponysay' --onelist)
set -g quoters ('/usr/bin/ponysay' --quoters) set -g quoters ('/usr/bin/ponysay' --quoters)
set -g balloons ('/usr/bin/ponysay' --balloonlist)
complete --command ponysay --short-option h --long-option help --description 'help of ponysay' complete --command ponysay --short-option h --long-option help --description 'help of ponysay'
complete --command ponysay --short-option v --long-option version --description 'version of ponysay' complete --command ponysay --short-option v --long-option version --description 'version of ponysay'
complete --command ponysay --short-option l --long-option list --description 'list pony files' complete --command ponysay --short-option l --long-option list --description 'list pony names'
complete --command ponysay --short-option L --long-option altlist --description 'list pony files with alternatives' complete --command ponysay --short-option L --long-option altlist --description 'list pony names with alternatives'
complete --command ponysay --short-option B --long-option balloonlist --description 'list balloon style names'
complete --command ponysay --short-option f --long-option pony --arguments "$ponies" --description 'pony' complete --command ponysay --short-option f --long-option pony --arguments "$ponies" --description 'pony'
complete --command ponysay --short-option q --long-option quote --arguments "$quoters" --no-files --description 'pony' complete --command ponysay --short-option q --long-option quote --arguments "$quoters" --no-files --description 'pony'
complete --command ponysay --short-option b --long-option balloon --arguments "$balloons" --description 'balloon style'
complete --command ponysay --short-option W --long-option wrap --arguments 'Integer' --description 'specify the column when the message should be wrapped' complete --command ponysay --short-option W --long-option wrap --arguments 'Integer' --description 'specify the column when the message should be wrapped'
complete --command ponysay --arguments 'MESSAGE' complete --command ponysay --arguments 'MESSAGE'
set -e ponies set -e ponies
set -e quoters set -e quoters
set -e balloons

View file

@ -2,10 +2,12 @@
_shortopts=( _shortopts=(
'-v[Show version and exit]' '-v[Show version and exit]'
'-h[Show this help and exit]' '-h[Show this help and exit]'
'-l[list ponyfiles]' '-l[list pony names]'
'-L[list ponyfiles with alternatives]' '-L[list pony names with alternatives]'
'-f[Select a pony (either a filename or a ponyname]: :_path_files -W '/usr/share/ponysay/ponies' -g "*(\:r)"' '-B[list balloon style names]'
'-f[Select a pony (either a file name or a pony name]: :_path_files -W '/usr/share/ponysay/ponies' -g "*(\:r)"'
'-q[Select ponies for MLP:FiM quotes]' '-q[Select ponies for MLP:FiM quotes]'
'-b[Selecy a balloon style]'
'-W[The screen column where the message should be wrapped]' '-W[The screen column where the message should be wrapped]'
) )
_arguments -s : \ _arguments -s : \

2
configure vendored
View file

@ -6,7 +6,7 @@ INFODESC=\''My Little Ponies for your terminal'\'
SHELL='bash' SHELL='bash'
completions='completion/bash-completion.sh completion/fish-completion.fish completion/zsh-completion.zsh' completions='completion/bash-completion.sh completion/fish-completion.fish completion/zsh-completion.zsh'
shareDirs='ponies ttyponies quotes' shareDirs='ponies ttyponies quotes balloons'
manFiles='manuals/manpage.6 manuals/manpage.es.6' manFiles='manuals/manpage.6 manuals/manpage.es.6'
licenseFiles='COPYING' licenseFiles='COPYING'

View file

@ -132,8 +132,10 @@ Show summary of options.
Show version of program. Show version of program.
@item -f PONY @item -f PONY
@itemx --file PONY
@itemx --pony PONY @itemx --pony PONY
@cindex @command{-f} @cindex @command{-f}
@cindex @command{--file}
@cindex @command{--pony} @cindex @command{--pony}
Specify the pony that should printed, this can either be a file name or a pony Specify the pony that should printed, this can either be a file name or a pony
name printed by @command{ponysay -l}. This option can be used multiple times to name printed by @command{ponysay -l}. This option can be used multiple times to
@ -145,8 +147,19 @@ If you have @command{util-say} installed, you can use .png-files as the
arguments for this options. arguments for this options.
In versions earlier than version 2.0, the if the pony were a file name it had In versions earlier than version 2.0, the if the pony were a file name it had
to include a `@code{/}'. This is not longer required and any existing file to include a `@code{/}'. This is not longer required and any existing pony name
supersedes pony names. supersedes file names.
@item -b STYLE
@itemx --bubble STYLE
@itemx --balloon STYLE
@cindex @command{-b}
@cindex @command{--bubble}
@cindex @command{--balloon}
Specify the balloon style that should used, this can either be a file name or a
balloon name printed by @command{ponysay -B}. This option can be used multiple
times to specify a set of styles from which one will be selected randomly. If no
balloon style is specified a fallback style will be used.
@item -q [PONY...] @item -q [PONY...]
@itemx --quote [PONY...] @itemx --quote [PONY...]
@ -185,6 +198,12 @@ is installed the ponies which have quotes, i.e. can be used with the
(depending on the terminal.) This options differs from @command{-l} by (depending on the terminal.) This options differs from @command{-l} by
printing alternative names (symbolic links) inside brackets after their printing alternative names (symbolic links) inside brackets after their
target ponies. target ponies.
@item -B
@itemx --balloonlist
@cindex @command{-B}
@cindex @command{--balloonlist}
Prints a list of all balloon styles.
@end table @end table
If neither @command{-q} is used nor any @var{message} is specified, @command{ponysay} If neither @command{-q} is used nor any @var{message} is specified, @command{ponysay}
@ -800,6 +819,7 @@ but is still available at @url{https://github.com/maandree/kmsponies4ponysay}.
@menu @menu
* Pony anatomy:: Anatomy of pony files. * Pony anatomy:: Anatomy of pony files.
* Pony quote infrastructure:: Pony quote infrastructure. * Pony quote infrastructure:: Pony quote infrastructure.
* Balloon style files:: Balloon style files.
* Printing in TTY with KMS:: Printing in TTY with KMS. * Printing in TTY with KMS:: Printing in TTY with KMS.
* Truncation:: Output truncation. * Truncation:: Output truncation.
* Languages:: Selection of languages. * Languages:: Selection of languages.
@ -861,6 +881,77 @@ when compiled to @code{quotes}. The source quote files are indentical to the com
quote files, except that there name contains just the first pony. quote files, except that there name contains just the first pony.
@node Balloon style files
@section Balloon style files
@cindex balloon style files
@cindex bubble style files
@cindex @command{ponythink}
Balloon style files are located in the directory @code{balloons}, the ones ending with
@code{.say} applies to @command{ponysay} and the ones ending with @code{.think} applies
to @command{ponythink}.
Balloon style consists of 20 strings. Each string is definied on separate lines, by their
name and their value seperated with a colon (@code{name:value}), if the name is empty it
continues the last one new line in the value. Only 10 of the strings may be multilined:
@code{nw}, @code{nnw}, @code{n}, @code{nne}, @code{ne}, @code{sw}, @code{ssw}, @code{s}
@code{sse} and @code{se}.
The following strings are used, and must be definied in the files:
@table @option
@item \
The character for the link to the balloon directed as @code{\}.
@item /
The character for the link to the balloon directed as @code{/}.
@item ww
The beginning of the balloon's line where the message is located if and only if the
message contains only one line.
@item ee
The end of the balloon's line where the message is located if and only if the message
contains only one line.
@item nw
The top left corner of the balloon.
@item nnw
If both this string and the @code{'nne'} string fits between the top corners, this
is printed directly to the right of the top left corner.
@item n
The top edge of the balloon.
@item nne
If both this string and the @code{'nnw'} string fits between the top corners, this
is printed directly to the right of the top top corner.
@item ne
The top right corner of the balloon.
@item nee
The end of the balloon's line where the message's first line is located if and only
if the message contains more than one line.
@item e
The right edge of the balloon.
@item see
The end of the balloon's line where the message's last line is located if and only
if the message contains more than one line.
@item se
The bottom right corner of the balloon.
@item sse
If both this string and the @code{'ssw'} string fits between the bottom corners, this
is printed directly to the left of the bottom right corner.
@item s
The bottom edge of the balloon.
@item ssw
If both this string and the @code{'sse'} string fits between the bottom corners, this
is printed directly to the right of the bottom left corner.
@item sw
The bottom left corner of the balloon.
@item sww
The beginning of the balloon's line where the message's last line is located if and
only if the message contains more than one line.
@item w
The left edge of the balloon.
@item nww
The beginning of the balloon's line where the message's first line is located if and
only if the message contains more than one line.
@end table
@node Printing in TTY with KMS @node Printing in TTY with KMS
@section Printing in TTY with KMS @section Printing in TTY with KMS
@cindex tty @cindex tty
@ -1043,6 +1134,10 @@ ANSI colour sequences in pony files are applied only to the pony image,
not the balloon link or the balloon itself. not the balloon link or the balloon itself.
@item @item
Support for colours in the message. Support for colours in the message.
@item
Support custom balloon styles using the option @code{-b}, @code{-B} will list
all available. This list depends on whether you are invoking @command{ponysay}
or @command{ponythink}
@end itemize @end itemize
@heading Version 2.1.1 @heading Version 2.1.1

Binary file not shown.

240
ponysay
View file

@ -46,16 +46,13 @@ class Ponysay():
args.help() args.help()
return return
if (args.opts['-l'] is not None) and pipelineout:
args.opts['--onelist'] = args.opts['-l']
args.opts['-l'] = None
if args.opts['-h'] is not None: args.help() if args.opts['-h'] is not None: args.help()
elif args.opts['--quoters'] is not None: self.quoters() elif args.opts['--quoters'] is not None: self.quoters()
elif args.opts['--onelist'] is not None: self.onelist() elif args.opts['--onelist'] is not None: self.onelist()
elif args.opts['-v'] is not None: self.version() elif args.opts['-v'] is not None: self.version()
elif args.opts['-l'] is not None: self.list() elif args.opts['-l'] is not None: self.list()
elif args.opts['-L'] is not None: self.linklist() elif args.opts['-L'] is not None: self.linklist()
elif args.opts['-B'] is not None: self.balloonlist()
elif args.opts['-q'] is not None: self.quote(args) elif args.opts['-q'] is not None: self.quote(args)
else: self.print_pony(args) else: self.print_pony(args)
@ -65,22 +62,22 @@ class Ponysay():
## ##
''' '''
Returns one file with full path, names is filter for names, also accepts filepaths. Returns one file with full path, names is filter for names, also accepts filepaths
''' '''
def __getponypath(self, names = None): def __getponypath(self, names = None):
ponies = {} ponies = {}
if not names == None:
for name in names:
if os.path.isfile(name):
ponies[name] = name
for ponydir in ponydirs: for ponydir in ponydirs:
for ponyfile in os.listdir(ponydir): for ponyfile in os.listdir(ponydir):
pony = ponyfile[:-5] pony = ponyfile[:-5]
if pony not in ponies: if pony not in ponies:
ponies[pony] = ponydir + ponyfile ponies[pony] = ponydir + ponyfile
if not names == None:
for name in names:
if os.path.isfile(name):
ponies[name] = name
if names == None: if names == None:
names = list(ponies.keys()) names = list(ponies.keys())
@ -164,10 +161,13 @@ class Ponysay():
quoters = self.__quoters() quoters = self.__quoters()
for ponydir in ponydirs: # Loop ponydirs for ponydir in ponydirs: # Loop ponydirs
print('\033[1mponyfiles located in ' + ponydir + '\033[21m') print('\033[1mponies located in ' + ponydir + '\033[21m')
ponies = os.listdir(ponydir) _ponies = os.listdir(ponydir)
ponies = [item[:-5] for item in ponies] # remove .pony from file name ponies = []
for pony in _ponies:
if (len(pony) > 5) and (pony[-5:] == '.pony'):
ponies.append(pony[:-5])
ponies.sort() ponies.sort()
width = len(max(ponies, key = len)) + 2 # Get the longest ponyfilename lenght + 2 spaces width = len(max(ponies, key = len)) + 2 # Get the longest ponyfilename lenght + 2 spaces
@ -192,12 +192,15 @@ class Ponysay():
quoters = self.__quoters() quoters = self.__quoters()
for ponydir in ponydirs: # Loop ponydirs for ponydir in ponydirs: # Loop ponydirs
print('\033[1mponyfiles located in ' + ponydir + '\033[21m') print('\033[1mponies located in ' + ponydir + '\033[21m')
files = os.listdir(ponydir) _ponies = os.listdir(ponydir)
files = [item[:-5] for item in files] # remove .pony from file name ponies = []
files.sort() for pony in _ponies:
pairs = [(item, os.readlink(ponydir + item + '.pony') if os.path.islink(ponydir + item + '.pony') else '') for item in files] if (len(pony) > 5) and (pony[-5:] == '.pony'):
ponies.append(pony[:-5])
ponies.sort()
pairs = [(pony, os.readlink(ponydir + pony + '.pony') if os.path.islink(ponydir + pony + '.pony') else '') for pony in ponies]
ponymap = {} ponymap = {}
for pair in pairs: for pair in pairs:
@ -243,7 +246,7 @@ class Ponysay():
for pony in ponies: for pony in ponies:
spacing = ' ' * (width - widths[index]) spacing = ' ' * (width - widths[index])
index += 1 index += 1
print(pony + spacing, end='') # Print ponyfilename print(pony + spacing, end='') # Print pony file name
x += width x += width
if x > (termsize[1] - width): # If too wide, make new line if x > (termsize[1] - width): # If too wide, make new line
print() print()
@ -272,10 +275,13 @@ class Ponysay():
''' '''
def onelist(self): def onelist(self):
last = '' last = ''
ponies = [] _ponies = []
for ponydir in ponydirs: # Loop ponydirs for ponydir in ponydirs: # Loop ponydirs
ponies += os.listdir(ponydir) _ponies += os.listdir(ponydir)
ponies = [item[:-5] for item in ponies] # remove .pony from file name ponies = []
for pony in _ponies:
if (len(pony) > 5) and (pony[-5:] == '.pony'):
ponies.append(pony[:-5])
ponies.sort() ponies.sort()
for pony in ponies: for pony in ponies:
if not pony == last: if not pony == last:
@ -283,6 +289,118 @@ class Ponysay():
print(pony) print(pony)
##
## Balloon methods
##
'''
Prints a list of all balloons
'''
def balloonlist(self):
termsize = self.__gettermsize()
balloonset = set()
for balloondir in balloondirs:
for balloon in os.listdir(balloondir):
if isthink and (len(balloon) > 6) and (balloon[-6:] == '.think'):
balloon = balloon[:-6]
elif (not isthink) and (len(balloon) > 4) and (balloon[-4:] == '.say'):
balloon = balloon[:-4]
else:
continue
if balloon not in balloonset:
balloonset.add(balloon)
balloons = list(balloonset)
balloons.sort()
width = len(max(balloons, key = len)) + 2
x = 0
for balloon in balloons:
spacing = ' ' * (width - len(balloon))
print(balloon + spacing, end='')
x += width
if x > (termsize[1] - width):
print()
x = 0
print();
'''
Returns one file with full path, names is filter for style names, also accepts filepaths
'''
def __getballoonpath(self, names):
if names is None:
return None
balloons = {}
for balloondir in balloondirs:
for balloon in os.listdir(balloondir):
balloonfile = balloon
if isthink and (len(balloon) > 6) and (balloon[-6:] == '.think'):
balloon = balloon[:-6]
elif (not isthink) and (len(balloon) > 4) and (balloon[-4:] == '.say'):
balloon = balloon[:-4]
else:
continue
if balloon not in balloons:
balloons[balloon] = balloondir + balloonfile
for name in names:
if os.path.isfile(name):
balloons[name] = name
if names == None:
names = list(balloons.keys())
balloon = names[random.randrange(0, len(names))]
if balloon not in balloons:
sys.stderr.write('That balloon style %s does not exist\n' % (balloon));
exit(1)
else:
return balloons[balloon]
'''
Creates the balloon style object
'''
def __getballoon(self, balloonfile):
if balloonfile is None:
if isthink:
return Balloon('o', 'o', '( ', ' )', [' _'], ['_'], ['_'], ['_'], ['_ '], ' )', ' )', ' )', ['- '], ['-'], ['-'], ['-'], [' -'], '( ', '( ', '( ')
return Balloon('\\', '/', '< ', ' >', [' _'], ['_'], ['_'], ['_'], ['_ '], ' \\', ' |', ' /', ['- '], ['-'], ['-'], ['-'], [' -'], '\\ ', '| ', '/ ')
map = {}
for elem in ('\\', '/', 'ww', 'ee', 'nw', 'nnw', 'n', 'nne', 'ne', 'nee', 'e', 'see', 'se', 'sse', 's', 'ssw', 'sw', 'sww', 'w', 'nww'):
map[elem] = []
balloonstream = None
try:
balloonstream = open(balloonfile, 'r')
data = [line.replace('\n', '') for line in balloonstream.readlines()]
finally:
if balloonstream is not None:
balloonstream.close()
last = None
for line in data:
if len(line) > 0:
if line[0] == ':':
map[last].append(line[1:])
else:
last = line[:line.index(':')]
value = line[len(last) + 1:]
map[last].append(value)
return Balloon(map['\\'][0], map['/'][0], map['ww'][0], map['ee'][0], map['nw'], map['nnw'], map['n'],
map['nne'], map['ne'], map['nee'][0], map['e'][0], map['see'][0], map['se'], map['sse'],
map['s'], map['ssw'], map['sw'], map['sww'][0], map['w'][0], map['nww'][0])
## ##
## Displaying methods ## Displaying methods
## ##
@ -323,7 +441,9 @@ class Ponysay():
widthtruncation = self.__gettermsize()[1] if env_width not in ('yes', 'y', '1') else None widthtruncation = self.__gettermsize()[1] if env_width not in ('yes', 'y', '1') else None
messagewrap = int(args.opts['-W'][0]) if args.opts['-W'] is not None else None messagewrap = int(args.opts['-W'][0]) if args.opts['-W'] is not None else None
backend = Backend(message = msg, ponyfile = pony, wrapcolumn = messagewrap if messagewrap is not None else 40, width = widthtruncation) balloon = self.__getballoon(self.__getballoonpath(args.opts['-b']))
backend = Backend(message = msg, ponyfile = pony, wrapcolumn = messagewrap if messagewrap is not None else 40, width = widthtruncation, balloon = balloon)
backend.parse() backend.parse()
output = backend.output output = backend.output
if (len(output) > 0) and (output[-1] == '\n'): if (len(output) > 0) and (output[-1] == '\n'):
@ -649,7 +769,7 @@ class ArgParser():
if first: if first:
first = False first = False
else: else:
print(' or', end="") print(' or', end='')
print('\t%s' % (line)) print('\t%s' % (line))
print() print()
@ -722,11 +842,6 @@ class Balloon():
if w < minw: w = minw if w < minw: w = minw
if h < minh: h = minh if h < minh: h = minh
rc = []
for j in range(0, len(self.n)):
rc.append(self.nw[j] + self.n[j] * (w - len(self.nw[j]) - len(self.ne[j])) + self.ne[j])
if len(lines) > 1: if len(lines) > 1:
(ws, es) = ({0 : self.nww, len(lines) - 1 : self.sww}, {0 : self.nee, len(lines) - 1 : self.see}) (ws, es) = ({0 : self.nww, len(lines) - 1 : self.sww}, {0 : self.nee, len(lines) - 1 : self.see})
for j in range(1, len(lines) - 1): for j in range(1, len(lines) - 1):
@ -735,11 +850,26 @@ class Balloon():
else: else:
(ws, es) = ({0 : self.ww}, {0 : self.ee}) (ws, es) = ({0 : self.ww}, {0 : self.ee})
rc = []
for j in range(0, len(self.n)):
outer = len(self.nw[j]) + len(self.ne[j])
inner = len(self.nnw[j]) + len(self.nne[j])
if outer + inner >= w:
rc.append(self.nw[j] + self.nnw[j] + self.n[j] * (w - outer - inner) + self.nne[j] + self.ne[j])
else:
rc.append(self.nw[j] + self.n[j] * (w - outer) + self.ne[j])
for j in range(0, len(lines)): for j in range(0, len(lines)):
rc.append(ws[j] + lines[j] + ' ' * (w - lencalc(lines[j]) - len(self.w) - len(self.e)) + es[j]) rc.append(ws[j] + lines[j] + ' ' * (w - lencalc(lines[j]) - len(self.w) - len(self.e)) + es[j])
for j in range(0, len(self.s)): for j in range(0, len(self.s)):
rc.append(self.sw[j] + self.s[j] * (w - len(self.sw[j]) - len(self.se[j])) + self.se[j]) outer = len(self.sw[j]) + len(self.se[j])
inner = len(self.ssw[j]) + len(self.sse[j])
if outer + inner >= w:
rc.append(self.sw[j] + self.ssw[j] + self.s[j] * (w - outer - inner) + self.sse[j] + self.se[j])
else:
rc.append(self.sw[j] + self.s[j] * (w - outer) + self.se[j])
return '\n'.join(rc) return '\n'.join(rc)
@ -751,18 +881,14 @@ Replacement for cowsay
class Backend(): class Backend():
''' '''
Constructor Constructor
Takes message [string], ponyfile [filename string], wrapcolumn [None or an int] and width [None or an int] Takes message [string], ponyfile [filename string], wrapcolumn [None or an int], width [None or an int] and balloon [Balloon object]
''' '''
def __init__(self, message, ponyfile, wrapcolumn, width): def __init__(self, message, ponyfile, wrapcolumn, width, balloon):
self.message = message self.message = message
self.ponyfile = ponyfile self.ponyfile = ponyfile
self.wrapcolumn = wrapcolumn self.wrapcolumn = wrapcolumn
self.width = width self.width = width
self.balloon = balloon
if isthink:
self.balloon = Balloon('o', 'o', '( ', ' )', [' _'], ['_'], ['_'], ['_'], ['_ '], ' )', ' )', ' )', ['- '], ['-'], ['-'], ['-'], [' -'], '( ', '( ', '( ')
else:
self.balloon = Balloon('\\', '/', '< ', ' >', [' _'], ['_'], ['_'], ['_'], ['_ '], ' \\', ' |', ' /', ['- '], ['-'], ['-'], ['-'], [' -'], '\\ ', '| ', '/ ')
self.link = {'\\' : self.balloon.link, '/' : self.balloon.linkmirror} self.link = {'\\' : self.balloon.link, '/' : self.balloon.linkmirror}
@ -945,7 +1071,7 @@ class Backend():
datalen = self.__len(data) datalen = self.__len(data)
skip += datalen skip += datalen
nonskip += datalen nonskip += datalen
data = data.replace("$", '$$') data = data.replace('$', '$$')
n += len(data) n += len(data)
self.pony = self.pony[:i] + data + self.pony[i:] self.pony = self.pony[:i] + data + self.pony[i:]
balloonLines[balloonLine] = None balloonLines[balloonLine] = None
@ -1196,7 +1322,7 @@ class ColourStack():
part = self.seq[i] part = self.seq[i]
p = 0 if part == '' else int(part) p = 0 if part == '' else int(part)
i += 1 i += 1
if p == '': self.stack[0][1:] = [None, None, [False] * 9] if p == 0: self.stack[0][1:] = [None, None, [False] * 9]
elif (1 <= p) and (p <= 9): self.stack[0][3][p - 1] = True elif (1 <= p) and (p <= 9): self.stack[0][3][p - 1] = True
elif (21 <= p) and (p <= 29): self.stack[0][3][p - 21] = False elif (21 <= p) and (p <= 29): self.stack[0][3][p - 21] = False
elif p == 39: self.stack[0][1] = None elif p == 39: self.stack[0][1] = None
@ -1240,7 +1366,8 @@ linuxvt = os.environ['TERM'] == 'linux'
''' '''
Whether the script is executed as ponythink Whether the script is executed as ponythink
''' '''
isthink = (len(__file__) >= 8) and (__file__[-8:] == 'think.py') isthink = (len(__file__) >= 5) and (__file__[-5:] == 'think')
isthink = ((len(__file__) >= 8) and (__file__[-8:] == 'think.py')) or isthink
''' '''
@ -1251,7 +1378,7 @@ pipelinein = not sys.stdin.isatty()
''' '''
Whether stdout is piped Whether stdout is piped
''' '''
pipelineout = False #not sys.stdout.isatty() # currently impossible, we need to get rid of the little shell script first pipelineout = not sys.stdout.isatty()
''' '''
Whether stderr is piped Whether stderr is piped
@ -1281,15 +1408,26 @@ for quotedir in _quotedirs:
quotedirs.append(quotedir) quotedirs.append(quotedir)
'''
The directories where balloon style files are stored
'''
balloondirs = []
_balloondirs = [HOME + '/.local/share/ponysay/balloons/', INSTALLDIR + '/share/ponysay/balloons/']
for balloondir in _balloondirs:
if os.path.isdir(balloondir):
balloondirs.append(balloondir)
usage_saythink = '\033[34;1m(ponysay | ponythink)\033[21;39m' usage_saythink = '\033[34;1m(ponysay | ponythink)\033[21;39m'
usage_wrap = '--wrap \033[4mCOLUMN\033[24m' usage_wrap = '--wrap \033[4mCOLUMN\033[24m'
usage_listhelp = '(--list | ---altlist | --version | --help)' usage_balloon = '--balloon \033[4mSTYLE\033[24m'
usage_listhelp = '(--list | --altlist | --balloonlist | --version | --help)'
usage_file = '[--pony \033[4mPONY\033[24m]... ([--] \033[4mmessage\033[24m | <<<\033[4mmessage\033[24m)' usage_file = '[--pony \033[4mPONY\033[24m]... ([--] \033[4mmessage\033[24m | <<<\033[4mmessage\033[24m)'
usage_quote = '--quote [\033[4mPONY\033[24m...]' usage_quote = '--quote [\033[4mPONY\033[24m...]'
usage = '%s %s\n%s [%s] %s\n%s [%s] %s' % (usage_saythink, usage_listhelp, usage = '%s %s\n%s [%s] [%s] %s\n%s [%s] [%s] %s' % (usage_saythink, usage_listhelp,
usage_saythink, usage_wrap, usage_file, usage_saythink, usage_wrap, usage_balloon, usage_file,
usage_saythink, usage_wrap, usage_quote) usage_saythink, usage_wrap, usage_balloon, usage_quote)
usage = usage.replace('\033[', '\0') usage = usage.replace('\033[', '\0')
for sym in ('[', ']', '(', ')', '|', '...'): for sym in ('[', ']', '(', ')', '|', '...'):
@ -1313,11 +1451,13 @@ opts.add_argumentless(['--onelist'])
opts.add_argumentless(['-h', '--help'], help = 'Print this help message.') opts.add_argumentless(['-h', '--help'], help = 'Print this help message.')
opts.add_argumentless(['-v', '--version'], help = 'Print the version of the program.') opts.add_argumentless(['-v', '--version'], help = 'Print the version of the program.')
opts.add_argumentless(['-l', '--list'], help = 'List pony files.') opts.add_argumentless(['-l', '--list'], help = 'List pony names.')
opts.add_argumentless(['-L', '--altlist'], help = 'List pony files with alternatives.') opts.add_argumentless(['-L', '--altlist'], help = 'List pony names with alternatives.')
opts.add_argumented( ['-W', '--wrap'], arg = "COLUMN", help = 'Specify the column when the message should be wrapped.') opts.add_argumentless(['-B', '--balloonlist'], help = 'list balloon styles.')
opts.add_argumented( ['-f', '--pony'], arg = "PONY", help = 'Select a pony.\nEither a file name or a pony name.') opts.add_argumented( ['-W', '--wrap'], arg = 'COLUMN', help = 'Specify the column when the message should be wrapped.')
opts.add_variadic( ['-q', '--quote'], arg = "PONY", help = 'Select a ponies which will quote themself.') opts.add_argumented( ['-b', '--bubble', '--balloon'], arg = 'STYLE', help = 'Select a balloon style.')
opts.add_argumented( ['-f', '--file', '--pony'], arg = 'PONY', help = 'Select a pony.\nEither a file name or a pony name.')
opts.add_variadic( ['-q', '--quote'], arg = 'PONY', help = 'Select a ponies which will quote themself.')
opts.parse() opts.parse()

Binary file not shown.