#input-event #terminal-input #key-input #crossterm #events

deprecated crossterm_input

A cross-platform library for reading userinput

15 releases (4 breaking)

0.5.0 Oct 21, 2019
0.3.9 Aug 2, 2019
0.3.8 Jul 25, 2019
0.1.0 Jan 27, 2019

#7 in #key-input

Download history 439/week @ 2023-11-20 360/week @ 2023-11-27 232/week @ 2023-12-04 272/week @ 2023-12-11 390/week @ 2023-12-18 275/week @ 2023-12-25 197/week @ 2024-01-01 592/week @ 2024-01-08 513/week @ 2024-01-15 476/week @ 2024-01-22 336/week @ 2024-01-29 375/week @ 2024-02-05 408/week @ 2024-02-12 303/week @ 2024-02-19 536/week @ 2024-02-26 422/week @ 2024-03-04

1,722 downloads per month
Used in 7 crates (5 directly)

MIT license

91KB
1.5K SLoC

Lines of Code Latest Version MIT docs Join us on Discord

Crossterm Input

The crossterm_input crate is deprecated and no longer maintained. The GitHub repository will be archived soon. All the code is being moved to the crossterm crate. You can learn more in the Merge sub-crates to the crossterm crate issue.

This crate allows you to read the user input cross-platform. It supports all UNIX and Windows terminals down to Windows 7 (not all terminals are tested see Tested Terminals for more info).

crossterm_input is a sub-crate of the crossterm crate. You can use it directly, but it's highly recommended to use the crossterm crate with the input feature enabled.

Features

  • Cross-platform
  • Multi-threaded (send, sync)
  • Detailed documentation
  • Few dependencies
  • Input
    • Read character
    • Read line
    • Read key input events (async / sync)
    • Read mouse input events (press, release, position, button)
    • Raw screen

Getting Started

Click to show Cargo.toml.
[dependencies]
# All crossterm features are enabled by default.
crossterm = "0.11"

use crossterm::{input, InputEvent, KeyEvent, MouseButton, MouseEvent, RawScreen, Result};

fn main() -> Result<()> {
    // Keep _raw around, raw mode will be disabled on the _raw is dropped
    let _raw = RawScreen::into_raw_mode()?;

    let input = input();
    input.enable_mouse_mode()?;

    let mut sync_stdin = input.read_sync();

    loop {
        if let Some(event) = sync_stdin.next() {
            match event {
                InputEvent::Keyboard(KeyEvent::Esc) => break,
                InputEvent::Keyboard(KeyEvent::Left) => println!("Left arrow"),
                InputEvent::Mouse(MouseEvent::Press(MouseButton::Left, col, row)) => {
                    println!("Left mouse button pressed at {}x{}", col, row);
                }
                _ => println!("Other event {:?}", event),
            }
        }
    }

    input.disable_mouse_mode()
} // <- _raw dropped = raw mode disabled

Other Resources

Authors

  • Timon Post - Project Owner & creator
  • Dave Ho - Contributor

License

This project is licensed under the MIT License - see the LICENSE file for details

Dependencies

~0.6–1.2MB
~19K SLoC