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:
|
def hold_till_enter() -> None:
|
||||||
import termios
|
import termios
|
||||||
from kittens.tui.operations import init_state, set_cursor_visible
|
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):
|
with suppress(BaseException):
|
||||||
print(
|
print(
|
||||||
'\n\x1b[1;32mPress Enter to exit',
|
'\n\x1b[1;32mPress Enter to exit',
|
||||||
end=init_state(alternate_screen=False, kitty_keyboard_mode=False) + set_cursor_visible(False),
|
end=init_state(alternate_screen=False, kitty_keyboard_mode=False) + set_cursor_visible(False),
|
||||||
flush=True)
|
flush=True, file=tty)
|
||||||
with suppress(BaseException):
|
with suppress(BaseException), open(term, 'rb') as inp:
|
||||||
fd = sys.stdin.fileno()
|
fd = inp.fileno()
|
||||||
old = termios.tcgetattr(fd)
|
old = termios.tcgetattr(fd)
|
||||||
new = old[:]
|
new = old[:]
|
||||||
new[3] &= ~termios.ECHO # 3 == 'lflags'
|
new[3] &= ~termios.ECHO # 3 == 'lflags'
|
||||||
@ -875,4 +877,5 @@ def hold_till_enter() -> None:
|
|||||||
tcsetattr_flags |= getattr(termios, 'TCSASOFT')
|
tcsetattr_flags |= getattr(termios, 'TCSASOFT')
|
||||||
termios.tcsetattr(fd, tcsetattr_flags, new)
|
termios.tcsetattr(fd, tcsetattr_flags, new)
|
||||||
with suppress(KeyboardInterrupt):
|
with suppress(KeyboardInterrupt):
|
||||||
input()
|
while inp.read(1) not in b'\n\r':
|
||||||
|
pass
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user