mirror of
https://github.com/erkin/ponysay.git
synced 2024-11-25 05:47:59 +01:00
-q works as -f + added --f, --F and --q which are varidic variants of -f, -F and -q, respectivly + warn if -q is used with -f and -F but allow (but still warn if used) -q -f
This commit is contained in:
parent
a07dadb813
commit
f6eae560b1
4 changed files with 114 additions and 30 deletions
10
CHANGELOG
10
CHANGELOG
|
@ -1,3 +1,13 @@
|
|||
Version 2.9
|
||||
|
||||
The option -q works like -f and -F, it takes one argument, and may be used multiple
|
||||
times for more arguments.
|
||||
|
||||
The old option -q is renamed to --q.
|
||||
|
||||
The options --f and --F has been added.
|
||||
|
||||
|
||||
Version 2.8
|
||||
|
||||
New ponies: airheart, bastionyorsets, peppermoon, shiningarmorwedding, starlight,
|
||||
|
|
|
@ -76,8 +76,8 @@ multiple times, and one of the will be selected randomly.
|
|||
.B \-q, \-\-quote [\fIname\fP...]
|
||||
By using this option, a pony will be printed with quotes from her in My Little Pony:
|
||||
Friendship is Magic. The pony will be selected randomly, unless at least one pony
|
||||
is added as an argument after \fI-q\fP. If one or more ponies are added after \fI-q\fP
|
||||
the pony will be selected randomly from that set of ponies.
|
||||
is added as an argument to \fI-q\fP. If one or more ponies are added as an argument
|
||||
to \fI-q\fP the pony will be selected randomly from that set of ponies.
|
||||
.TP
|
||||
.B \-W, \-\-wrap \fIcolumn\fP
|
||||
The screen column where the message should be wrapped.
|
||||
|
|
|
@ -172,7 +172,7 @@ 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 pony name
|
||||
supersedes file names.
|
||||
|
||||
@item -F
|
||||
@item -F PONY
|
||||
@itemx ++file PONY
|
||||
@itemx ++pony PONY
|
||||
@opindex @option{-F}
|
||||
|
@ -181,6 +181,54 @@ supersedes file names.
|
|||
Just as @option{-F}, but it uses extra (non-MLP:FiM) ponies instead of standard
|
||||
(MLP:FiM) ponies
|
||||
|
||||
@item -q PONY
|
||||
@itemx --quote PONY
|
||||
@opindex @option{-q}
|
||||
@opindex @option{--quote}
|
||||
@cindex quotes
|
||||
@cindex pony quotes
|
||||
By using this option, a pony will be printed with quotes from her in My Little Pony:
|
||||
Friendship is Magic. The pony will be selected randomly, unless at least one pony
|
||||
is added as an argument to @option{-q}. If one or more ponies are added as an argument
|
||||
to @option{-q}, the pony will be selected randomly from that set of ponies.
|
||||
This option requires the extension @command{ponyquotes4ponysay}, which is included
|
||||
by default since version 1.2.
|
||||
|
||||
The argument can be a file name, but only if it ends with @file{.pony}.
|
||||
|
||||
@item --f [PONY...]
|
||||
@itemx --files [PONY...]
|
||||
@itemx --ponies [PONY...]
|
||||
@opindex @option{--f}
|
||||
@opindex @option{--files}
|
||||
@opindex @option{--ponies}
|
||||
Variadic variant of @option{-f}, meaning that all arguments added after this one
|
||||
will parsed as an argument to this option. Additionally, those options are added
|
||||
to @option{-f}.
|
||||
|
||||
@item --F [PONY...]
|
||||
@itemx ++files [PONY...]
|
||||
@itemx ++ponies [PONY...]
|
||||
@opindex @option{--F}
|
||||
@opindex @option{++files}
|
||||
@opindex @option{++ponies}
|
||||
Variadic variant of @option{-F}, meaning that all arguments added after this one
|
||||
will parsed as an argument to this option. Additionally, those options are added
|
||||
to @option{-F}.
|
||||
|
||||
@item --q [PONY...]
|
||||
@itemx --quotes [PONY...]
|
||||
@opindex @option{--q}
|
||||
@opindex @option{--quotes}
|
||||
@cindex quotes
|
||||
@cindex pony quotes
|
||||
Variadic variant of @option{-q}, meaning that all arguments added after this one
|
||||
will parsed as an argument to this option. Additionally, those options are added
|
||||
to @option{-q}.
|
||||
|
||||
An important feature of this options, is that you can but it in the end of the
|
||||
command line, without any argument to get a quote from any pony with a quote.
|
||||
|
||||
@item -b STYLE
|
||||
@itemx --bubble STYLE
|
||||
@itemx --balloon STYLE
|
||||
|
@ -192,19 +240,6 @@ balloon name printed by @option{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...]
|
||||
@itemx --quote [PONY...]
|
||||
@opindex @option{-q}
|
||||
@opindex @option{--quote}
|
||||
By using this option, a pony will be printed with quotes from her in My Little Pony:
|
||||
Friendship is Magic. The pony will be selected randomly, unless at least one pony
|
||||
is added as an argument after @option{-q}. If one or more ponies are added after
|
||||
@option{-q}, the pony will be selected randomly from that set of ponies.
|
||||
This option requires the extension @command{ponyquotes4ponysay}, which is included
|
||||
by default since version 1.2.
|
||||
|
||||
The argument can be a file name, but only if it ends with @file{.pony}.
|
||||
|
||||
@item -W COLUMN
|
||||
@itemx --wrap COLUMN
|
||||
@opindex @option{-W}
|
||||
|
@ -1947,6 +1982,18 @@ sequences.
|
|||
@cindex versions
|
||||
@cindex previous releases
|
||||
|
||||
@heading Version 2.9
|
||||
@itemize @bullet
|
||||
@item
|
||||
The option @option{-q} works like @option{-f} and @option{-F}, it takes one argument, and
|
||||
may be used multiple times for more arguments.
|
||||
@item
|
||||
The old option @option{-q} is renamed to @option{--q}.
|
||||
@item
|
||||
The options @option{--f} and @option{--F} has been added.
|
||||
@end itemize
|
||||
|
||||
|
||||
@heading Version 2.8
|
||||
@itemize @bullet
|
||||
@item
|
||||
|
|
55
ponysay.py
55
ponysay.py
|
@ -47,6 +47,14 @@ programs by default, report them to Princess Celestia so she can banish them to
|
|||
def print(text = '', end = '\n'):
|
||||
sys.stdout.buffer.write((str(text) + end).encode('utf-8'))
|
||||
|
||||
'''
|
||||
stderr equivalent to print()
|
||||
|
||||
@param text:str The text to print (empty string is default)
|
||||
@param end:str The appendix to the text to print (line breaking is default)
|
||||
'''
|
||||
def printerr(text = '', end = '\n'):
|
||||
sys.stderr.buffer.write((str(text) + end).encode('utf-8'))
|
||||
|
||||
'''
|
||||
Checks whether a text ends with a specific text, but has more
|
||||
|
@ -82,18 +90,23 @@ class Ponysay():
|
|||
global extraponydirs
|
||||
|
||||
## Emulate termial capabilities
|
||||
if args.opts['-X'] is not None:
|
||||
linuxvt = False
|
||||
usekms = False
|
||||
elif args.opts['-V'] is not None:
|
||||
linuxvt = True
|
||||
usekms = False
|
||||
elif args.opts['-K'] is not None:
|
||||
linuxvt = True
|
||||
usekms = True
|
||||
if args.opts['-X'] is not None: (linuxvt, usekms) = (False, False)
|
||||
elif args.opts['-V'] is not None: (linuxvt, usekms) = (True, False)
|
||||
elif args.opts['-K'] is not None: (linuxvt, usekms) = (True, True)
|
||||
ponydirs = vtponydirs if linuxvt and not usekms else xponydirs
|
||||
extraponydirs = extravtponydirs if linuxvt and not usekms else extraxponydirs
|
||||
|
||||
## Variadic variants of -f, -F and -q
|
||||
if args.opts['--f'] is not None:
|
||||
if args.opts['-f'] is not None: args.opts['-f'] += args.opts['--f']
|
||||
else: args.opts['-f'] = args.opts['--f']
|
||||
if args.opts['--F'] is not None:
|
||||
if args.opts['-F'] is not None: args.opts['-F'] += args.opts['--F']
|
||||
else: args.opts['-F'] = args.opts['--F']
|
||||
if args.opts['--q'] is not None:
|
||||
if args.opts['-q'] is not None: args.opts['-q'] += args.opts['--q']
|
||||
else: args.opts['-q'] = args.opts['--q']
|
||||
|
||||
## Run modes
|
||||
if args.opts['-h'] is not None: args.help()
|
||||
elif args.opts['--quoters'] is not None: self.quoters()
|
||||
|
@ -126,8 +139,19 @@ class Ponysay():
|
|||
mode += '$/= $$\\= $'
|
||||
|
||||
## The stuff
|
||||
if args.opts['-q'] is not None: self.quote(args)
|
||||
else: self.print_pony(args)
|
||||
if args.opts['-q'] is not None:
|
||||
warn = (args.opts['-f'] is not None) or (args.opts['-F'] is not None)
|
||||
if (len(args.opts['-q']) == 1) and ((args.opts['-q'][0] == '-f') or (args.opts['-q'][0] == '-F')):
|
||||
warn = True
|
||||
if args.opts['-q'][0] == '-f':
|
||||
args.opts['-q'] = args.files
|
||||
if args.opts['-f'] is not None:
|
||||
args.opts['-q'] += args.opts['-f']
|
||||
self.quote(args)
|
||||
if warn:
|
||||
printerr('-q cannot be used at the same time as -f or -F.')
|
||||
else:
|
||||
self.print_pony(args)
|
||||
|
||||
|
||||
##############################################
|
||||
|
@ -2270,8 +2294,8 @@ usage_saythink = '\033[34;1m(ponysay | ponythink)\033[21;39m'
|
|||
usage_common = '[-c] [-W\033[4mCOLUMN\033[24m] [-b\033[4mSTYLE\033[24m]'
|
||||
usage_listhelp = '(-l | -L | -B | +l | +L | -v | -h)'
|
||||
usage_file = '[-f\033[4mPONY\033[24m]* [[--] \033[4mmessage\033[24m]'
|
||||
usage_xfile = '[-F\033[4mPONY\033[24m]* [[--] \033[4mmessage\033[24m]'
|
||||
usage_quote = '-q [\033[4mPONY\033[24m*]'
|
||||
usage_xfile = '(-F\033[4mPONY\033[24m)* [[--] \033[4mmessage\033[24m]'
|
||||
usage_quote = '(-q \033[4mPONY\033[24m)*'
|
||||
|
||||
usage = '%s %s\n%s %s %s\n%s %s %s\n%s %s %s' % (usage_saythink, usage_listhelp,
|
||||
usage_saythink, usage_common, usage_file,
|
||||
|
@ -2325,7 +2349,10 @@ opts.add_argumented( ['-W', '--wrap'], arg = 'COLUMN', help =
|
|||
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_argumented( ['-F', '++file', '++pony'], arg = 'PONY', help = 'Select a non-MLP:FiM pony.')
|
||||
opts.add_variadic( ['-q', '--quote'], arg = 'PONY', help = 'Select a ponies which will quote themself.')
|
||||
opts.add_argumented( ['-q', '--quote'], arg = 'PONY', help = 'Select a pony which will quote herself.')
|
||||
opts.add_variadic( ['--f', '--files', '--ponies'], arg = 'PONY')
|
||||
opts.add_variadic( ['--F', '++files', '++ponies'], arg = 'PONY')
|
||||
opts.add_variadic( ['--q', '--quotes'], arg = 'PONY')
|
||||
|
||||
opts.parse()
|
||||
|
||||
|
|
Loading…
Reference in a new issue