Debian Codegraph @

src/terminal.rs

raw symbols SCIP
1 //! Derived from TUI-rs, license: MIT, Copyright (c) 2016 Florian Dehau
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#, iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/};
3
4 use tuirust-analyzer cargo ratatui 0.30.0 crate/::{backendrust-analyzer cargo ratatui 0.30.0 backend/::Backendrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#, bufferrust-analyzer cargo ratatui-core 0.1.0 buffer/::Bufferrust-analyzer cargo ratatui-core 0.1.0 buffer/buffer/Buffer#, layoutrust-analyzer cargo ratatui-core 0.1.0 layout/::Rectrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#, preluderust-analyzer cargo ratatui 0.30.0 prelude/::Positionrust-analyzer cargo ratatui-core 0.1.0 layout/position/Position#};
5
6 /// A component meant to be rendered by `Terminal::render(...)`.
7 /// All other components don't have to implement this trait, and instead
8 /// provide a render method by convention, tuned towards their needs using whichever
9 /// generic types or lifetimes they need.
10 pub trait ToplevelComponentrust-analyzer cargo tui-react 0.24.0 terminal/ToplevelComponent# {
11 type Propsrust-analyzer cargo tui-react 0.24.0 terminal/ToplevelComponent#Props#;
12
13 fn renderrust-analyzer cargo tui-react 0.24.0 terminal/ToplevelComponent#render().(&mut self, props: impl Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<Self::Propsrust-analyzer cargo tui-react 0.24.0 terminal/ToplevelComponent#Props#>, area: Rectrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#, buf: &mut Bufferrust-analyzer cargo ratatui-core 0.1.0 buffer/buffer/Buffer#);
14 }
15
16 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
17 pub struct Terminalrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#<B>
18 where
19 B: Backendrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#,
20 {
21 pub backendrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#backend.: B,
22 buffersrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#buffers.: [Bufferrust-analyzer cargo ratatui-core 0.1.0 buffer/buffer/Buffer#; 2],
23 currentrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#current.: usize,
24 hidden_cursorrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#hidden_cursor.: bool,
25 known_sizerust-analyzer cargo tui-react 0.24.0 terminal/Terminal#known_size.: Rectrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#,
26 }
27
28 impl<B> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for Terminalrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#<B>
29 where
30 B: Backendrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#,
31 {
32 fn droprust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`][Drop]drop().(&mut self) {
33 // Attempt to restore the cursor state
34 if self.hidden_cursorrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#hidden_cursor. {
35 // We can't use the where clause in drop, so we need to work around it
36 // For backends that don't implement Into<io::Error>, this won't compile
37 // but that's acceptable since most real backends do implement this
38 let _ = self.backendrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#backend..show_cursorrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#show_cursor().();
39 }
40 }
41 }
42
43 impl<B> Terminalrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#<B>
44 where
45 B: Backendrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#,
46 {
47 pub fn newrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]new().(backend: B) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Terminalrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#<B>>
48 where
49 B::Errorrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#Error#: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
50 {
51 let size = backend.sizerust-analyzer cargo ratatui-core 0.1.0 backend/Backend#size().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]other().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
52 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Terminalrust-analyzer cargo tui-react 0.24.0 terminal/Terminal# {
53 backendrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#backend.,
54 buffersrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#buffers.: [Bufferrust-analyzer cargo ratatui-core 0.1.0 buffer/buffer/Buffer#::emptyrust-analyzer cargo ratatui-core 0.1.0 buffer/buffer/impl#[Buffer]empty().(size), Bufferrust-analyzer cargo ratatui-core 0.1.0 buffer/buffer/Buffer#::emptyrust-analyzer cargo ratatui-core 0.1.0 buffer/buffer/impl#[Buffer]empty().(size)],
55 currentrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#current.: 0,
56 hidden_cursorrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#hidden_cursor.: false,
57 known_sizerust-analyzer cargo tui-react 0.24.0 terminal/Terminal#known_size.: size,
58 })
59 }
60
61 pub fn current_buffer_mutrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]current_buffer_mut().(&mut self) -> &mut Bufferrust-analyzer cargo ratatui-core 0.1.0 buffer/buffer/Buffer# {
62 &mut self.buffersrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#buffers.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().self.currentrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#current.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().
63 }
64
65 pub fn reconcile_and_flushrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]reconcile_and_flush().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()>
66 where
67 B::Errorrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#Error#: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
68 {
69 let previous_buffer = &self.buffersrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#buffers.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().self.currentrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#current.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().;
70 let current_buffer = &self.buffersrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#buffers.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().self.currentrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#current.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().;
71 let updates = previous_buffer.diffrust-analyzer cargo ratatui-core 0.1.0 buffer/buffer/impl#[Buffer]diff().(current_buffer);
72 self.backendrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#backend.
73 .drawrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#draw().(updates.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().())
74 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]other().)
75 }
76
77 pub fn resizerust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]resize().(&mut self, area: Rectrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()>
78 where
79 B::Errorrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#Error#: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
80 {
81 self.buffersrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#buffers.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().self.currentrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#current.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()..resizerust-analyzer cargo ratatui-core 0.1.0 buffer/buffer/impl#[Buffer]resize().(area);
82 self.buffersrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#buffers.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().self.currentrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#current.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()..resetrust-analyzer cargo ratatui-core 0.1.0 buffer/buffer/impl#[Buffer]reset().();
83 self.buffersrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#buffers.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().self.currentrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#current.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()..resizerust-analyzer cargo ratatui-core 0.1.0 buffer/buffer/impl#[Buffer]resize().(area);
84 self.known_sizerust-analyzer cargo tui-react 0.24.0 terminal/Terminal#known_size. = area;
85 self.backendrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#backend..clearrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#clear().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]other().)
86 }
87
88 pub fn autoresizerust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]autoresize().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()>
89 where
90 B::Errorrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#Error#: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
91 {
92 let size = self.sizerust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]size().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
93 if self.known_sizerust-analyzer cargo tui-react 0.24.0 terminal/Terminal#known_size. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().size {
94 self.resizerust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]resize().(size)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
95 }
96 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
97 }
98
99 /// Get ready for rendering and return the maximum display size as `Rect`
100 pub fn pre_renderrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]pre_render().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Rectrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#>
101 where
102 B::Errorrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#Error#: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
103 {
104 // Autoresize - otherwise we get glitches if shrinking or potential desync between widgets
105 // and the terminal (if growing), which may OOB.
106 self.autoresizerust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]autoresize().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
107 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.known_sizerust-analyzer cargo tui-react 0.24.0 terminal/Terminal#known_size.)
108 }
109
110 pub fn post_renderrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]post_render().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()>
111 where
112 B::Errorrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#Error#: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
113 {
114 self.reconcile_and_flushrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]reconcile_and_flush().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
115
116 self.buffersrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#buffers.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().self.currentrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#current.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()..resetrust-analyzer cargo ratatui-core 0.1.0 buffer/buffer/impl#[Buffer]reset().();
117 self.currentrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#current. = 1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().self.currentrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#current.;
118
119 self.backendrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#backend..flushrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#flush().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]other().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
120 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
121 }
122
123 pub fn renderrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]render().<C>(&mut self, component: &mut C, props: impl Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<C::Propsrust-analyzer cargo tui-react 0.24.0 terminal/ToplevelComponent#Props#>) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()>
124 where
125 C: ToplevelComponentrust-analyzer cargo tui-react 0.24.0 terminal/ToplevelComponent#,
126 B::Errorrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#Error#: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
127 {
128 self.pre_renderrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]pre_render().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
129 component.renderrust-analyzer cargo tui-react 0.24.0 terminal/ToplevelComponent#render().(props, self.known_sizerust-analyzer cargo tui-react 0.24.0 terminal/Terminal#known_size., self.current_buffer_mutrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]current_buffer_mut().());
130 self.post_renderrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]post_render().()
131 }
132
133 pub fn hide_cursorrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]hide_cursor().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()>
134 where
135 B::Errorrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#Error#: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
136 {
137 self.backendrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#backend..hide_cursorrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#hide_cursor().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]other().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
138 self.hidden_cursorrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#hidden_cursor. = true;
139 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
140 }
141 pub fn show_cursorrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]show_cursor().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()>
142 where
143 B::Errorrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#Error#: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
144 {
145 self.backendrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#backend..show_cursorrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#show_cursor().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]other().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
146 self.hidden_cursorrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#hidden_cursor. = false;
147 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
148 }
149 pub fn get_cursorrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]get_cursor().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<(u16, u16)>
150 where
151 B::Errorrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#Error#: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
152 {
153 let pos = self
154 .backendrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#backend.
155 .get_cursor_positionrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#get_cursor_position().()
156 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]other().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
157 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((pos.xrust-analyzer cargo ratatui-core 0.1.0 layout/position/Position#x., pos.yrust-analyzer cargo ratatui-core 0.1.0 layout/position/Position#y.))
158 }
159 pub fn set_cursorrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]set_cursor().(&mut self, x: u16, y: u16) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()>
160 where
161 B::Errorrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#Error#: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
162 {
163 self.backendrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#backend.
164 .set_cursor_positionrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#set_cursor_position().(Positionrust-analyzer cargo ratatui-core 0.1.0 layout/position/Position# { xrust-analyzer cargo ratatui-core 0.1.0 layout/position/Position#x., yrust-analyzer cargo ratatui-core 0.1.0 layout/position/Position#y. })
165 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]other().)
166 }
167 pub fn clearrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]clear().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()>
168 where
169 B::Errorrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#Error#: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
170 {
171 self.backendrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#backend..clearrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#clear().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]other().)
172 }
173 pub fn sizerust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]size().(&self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Rectrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#>
174 where
175 B::Errorrust-analyzer cargo ratatui-core 0.1.0 backend/Backend#Error#: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static,
176 {
177 self.backendrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#backend.
178 .sizerust-analyzer cargo ratatui-core 0.1.0 backend/Backend#size().()
179 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]other().)
180 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|size| size.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
181 }
182 }
183
184 #[cfg(test)]
185 mod testsrust-analyzer cargo tui-react 0.24.0 terminal/tests/ {
186 use superrust-analyzer cargo tui-react 0.24.0 terminal/::*;
187 use tuirust-analyzer cargo ratatui 0.30.0 crate/::backendrust-analyzer cargo ratatui 0.30.0 backend/::TestBackendrust-analyzer cargo ratatui-core 0.1.0 backend/test/TestBackend#;
188
189 #[expect(dead_code)]
190 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
191 struct ComplexPropsrust-analyzer cargo tui-react 0.24.0 terminal/tests/ComplexProps# {
192 xrust-analyzer cargo tui-react 0.24.0 terminal/tests/ComplexProps#x.: usize,
193 yrust-analyzer cargo tui-react 0.24.0 terminal/tests/ComplexProps#y.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
194 }
195
196 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
197 struct StatefulComponentrust-analyzer cargo tui-react 0.24.0 terminal/tests/StatefulComponent# {
198 xrust-analyzer cargo tui-react 0.24.0 terminal/tests/StatefulComponent#x.: usize,
199 }
200
201 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
202 struct StatelessComponentrust-analyzer cargo tui-react 0.24.0 terminal/tests/StatelessComponent#;
203
204 impl ToplevelComponentrust-analyzer cargo tui-react 0.24.0 terminal/ToplevelComponent# for StatefulComponentrust-analyzer cargo tui-react 0.24.0 terminal/tests/StatefulComponent# {
205 type Propsrust-analyzer cargo tui-react 0.24.0 terminal/tests/impl#[StatefulComponent][ToplevelComponent]Props# = usize;
206
207 fn renderrust-analyzer cargo tui-react 0.24.0 terminal/tests/impl#[StatefulComponent][ToplevelComponent]render().(&mut self, props: impl Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<Selfrust-analyzer cargo tui-react 0.24.0 terminal/tests/impl#[StatefulComponent][ToplevelComponent]::Propsrust-analyzer cargo tui-react 0.24.0 terminal/ToplevelComponent#Props#>, _area: Rectrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#, _buf: &mut Bufferrust-analyzer cargo ratatui-core 0.1.0 buffer/buffer/Buffer#) {
208 self.xrust-analyzer cargo tui-react 0.24.0 terminal/tests/StatefulComponent#x. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().props.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#borrow().();
209 }
210 }
211
212 impl ToplevelComponentrust-analyzer cargo tui-react 0.24.0 terminal/ToplevelComponent# for StatelessComponentrust-analyzer cargo tui-react 0.24.0 terminal/tests/StatelessComponent# {
213 type Propsrust-analyzer cargo tui-react 0.24.0 terminal/tests/impl#[StatelessComponent][ToplevelComponent]Props# = ComplexPropsrust-analyzer cargo tui-react 0.24.0 terminal/tests/ComplexProps#;
214 fn renderrust-analyzer cargo tui-react 0.24.0 terminal/tests/impl#[StatelessComponent][ToplevelComponent]render().(&mut self, _props: impl Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<Selfrust-analyzer cargo tui-react 0.24.0 terminal/tests/impl#[StatelessComponent][ToplevelComponent]::Propsrust-analyzer cargo tui-react 0.24.0 terminal/ToplevelComponent#Props#>, _area: Rectrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#, _buf: &mut Bufferrust-analyzer cargo ratatui-core 0.1.0 buffer/buffer/Buffer#) {
215 // does not matter - we want to see it compiles essentially
216 }
217 }
218
219 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
220 fn it_does_render_with_simple_and_complex_propsrust-analyzer cargo tui-react 0.24.0 terminal/tests/it_does_render_with_simple_and_complex_props().() {
221 let mut term = Terminalrust-analyzer cargo tui-react 0.24.0 terminal/Terminal#::newrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]new().(TestBackendrust-analyzer cargo ratatui-core 0.1.0 backend/test/TestBackend#::newrust-analyzer cargo ratatui-core 0.1.0 backend/test/impl#[TestBackend]new().(20, 20)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
222 let mut c = StatefulComponentrust-analyzer cargo tui-react 0.24.0 terminal/tests/StatefulComponent#::defaultrust-analyzer cargo tui-react 0.24.0 terminal/tests/impl#[StatefulComponent][Default]default().();
223
224 term.renderrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]render().(&mut c, 3usize).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().();
225 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(c.xrust-analyzer cargo tui-react 0.24.0 terminal/tests/StatefulComponent#x., 3);
226
227 let mut c = StatelessComponentrust-analyzer cargo tui-react 0.24.0 terminal/tests/StatelessComponent#;
228 term.renderrust-analyzer cargo tui-react 0.24.0 terminal/impl#[`Terminal<B>`]render().(&mut c, ComplexPropsrust-analyzer cargo tui-react 0.24.0 terminal/tests/ComplexProps#::defaultrust-analyzer cargo tui-react 0.24.0 terminal/tests/impl#[ComplexProps][Default]default().()).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().();
229 }
230 }