Make --hold a bit more robust
This commit is contained in:
parent
266e70222f
commit
9aefcfe56f
20
__main__.py
20
__main__.py
@ -31,14 +31,26 @@ def runpy(args: List[str]) -> None:
|
|||||||
|
|
||||||
def hold(args: List[str]) -> None:
|
def hold(args: List[str]) -> None:
|
||||||
import subprocess
|
import subprocess
|
||||||
import tty
|
import termios
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
|
from kittens.tui.operations import init_state, set_cursor_visible
|
||||||
ret = subprocess.Popen(args[1:]).wait()
|
ret = subprocess.Popen(args[1:]).wait()
|
||||||
with suppress(BaseException):
|
with suppress(BaseException):
|
||||||
print('\n\x1b[1;32mPress any key to exit', end='', flush=True)
|
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):
|
with suppress(BaseException):
|
||||||
tty.setraw(sys.stdin.fileno())
|
fd = sys.stdin.fileno()
|
||||||
sys.stdin.buffer.read(1)
|
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()
|
||||||
raise SystemExit(ret)
|
raise SystemExit(ret)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -291,7 +291,7 @@ class MouseTracking(Enum):
|
|||||||
full = auto()
|
full = auto()
|
||||||
|
|
||||||
|
|
||||||
def init_state(alternate_screen: bool = True, mouse_tracking: MouseTracking = MouseTracking.none) -> str:
|
def init_state(alternate_screen: bool = True, mouse_tracking: MouseTracking = MouseTracking.none, kitty_keyboard_mode: bool = True) -> str:
|
||||||
sc = SAVE_CURSOR if alternate_screen else ''
|
sc = SAVE_CURSOR if alternate_screen else ''
|
||||||
ans = (
|
ans = (
|
||||||
S7C1T + sc + SAVE_PRIVATE_MODE_VALUES + reset_mode(Mode.LNM) +
|
S7C1T + sc + SAVE_PRIVATE_MODE_VALUES + reset_mode(Mode.LNM) +
|
||||||
@ -314,7 +314,10 @@ def init_state(alternate_screen: bool = True, mouse_tracking: MouseTracking = Mo
|
|||||||
ans += set_mode(Mode.MOUSE_MOTION_TRACKING)
|
ans += set_mode(Mode.MOUSE_MOTION_TRACKING)
|
||||||
elif mouse_tracking is MouseTracking.full:
|
elif mouse_tracking is MouseTracking.full:
|
||||||
ans += set_mode(Mode.MOUSE_MOVE_TRACKING)
|
ans += set_mode(Mode.MOUSE_MOVE_TRACKING)
|
||||||
|
if kitty_keyboard_mode:
|
||||||
ans += '\033[>31u' # extended keyboard mode
|
ans += '\033[>31u' # extended keyboard mode
|
||||||
|
else:
|
||||||
|
ans += '\033[>u' # legacy keyboard mode
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user