Cursor

Struct Cursor 

Source
#[non_exhaustive]
pub struct Cursor { /* private fields */ }

Implementations§

Source§

impl Cursor

Source

pub fn symbol(self, symbol: &str) -> Self

Sets the symbol for the cursor.

§Arguments
  • symbol: The symbol to set as the cursor.
§Example
use ratatui::style::Style;
use tui_term::widget::Cursor;

let cursor = Cursor::default().symbol("|");
Source

pub const fn style(self, style: Style) -> Self

Sets the style for the cursor.

§Arguments
  • style: The Style to set for the cursor.
§Example
use ratatui::style::Style;
use tui_term::widget::Cursor;

let cursor = Cursor::default().style(Style::default());
Source

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: The Style to set as the overlay style for the cursor.
§Example
use ratatui::style::Style;
use tui_term::widget::Cursor;

let cursor = Cursor::default().overlay_style(Style::default());
Source

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 75)
57fn ui(f: &mut Frame, screen: &Screen) {
58    let chunks = ratatui::layout::Layout::default()
59        .direction(ratatui::layout::Direction::Vertical)
60        .margin(1)
61        .constraints(
62            [
63                ratatui::layout::Constraint::Percentage(100),
64                ratatui::layout::Constraint::Min(1),
65            ]
66            .as_ref(),
67        )
68        .split(f.area());
69    let title = Line::from("[ Running: ls ]");
70    let block = Block::default()
71        .borders(Borders::ALL)
72        .title(title)
73        .style(Style::default().add_modifier(Modifier::BOLD));
74    let pseudo_term = PseudoTerminal::new(screen)
75        .cursor(tui_term::widget::Cursor::default().visibility(false))
76        .block(block.clone());
77    f.render_widget(pseudo_term, chunks[0]);
78    let explanation = "Press q to exit";
79    let explanation = Paragraph::new(explanation)
80        .style(Style::default().add_modifier(Modifier::BOLD | Modifier::REVERSED))
81        .alignment(Alignment::Center);
82    f.render_widget(explanation, chunks[1]);
83}
Source

pub fn show(&mut self)

Show the cursor (default)

Source

pub fn hide(&mut self)

Hide the cursor

Examples found in repository?
examples/smux.rs (line 79)
38async fn main() -> io::Result<()> {
39    init_panic_hook();
40    let (mut terminal, mut size) = setup_terminal().unwrap();
41
42    let cwd = std::env::current_dir().unwrap();
43    let mut cmd = CommandBuilder::new_default_prog();
44    cmd.cwd(cwd);
45
46    let mut panes: Vec<PtyPane> = Vec::new();
47    let mut active_pane: Option<usize> = None;
48
49    // Add a default pane
50    let pane_size = calc_pane_size(size, 1);
51    open_new_pane(&mut panes, &mut active_pane, &cmd, pane_size)?;
52
53    loop {
54        terminal.draw(|f| {
55            let chunks = Layout::default()
56                .direction(Direction::Vertical)
57                .margin(1)
58                .constraints([Constraint::Percentage(100), Constraint::Min(1)].as_ref())
59                .split(f.area());
60
61            let pane_height = if panes.is_empty() {
62                chunks[0].height
63            } else {
64                (chunks[0].height.saturating_sub(1)) / panes.len() as u16
65            };
66
67            for (index, pane) in panes.iter().enumerate() {
68                let block = Block::default()
69                    .borders(Borders::ALL)
70                    .style(Style::default().add_modifier(Modifier::BOLD));
71                let mut cursor = Cursor::default();
72                let block = if Some(index) == active_pane {
73                    block.style(
74                        Style::default()
75                            .add_modifier(Modifier::BOLD)
76                            .fg(Color::LightMagenta),
77                    )
78                } else {
79                    cursor.hide();
80                    block
81                };
82                let parser = pane.parser.read().unwrap();
83                let screen = parser.screen();
84                let pseudo_term = PseudoTerminal::new(screen).block(block).cursor(cursor);
85                let pane_chunk = Rect {
86                    x: chunks[0].x,
87                    y: chunks[0].y + (index as u16 * pane_height), /* Adjust the y coordinate for
88                                                                    * each pane */
89                    width: chunks[0].width,
90                    height: pane_height, // Use the calculated pane height directly
91                };
92                f.render_widget(pseudo_term, pane_chunk);
93            }
94
95            let explanation =
96                "Ctrl+n to open a new pane | Ctrl+x to close the active pane | Ctrl+q to quit";
97            let explanation = Paragraph::new(explanation)
98                .style(Style::default().add_modifier(Modifier::BOLD | Modifier::REVERSED))
99                .alignment(Alignment::Center);
100            f.render_widget(explanation, chunks[1]);
101        })?;
102
103        if event::poll(Duration::from_millis(10))? {
104            tracing::info!("Terminal Size: {:?}", terminal.size());
105            match event::read()? {
106                Event::Key(key) => match key.code {
107                    KeyCode::Char('q') if key.modifiers.contains(KeyModifiers::CONTROL) => {
108                        cleanup_terminal(&mut terminal).unwrap();
109                        return Ok(());
110                    }
111                    KeyCode::Char('n') if key.modifiers.contains(KeyModifiers::CONTROL) => {
112                        let pane_size = calc_pane_size(size, panes.len() + 1);
113                        tracing::info!("Opened new pane with size: {size:?}");
114                        resize_all_panes(&mut panes, pane_size);
115                        open_new_pane(&mut panes, &mut active_pane, &cmd, pane_size)?;
116                    }
117                    KeyCode::Char('x') if key.modifiers.contains(KeyModifiers::CONTROL) => {
118                        close_active_pane(&mut panes, &mut active_pane).await?;
119                        resize_all_panes(&mut panes, pane_size);
120                    }
121                    KeyCode::Char('k') if key.modifiers.contains(KeyModifiers::CONTROL) => {
122                        if let Some(pane) = active_pane {
123                            active_pane = Some(pane.saturating_sub(1));
124                        }
125                    }
126                    KeyCode::Char('j') if key.modifiers.contains(KeyModifiers::CONTROL) => {
127                        if let Some(pane) = active_pane {
128                            if pane < panes.len() - 1 {
129                                active_pane = Some(pane.saturating_add(1));
130                            }
131                        }
132                    }
133                    _ => {
134                        if let Some(index) = active_pane {
135                            if handle_pane_key_event(&mut panes[index], &key).await {
136                                continue;
137                            }
138                        }
139                    }
140                },
141                Event::Resize(cols, rows) => {
142                    tracing::info!("Resized to: rows: {} cols: {}", rows, cols);
143                    size.rows = rows;
144                    size.cols = cols;
145                    let pane_size = calc_pane_size(size, panes.len());
146                    resize_all_panes(&mut panes, pane_size);
147                }
148                _ => {}
149            }
150        }
151    }
152}

Trait Implementations§

Source§

impl Default for Cursor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

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>

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)

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)

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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.