#terminal #tiny #cli #termios #linux-terminal #api-bindings #read-key

read-key-termios

Simple key-reading using Termios from Libc. Unsafe for obvious reasons. Also doesn't work on Windows for obvious reasons.

1 unstable release

0.1.0 Jul 10, 2024

#1491 in Command line utilities

MIT license

5KB

Read Key (Termios)

This is a tiny crate that adds functionality for entering and leaving raw mode on Linux. It is useful when you are making a small CLI application and you don't want to add a ton of dependencies.

Functions

init(): Enters raw mode by disabling ICANON and ECHO.
close(): Exits raw mode by enabling ICANON and ECHO.
read_key(fd: i32) -> u8: Reads a key from the FD specified.


lib.rs:

Read Key (Termios): A tiny crate to read keys on Linux without introducing a huge amount of dependencies.

fn read_key(fd: i32) -> u8; Takes in the FD to read. Blocks until a key has been pressed. This should be used with polling acceptably. It retuns a byte for the user to parse.

fn init(); Enters raw mode, and allows the keys to start being read.

fn close(): Enters cooked mode. Read_key() will not work after this.

No runtime deps