Skip to main content

repline/
raw.rs

1//! Sets the terminal to [`raw`] mode for the duration of the returned object's lifetime.
2
3/// Sets the terminal to raw mode for the duration of the returned object's lifetime.
4pub fn raw() -> impl Drop {
5    Raw::default()
6}
7
8/// Internal [`Drop`] object for [`raw`]
9struct Raw();
10
11impl Default for Raw {
12    fn default() -> Self {
13        std::thread::yield_now();
14        crossterm::terminal::enable_raw_mode().expect("should be able to transition into raw mode");
15        Raw()
16    }
17}
18
19impl Drop for Raw {
20    fn drop(&mut self) {
21        crossterm::terminal::disable_raw_mode()
22            .expect("should be able to transition out of raw mode");
23    }
24}