Make hold_till_enter re-useable
This commit is contained in:
parent
04807453ec
commit
a155b081b7
21
__main__.py
21
__main__.py
@ -31,26 +31,9 @@ def runpy(args: List[str]) -> None:
|
||||
|
||||
def hold(args: List[str]) -> None:
|
||||
import subprocess
|
||||
import termios
|
||||
from contextlib import suppress
|
||||
from kittens.tui.operations import init_state, set_cursor_visible
|
||||
ret = subprocess.Popen(args[1:]).wait()
|
||||
with suppress(BaseException):
|
||||
print(
|
||||
'\n\x1b[1;32mPress Enter to exit',
|
||||
end=init_state(alternate_screen=False, kitty_keyboard_mode=False) + set_cursor_visible(False),
|
||||
flush=True)
|
||||
with suppress(BaseException):
|
||||
fd = sys.stdin.fileno()
|
||||
old = termios.tcgetattr(fd)
|
||||
new = old[:]
|
||||
new[3] &= ~termios.ECHO # 3 == 'lflags'
|
||||
tcsetattr_flags = termios.TCSAFLUSH
|
||||
if hasattr(termios, 'TCSASOFT'):
|
||||
tcsetattr_flags |= getattr(termios, 'TCSASOFT')
|
||||
termios.tcsetattr(fd, tcsetattr_flags, new)
|
||||
with suppress(KeyboardInterrupt):
|
||||
input()
|
||||
from kitty.utils import hold_till_enter
|
||||
hold_till_enter()
|
||||
raise SystemExit(ret)
|
||||
|
||||
|
||||
|
||||
@ -852,3 +852,24 @@ def control_codes_pat() -> 'Pattern[str]':
|
||||
|
||||
def sanitize_control_codes(text: str, replace_with: str = '') -> str:
|
||||
return control_codes_pat().sub(replace_with, text)
|
||||
|
||||
|
||||
def hold_till_enter() -> None:
|
||||
import termios
|
||||
from kittens.tui.operations import init_state, set_cursor_visible
|
||||
with suppress(BaseException):
|
||||
print(
|
||||
'\n\x1b[1;32mPress Enter to exit',
|
||||
end=init_state(alternate_screen=False, kitty_keyboard_mode=False) + set_cursor_visible(False),
|
||||
flush=True)
|
||||
with suppress(BaseException):
|
||||
fd = sys.stdin.fileno()
|
||||
old = termios.tcgetattr(fd)
|
||||
new = old[:]
|
||||
new[3] &= ~termios.ECHO # 3 == 'lflags'
|
||||
tcsetattr_flags = termios.TCSAFLUSH
|
||||
if hasattr(termios, 'TCSASOFT'):
|
||||
tcsetattr_flags |= getattr(termios, 'TCSASOFT')
|
||||
termios.tcsetattr(fd, tcsetattr_flags, new)
|
||||
with suppress(KeyboardInterrupt):
|
||||
input()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user