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
//! Terminal handles, raw-mode state, window-size queries, and tty helpers.
//!
//! The terminal module provides the building blocks used by renderers and
//! event sources: [`Terminal`] for pairing input and output handles,
//! raw-mode save/restore helpers, direct stdio handles, controlling-terminal
//! opening, and environment lookups.
//!
//! ## The `Terminal<I, O>` handle
//!
//! [`Terminal`] owns an input half, an output half, an [`Env`], and an
//! optional saved raw-mode [`State`]. It implements [`std::io::Read`] by
//! reading from the input half and [`std::io::Write`] by writing to the output
//! half. Use [`Terminal::stdio`] for inherited stdin/stdout, or
//! [`Terminal::open`] to talk directly to the controlling terminal when stdio
//! may be redirected.
//!
//! ## Raw-mode lifecycle
//!
//! Raw mode is an explicit save/apply/restore flow. [`Terminal::make_raw`]
//! calls `make_raw_mode`, stores the returned [`State`] inside the
//! `Terminal`, and returns a clone of that state. [`Terminal::restore`] applies
//! the stored state with `set_state` and clears it. The free functions expose
//! the same lifecycle for callers that manage handles and state themselves.
//!
//! ```text
//! normal terminal state
//! │
//! │ make_raw() -> State
//! ▼
//! raw terminal state ────── use terminal ──────┐
//! │ │
//! └──────── restore()/set_state(State) ◀
//! ```
//!
//! There is no paired enable/disable function in this API; keep the returned
//! [`State`] or the [`Terminal`] that cached it, and restore explicitly.
//!
//! ## Window size
//!
//! `get_window_size` queries the operating system for cell dimensions and,
//! where available, pixel dimensions. [`Terminal::get_window_size`] applies the
//! platform-specific handle selection: Unix tries output first, then input;
//! Windows queries the output console screen buffer.
//!
//! ## Stdio and controlling-terminal handles
//!
//! [`stdin`], [`stdout`], and [`stderr`] wrap the inherited process streams as
//! cheap, copyable, unbuffered handles. `open_tty` opens the controlling
//! terminal directly: Unix uses `/dev/tty` for both halves, and Windows uses
//! `CONIN$` for input and `CONOUT$` for output. The direct tty path is useful
//! for applications whose stdin or stdout may be a pipe but which still need a
//! real terminal.
//!
//! ```rust,ignore
//! use uncurses::terminal::Terminal;
//!
//! let mut term = Terminal::stdio();
//! let saved = term.make_raw()?;
//! let size = term.get_window_size()?;
//! let _ = (saved, size.col, size.row);
//! term.restore()?;
//! # Ok::<(), std::io::Error>(())
//! ```
pub use ;
pub use Terminal;
pub use State;
pub use Winsize;
pub use ;
pub use ;
pub use get_window_size;