else/Clipext/clipext.py

48 lines
1.1 KiB
Python
Raw Normal View History

2016-08-18 01:24:38 +00:00
import pyperclip
CLIPBOARD_STRINGS = ['!c', '!clip', '!clipboard']
INPUT_STRINGS = ['!i', '!in', '!input', '!stdin']
EOF = '\x1a'
def _input_lines():
2016-08-18 01:24:38 +00:00
userinput = []
while True:
try:
additional = input()
except EOFError:
# If you enter nothing but ctrl-z
additional = EOF
2016-09-05 23:37:07 +00:00
else:
userinput.append(additional)
2016-08-18 01:24:38 +00:00
additional = additional.split(EOF)
has_eof = len(additional) > 1
additional = additional[0]
yield additional
if has_eof:
2016-08-18 01:24:38 +00:00
break
def multi_line_input(split_lines=False):
generator = _input_lines()
if split_lines:
return generator
else:
return '\n'.join(generator)
2016-08-18 01:24:38 +00:00
def resolve(arg, split_lines=False):
2016-08-18 01:24:38 +00:00
lowered = arg.lower()
if lowered in INPUT_STRINGS:
return multi_line_input(split_lines=split_lines)
elif lowered in CLIPBOARD_STRINGS:
text = pyperclip.paste()
else:
text = arg
if split_lines:
lines = text.splitlines()
return lines
else:
return text