mirror of
https://github.com/erkin/ponysay.git
synced 2025-02-21 11:54:21 +01:00
cowsay replacement env vars + can get terminal if stdin is piped in
This commit is contained in:
parent
88baa565a0
commit
de1f27a73a
1 changed files with 28 additions and 10 deletions
38
ponysay.py
38
ponysay.py
|
@ -86,6 +86,7 @@ parser.add_argument('message', nargs = '?', help = 'message to ponysay')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
This is the mane class of ponysay
|
This is the mane class of ponysay
|
||||||
'''
|
'''
|
||||||
|
@ -178,6 +179,16 @@ class ponysay():
|
||||||
return rc
|
return rc
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
Gets the size of the terminal in (rows, columns)
|
||||||
|
'''
|
||||||
|
def __gettermsize(self):
|
||||||
|
termsize = Popen(['stty', 'size'], stdout=PIPE, stdin=sys.stderr).communicate()[0]
|
||||||
|
termsize = termsize.decode('utf8', 'replace')[:-1].split(' ') # [:-1] removes a \n
|
||||||
|
termsize = [int(item) for item in termsize]
|
||||||
|
return termsize
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
## Listing methods
|
## Listing methods
|
||||||
##
|
##
|
||||||
|
@ -186,9 +197,7 @@ class ponysay():
|
||||||
Lists the available ponies
|
Lists the available ponies
|
||||||
'''
|
'''
|
||||||
def list(self):
|
def list(self):
|
||||||
termsize = Popen(['stty', 'size'], stdout=PIPE).communicate()[0].decode('utf8', 'replace')[:-1].split(' ')
|
termsize = self.__gettermsize()
|
||||||
termsize = [int(item) for item in termsize]
|
|
||||||
|
|
||||||
quoters = self.__quoters()
|
quoters = self.__quoters()
|
||||||
|
|
||||||
for ponydir in ponydirs: # Loop ponydirs
|
for ponydir in ponydirs: # Loop ponydirs
|
||||||
|
@ -216,9 +225,7 @@ class ponysay():
|
||||||
Lists the available ponies with alternatives inside brackets
|
Lists the available ponies with alternatives inside brackets
|
||||||
'''
|
'''
|
||||||
def linklist(self):
|
def linklist(self):
|
||||||
termsize = Popen(['stty', 'size'], stdout=PIPE).communicate()[0].decode('utf8', 'replace')[:-1].split(' ')
|
termsize = self.__gettermsize()
|
||||||
termsize = [int(item) for item in termsize]
|
|
||||||
|
|
||||||
quoters = self.__quoters()
|
quoters = self.__quoters()
|
||||||
|
|
||||||
for ponydir in ponydirs: # Loop ponydirs
|
for ponydir in ponydirs: # Loop ponydirs
|
||||||
|
@ -317,6 +324,20 @@ class ponysay():
|
||||||
## Displaying methods
|
## Displaying methods
|
||||||
##
|
##
|
||||||
|
|
||||||
|
'''
|
||||||
|
Returns the cowsay command
|
||||||
|
'''
|
||||||
|
def __getcowsay(self):
|
||||||
|
isthink = 'think.py' in __file__
|
||||||
|
|
||||||
|
if isthink:
|
||||||
|
cowthink = os.environ['PONYSAY_COWTHINK'] if 'PONYSAY_COWTHINK' in os.environ else None
|
||||||
|
return 'cowthink' if (cowthink is None) or (cowthink == "") else cowthink
|
||||||
|
|
||||||
|
cowsay = os.environ['PONYSAY_COWSAY'] if 'PONYSAY_COWSAY' in os.environ else None
|
||||||
|
return 'cowsay' if (cowsay is None) or (cowsay == "") else cowsay
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Print the pony with a speech or though bubble
|
Print the pony with a speech or though bubble
|
||||||
'''
|
'''
|
||||||
|
@ -328,12 +349,9 @@ class ponysay():
|
||||||
|
|
||||||
pony = self.__getponypath(args.pony)
|
pony = self.__getponypath(args.pony)
|
||||||
|
|
||||||
if 'think.py' in __file__: cmd = 'cowthink'
|
|
||||||
else: cmd = 'cowsay'
|
|
||||||
|
|
||||||
if linuxvt:
|
if linuxvt:
|
||||||
print('\033[H\033[2J', end='')
|
print('\033[H\033[2J', end='')
|
||||||
os.system(cmd + (' -W ' + args.wrap if args.wrap is not None else '') + ' -f ' + pony + ' \'' + msg.replace('\'', '\'\\\'\'') + '\'')
|
os.system(self.__getcowsay() + (' -W ' + args.wrap if args.wrap is not None else '') + ' -f ' + pony + ' \'' + msg.replace('\'', '\'\\\'\'') + '\'')
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in a new issue