Skip to content

Commit

Permalink
tui: don't show cursor when term is not active
Browse files Browse the repository at this point in the history
  • Loading branch information
kxxt committed May 11, 2024
1 parent 48df4e1 commit 7c4c7f3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
23 changes: 19 additions & 4 deletions src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,19 @@ impl App {
printer_args: PrinterArgs::from_cli(tracing_args, modifier_args),
split_percentage: if pty_master.is_some() { 50 } else { 100 },
term: if let Some(pty_master) = pty_master {
Some(PseudoTerminalPane::new(
let mut term = PseudoTerminalPane::new(
PtySize {
rows: 24,
cols: 80,
pixel_width: 0,
pixel_height: 0,
},
pty_master,
)?)
)?;
if active_pane == ActivePane::Terminal {
term.focus(true);
}
Some(term)
} else {
None
},
Expand Down Expand Up @@ -427,8 +431,19 @@ impl App {
}
Action::SwitchActivePane => {
self.active_pane = match self.active_pane {
ActivePane::Events => ActivePane::Terminal,
ActivePane::Terminal => ActivePane::Events,
ActivePane::Events => {
if let Some(term) = self.term.as_mut() {
term.focus(true);
ActivePane::Terminal
} else {
self.term.as_mut().map(|t| t.focus(false));
ActivePane::Events
}
}
ActivePane::Terminal => {
self.term.as_mut().map(|t| t.focus(false));
ActivePane::Events
}
}
}
Action::ShowCopyDialog(e) => {
Expand Down
14 changes: 12 additions & 2 deletions src/tui/pseudo_term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::io::{BufWriter, Write};
use std::sync::Arc;
use tokio::sync::mpsc::channel;
use tracing::{trace, warn};
use tui_term::widget::PseudoTerminal;
use tui_term::widget::{Cursor, PseudoTerminal};

use tokio_util::sync::CancellationToken;

Expand All @@ -50,6 +50,7 @@ pub struct PseudoTerminalPane {
master_tx: tokio::sync::mpsc::Sender<Bytes>,
master_cancellation_token: CancellationToken,
size: PtySize,
focus: bool,
}

const ESCAPE: u8 = 27;
Expand Down Expand Up @@ -117,6 +118,7 @@ impl PseudoTerminalPane {
writer_task,
master_tx: tx,
master_cancellation_token,
focus: false,
})
}

Expand Down Expand Up @@ -187,6 +189,10 @@ impl PseudoTerminalPane {
Ok(())
}

pub fn focus(&mut self, focus: bool) {
self.focus = focus;
}

/// Closes pty master
pub fn exit(&self) {
self.master_cancellation_token.cancel()
Expand All @@ -199,7 +205,11 @@ impl Widget for &PseudoTerminalPane {
Self: Sized,
{
let parser = self.parser.read().unwrap();
let pseudo_term = PseudoTerminal::new(parser.screen());
let mut cursor = Cursor::default();
if !self.focus {
cursor.hide();
}
let pseudo_term = PseudoTerminal::new(parser.screen()).cursor(cursor);
pseudo_term.render(area, buf);
}
}

0 comments on commit 7c4c7f3

Please sign in to comment.