1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//! Terminal event-reading backend trait and implementations
//!
//! # Backend implementations
//!
//! Backend implements reading terminal events and is mainly used in
//! combination of [`Term`](crate::term::Term).
//!
//! Currently two backends are supported:
//! - [`CrosstermBackend`] - requires
//! `backend-crossterm` feature (default).
//! - [`TermalBackend`] - requires
//! `backend-termal` feature.
//!
//! You can create new [`Term`](crate::term::Term) with specified backend like
//! this:
//! ```rust
//! use termint::prelude::*;
//!
//! let term = Term::<(), TermalBackend>::new();
//! ```
//!
//! # Backend trait
//!
//! This trait is can be used to implement a custom backend.
//!
//! # Example
//!
//! Reading events from the given backend:
//!
//! ```rust
//! use std::{io::Write, time::Duration};
//! use termint::{
//! prelude::*,
//! term::{
//! backend::Backend, enable_bracketed_paste, enable_mouse_capture,
//! disable_bracketed_paste, disable_mouse_capture
//! }
//! };
//! use termal::raw::{disable_raw_mode, enable_raw_mode};
//!
//! fn print_events<B: Backend>(mut backend: B) -> Result<(), Error> {
//! enable_raw_mode()?;
//! enable_bracketed_paste();
//! enable_mouse_capture();
//!
//! let mut stdout = std::io::stdout();
//! let mut timeout = Duration::from_millis(100);
//! loop {
//! if let Some(event) = backend.read_event(timeout)? {
//! print!("{:?}\n\r", event);
//! _ = stdout.flush();
//! }
//! }
//!
//! disable_bracketed_paste();
//! disable_mouse_capture();
//! disable_raw_mode()?;
//! Ok(())
//! }
//! ```
use Duration;
pub use CrosstermBackend;
pub use *;
pub use TermalBackend;
use crateError;
pub type DefaultBackend = CrosstermBackend;
pub type DefaultBackend = TermalBackend;
pub type DefaultBackend = NoBackend;
/// Backend trait allows creating custom backends, which then can be used as
/// a custom [`Term`](crate::term::Term) backend in the Framework mode.
/// This is used when no backend feature is enabled. When
/// [`Term`](crate::term::Term) has `NoBackend`, the Framework mode is
/// disabled.
///
/// # Example
///
/// If you want to use the `NoBackend` with [`Term`](crate::term::Term), you
/// can create it like this:
///
/// ```rust
/// use termint::prelude::*;
/// use termint::term::backend::NoBackend;
///
/// Term::<NoBackend>::new();
/// ```
;