Basic ask kitten
This commit is contained in:
parent
dc6ef63ddd
commit
3790af6897
0
kittens/ask/__init__.py
Normal file
0
kittens/ask/__init__.py
Normal file
51
kittens/ask/main.py
Normal file
51
kittens/ask/main.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# vim:fileencoding=utf-8
|
||||||
|
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
import json
|
||||||
|
import readline
|
||||||
|
import sys
|
||||||
|
from gettext import gettext as _
|
||||||
|
|
||||||
|
from kitty.cli import parse_args
|
||||||
|
|
||||||
|
from ..tui.operations import alternate_screen, styled
|
||||||
|
|
||||||
|
|
||||||
|
def option_text():
|
||||||
|
return '''\
|
||||||
|
--type -t
|
||||||
|
choices=line
|
||||||
|
default=line
|
||||||
|
Type of input. Defaults to asking for a line of text.
|
||||||
|
|
||||||
|
|
||||||
|
--message -m
|
||||||
|
The message to display to the user. If not specified a default
|
||||||
|
message is shown.
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
def main(args=sys.argv):
|
||||||
|
msg = 'Ask the user for input'
|
||||||
|
try:
|
||||||
|
args, items = parse_args(args[1:], option_text, '', msg, 'kitty ask')
|
||||||
|
except SystemExit as e:
|
||||||
|
print(e.args[0], file=sys.stderr)
|
||||||
|
input('Press enter to quit...')
|
||||||
|
return 1
|
||||||
|
|
||||||
|
with alternate_screen():
|
||||||
|
if args.message:
|
||||||
|
print(styled(args.message), bold=True)
|
||||||
|
|
||||||
|
readline.read_init_file()
|
||||||
|
|
||||||
|
prompt = ': '
|
||||||
|
if args.type == 'line':
|
||||||
|
prompt = _('Enter line: ')
|
||||||
|
try:
|
||||||
|
ans = input(prompt)
|
||||||
|
except (KeyboardInterrupt, EOFError):
|
||||||
|
return
|
||||||
|
print('OK:', json.dumps(ans))
|
||||||
@ -2,6 +2,7 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
import sys
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
from kitty.terminfo import string_capabilities
|
from kitty.terminfo import string_capabilities
|
||||||
@ -151,3 +152,11 @@ def cursor(write):
|
|||||||
write(SAVE_CURSOR)
|
write(SAVE_CURSOR)
|
||||||
yield
|
yield
|
||||||
write(RESTORE_CURSOR)
|
write(RESTORE_CURSOR)
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def alternate_screen(f=None):
|
||||||
|
f = f or sys.stdout
|
||||||
|
print(set_mode('ALTERNATE_SCREEN'), end='', file=f)
|
||||||
|
yield
|
||||||
|
print(reset_mode('ALTERNATE_SCREEN'), end='', file=f)
|
||||||
|
|||||||
@ -231,7 +231,7 @@ expression instead.
|
|||||||
|
|
||||||
--url-prefixes
|
--url-prefixes
|
||||||
default={0}
|
default={0}
|
||||||
Comma separeted list of recognized URL prefixes. Defaults to:
|
Comma separated list of recognized URL prefixes. Defaults to:
|
||||||
{0}
|
{0}
|
||||||
'''.format, ','.join(sorted(URL_PREFIXES)))
|
'''.format, ','.join(sorted(URL_PREFIXES)))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user