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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
use fmt;
use crateRect;
/// The area of the terminal that Ratatui draws into.
///
/// A [`Viewport`] controls where widgets render and what [`Frame::area`] returns.
///
/// For a higher-level overview of viewports in the context of an application (including
/// examples), see [`Terminal`].
///
/// Choose a viewport based on how the Ratatui UI should fit into the terminal:
///
/// - [`Viewport::Fullscreen`] for the standard case: your app owns the whole terminal surface.
/// - [`Viewport::Inline`] when the UI should live inside a larger CLI flow, with normal terminal
/// output above it.
/// - [`Viewport::Fixed`] when Ratatui should render into one region of a terminal layout managed
/// elsewhere.
///
/// In fullscreen mode, the viewport starts at (0, 0). In inline and fixed mode, the viewport may
/// have a non-zero `x`/`y` origin; prefer using `Frame::area()` as your root layout rectangle.
/// Code that assumes `(0, 0)` as the origin is therefore only correct for fullscreen viewports.
///
/// See [`Terminal::with_options`] for how to select a viewport, and [`Terminal::resize`] /
/// [`Terminal::autoresize`] for resize behavior.
///
/// # Example
///
/// ```rust,no_run
/// # #![allow(unexpected_cfgs)]
/// # #[cfg(feature = "crossterm")]
/// # {
/// use ratatui::backend::CrosstermBackend;
/// use ratatui::layout::{Constraint, Layout, Rect};
/// use ratatui::{Terminal, TerminalOptions, Viewport};
///
/// let mut terminal = Terminal::with_options(
/// CrosstermBackend::new(std::io::stdout()),
/// TerminalOptions {
/// viewport: Viewport::Fixed(Rect::new(10, 5, 20, 4)),
/// },
/// )?;
///
/// terminal.draw(|frame| {
/// // `frame.area()` is `Rect::new(10, 5, 20, 4)`, not `(0, 0, 20, 4)`.
/// let [title, body] =
/// Layout::vertical([Constraint::Length(1), Constraint::Min(0)]).areas(frame.area());
///
/// frame.render_widget("panel title", title);
/// frame.render_widget("render the body relative to the fixed viewport", body);
/// })?;
/// # }
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
///
/// [`Frame::area`]: crate::terminal::Frame::area
/// [`Terminal`]: crate::terminal::Terminal
/// [`Terminal::with_options`]: crate::terminal::Terminal::with_options
/// [`Terminal::resize`]: crate::terminal::Terminal::resize
/// [`Terminal::autoresize`]: crate::terminal::Terminal::autoresize