compio_term/lib.rs
1//! Completion-based terminal support for the [Compio](https://crates.io/crates/compio)
2//! runtime.
3//!
4//! This crate keeps Crossterm's event data model and command types. It replaces
5//! Crossterm's threaded event reader with a local Compio [`event::EventStream`]
6//! and writes queued commands through Compio [`io::AsyncWrite`] sinks. Event
7//! reading never starts a helper thread.
8//!
9//! Crossterm's cursor, style, terminal, and terminal detection modules are
10//! re-exported unchanged. Crossterm's synchronous command execution traits and
11//! macros are replaced by [`CommandQueue`], [`Commands`], and
12//! [`Queueable`].
13//!
14//! [`io::AsyncWrite`]: compio_io::AsyncWrite
15
16#![allow(unused_features)]
17#![warn(missing_docs)]
18#![deny(rustdoc::broken_intra_doc_links)]
19use std::io;
20
21use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
22
23mod command;
24pub mod event;
25
26pub use command::{CommandQueue, Commands, Queueable};
27pub use crossterm::{Command, cursor, style, terminal, tty};
28
29/// A guard that keeps the terminal in raw mode until it is dropped.
30#[derive(Debug)]
31#[must_use = "raw mode is disabled when the guard is dropped"]
32pub struct RawMode;
33
34impl RawMode {
35 /// Enables terminal raw mode.
36 pub fn enable() -> io::Result<Self> {
37 enable_raw_mode()?;
38 Ok(Self)
39 }
40}
41
42impl Drop for RawMode {
43 fn drop(&mut self) {
44 if let Err(error) = disable_raw_mode() {
45 compio_log::error!("failed to disable terminal raw mode: {error}");
46 }
47 }
48}