#[non_exhaustive]pub struct Cursor { /* private fields */ }Implementations§
Source§impl Cursor
impl Cursor
Sourcepub const fn overlay_style(self, overlay_style: Style) -> Self
pub const fn overlay_style(self, overlay_style: Style) -> Self
Sets the overlay style for the cursor.
The overlay style is used when the cursor overlaps with existing content on the screen.
§Arguments
overlay_style: TheStyleto set as the overlay style for the cursor.
§Example
use ratatui_core::style::Style;
use tui_term::widget::Cursor;
let cursor = Cursor::default().overlay_style(Style::default());Sourcepub const fn visibility(self, show: bool) -> Self
pub const fn visibility(self, show: bool) -> Self
Set the visibility of the cursor (default = shown)
Examples found in repository?
examples/simple_ls_controller.rs (line 78)
60fn ui(f: &mut Frame, screen: &Screen) {
61 let chunks = ratatui::layout::Layout::default()
62 .direction(ratatui::layout::Direction::Vertical)
63 .margin(1)
64 .constraints(
65 [
66 ratatui::layout::Constraint::Percentage(100),
67 ratatui::layout::Constraint::Min(1),
68 ]
69 .as_ref(),
70 )
71 .split(f.area());
72 let title = Line::from("[ Running: ls ]");
73 let block = Block::default()
74 .borders(Borders::ALL)
75 .title(title)
76 .style(Style::default().add_modifier(Modifier::BOLD));
77 let pseudo_term = PseudoTerminal::new(screen)
78 .cursor(tui_term::widget::Cursor::default().visibility(false))
79 .block(block.clone());
80 f.render_widget(pseudo_term, chunks[0]);
81 let explanation = "Press q to exit";
82 let explanation = Paragraph::new(explanation)
83 .style(Style::default().add_modifier(Modifier::BOLD | Modifier::REVERSED))
84 .alignment(Alignment::Center);
85 f.render_widget(explanation, chunks[1]);
86}Sourcepub fn hide(&mut self)
pub fn hide(&mut self)
Hide the cursor
Examples found in repository?
examples/smux.rs (line 86)
44async fn run_smux(terminal: &mut DefaultTerminal) -> io::Result<()> {
45 let mut size = Size {
46 rows: terminal.size()?.height,
47 cols: terminal.size()?.width,
48 };
49
50 let cwd = std::env::current_dir().unwrap();
51 let mut cmd = CommandBuilder::new_default_prog();
52 cmd.cwd(cwd);
53
54 let mut panes: Vec<PtyPane> = Vec::new();
55 let mut active_pane: Option<usize> = None;
56
57 let pane_size = calc_pane_size(size, 1);
58 open_new_pane(&mut panes, &mut active_pane, &cmd, pane_size)?;
59
60 loop {
61 terminal.draw(|f| {
62 let chunks = Layout::default()
63 .direction(Direction::Vertical)
64 .margin(1)
65 .constraints([Constraint::Percentage(100), Constraint::Min(1)].as_ref())
66 .split(f.area());
67
68 let pane_height = if panes.is_empty() {
69 chunks[0].height
70 } else {
71 (chunks[0].height.saturating_sub(1)) / panes.len() as u16
72 };
73
74 for (index, pane) in panes.iter().enumerate() {
75 let block = Block::default()
76 .borders(Borders::ALL)
77 .style(Style::default().add_modifier(Modifier::BOLD));
78 let mut cursor = Cursor::default();
79 let block = if Some(index) == active_pane {
80 block.style(
81 Style::default()
82 .add_modifier(Modifier::BOLD)
83 .fg(Color::LightMagenta),
84 )
85 } else {
86 cursor.hide();
87 block
88 };
89 let parser = pane.parser.read().unwrap();
90 let screen = parser.screen();
91 let pseudo_term = PseudoTerminal::new(screen).block(block).cursor(cursor);
92 let pane_chunk = Rect {
93 x: chunks[0].x,
94 y: chunks[0].y + (index as u16 * pane_height), /* Adjust the y coordinate for
95 * each pane */
96 width: chunks[0].width,
97 height: pane_height, // Use the calculated pane height directly
98 };
99 f.render_widget(pseudo_term, pane_chunk);
100 }
101
102 let explanation =
103 "Ctrl+n to open a new pane | Ctrl+x to close the active pane | Ctrl+q to quit";
104 let explanation = Paragraph::new(explanation)
105 .style(Style::default().add_modifier(Modifier::BOLD | Modifier::REVERSED))
106 .alignment(Alignment::Center);
107 f.render_widget(explanation, chunks[1]);
108 })?;
109
110 if event::poll(Duration::from_millis(10))? {
111 tracing::info!("Terminal Size: {:?}", terminal.size());
112 match event::read()? {
113 Event::Key(key) => match key.code {
114 KeyCode::Char('q') if key.modifiers.contains(KeyModifiers::CONTROL) => {
115 return Ok(());
116 }
117 KeyCode::Char('n') if key.modifiers.contains(KeyModifiers::CONTROL) => {
118 let pane_size = calc_pane_size(size, panes.len() + 1);
119 tracing::info!("Opened new pane with size: {size:?}");
120 resize_all_panes(&mut panes, pane_size);
121 open_new_pane(&mut panes, &mut active_pane, &cmd, pane_size)?;
122 }
123 KeyCode::Char('x') if key.modifiers.contains(KeyModifiers::CONTROL) => {
124 close_active_pane(&mut panes, &mut active_pane).await?;
125 resize_all_panes(&mut panes, pane_size);
126 }
127 KeyCode::Char('k') if key.modifiers.contains(KeyModifiers::CONTROL) => {
128 if let Some(pane) = active_pane {
129 active_pane = Some(pane.saturating_sub(1));
130 }
131 }
132 KeyCode::Char('j') if key.modifiers.contains(KeyModifiers::CONTROL) => {
133 if let Some(pane) = active_pane {
134 if pane < panes.len() - 1 {
135 active_pane = Some(pane.saturating_add(1));
136 }
137 }
138 }
139 _ => {
140 if let Some(index) = active_pane {
141 if handle_pane_key_event(&mut panes[index], &key).await {
142 continue;
143 }
144 }
145 }
146 },
147 Event::Resize(cols, rows) => {
148 tracing::info!("Resized to: rows: {} cols: {}", rows, cols);
149 size.rows = rows;
150 size.cols = cols;
151 let pane_size = calc_pane_size(size, panes.len());
152 resize_all_panes(&mut panes, pane_size);
153 }
154 _ => {}
155 }
156 }
157
158 cleanup_exited_panes(&mut panes, &mut active_pane);
159
160 if panes.is_empty() {
161 return Ok(());
162 }
163 }
164}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Cursor
impl RefUnwindSafe for Cursor
impl Send for Cursor
impl Sync for Cursor
impl Unpin for Cursor
impl UnwindSafe for Cursor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more