Get --hold to work even when stdin is redirected
This commit is contained in:
parent
9b2db6ec53
commit
fc17528337
@ -860,13 +860,15 @@ def sanitize_control_codes(text: str, replace_with: str = '') -> str:
|
||||
def hold_till_enter() -> None:
|
||||
import termios
|
||||
from kittens.tui.operations import init_state, set_cursor_visible
|
||||
term = os.ctermid() or '/dev/tty'
|
||||
with open(term, 'w') as tty:
|
||||
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()
|
||||
flush=True, file=tty)
|
||||
with suppress(BaseException), open(term, 'rb') as inp:
|
||||
fd = inp.fileno()
|
||||
old = termios.tcgetattr(fd)
|
||||
new = old[:]
|
||||
new[3] &= ~termios.ECHO # 3 == 'lflags'
|
||||
@ -875,4 +877,5 @@ def hold_till_enter() -> None:
|
||||
tcsetattr_flags |= getattr(termios, 'TCSASOFT')
|
||||
termios.tcsetattr(fd, tcsetattr_flags, new)
|
||||
with suppress(KeyboardInterrupt):
|
||||
input()
|
||||
while inp.read(1) not in b'\n\r':
|
||||
pass
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user