Crate terminal_utils

Source
Expand description

§Usage

This crate provides utilities for working with the terminal.

§Terminal size

let size = terminal_utils::size().unwrap();
println!("The terminal is {}x{} characters.", size.width, size.height);

§Raw mode

let raw_mode_guard = terminal_utils::enable_raw_mode().unwrap();
println!("Raw mode is enabled.");

let is_raw_mode_enabled = terminal_utils::is_raw_mode_enabled().unwrap();
assert!(is_raw_mode_enabled);

// Previous terminal mode is restored when the guard is dropped.
drop(raw_mode_guard);
println!("Raw mode is disabled.");

§Resize signal

This feature is only available with the tokio feature. It is enabled by default.

let mut resize_rx = terminal_utils::on_resize().unwrap();
tokio::spawn(async move {
    loop {
        resize_rx.changed().await.unwrap();

        let size = resize_rx.borrow();
        println!("terminal size changed: {:?}", size);
    }
});

Structs§

RawModeGuard
A guard that restores the previous terminal mode when dropped.
TerminalSize

Functions§

enable_raw_mode
Enables raw mode. Once the returned guard is dropped, the previous mode is restored.
is_raw_mode_enabled
Tells whether the raw mode is currently enabled.
on_resize
Returns a receiver that receives a signal when the terminal is resized.
size
Returns the size of the terminal.