os.tty – Terminal control functions
Example
The code:
from os.tty import set_to_cbreak_mode
from os.tty import is_tty
from os import STDIN
# ToDo: Should not be needed.
from os import Stdin
func main():
if is_tty(0):
set_to_cbreak_mode(0)
while True:
value = STDIN.get()
if value == 4 or value == -1:
break
print(f"Got '{char(value)}'.")
Build and run:
❯ mys build
✔ Reading package configuration (0 seconds)
✔ Building (0.01 seconds)
❯ ./build/speed/app
Got '1'.
Got '2'.
Got '3'.
Got 'a'.
Got 'b'.
Got 'c'.
API
func set_to_raw_mode(fd: i64):
Set the mode of given file descriptor to raw.
func set_to_cbreak_mode(fd: i64):
Set the mode of given file descriptor to cbreak.
func is_tty(fd: i64) -> bool:
Returns True if given file descriptor is a TTY, False otherwise.