Skip to content

Commit

Permalink
This term specific behavior really doesn't belong to compositor
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed May 1, 2022
1 parent 14f9878 commit 57d4a9b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
18 changes: 16 additions & 2 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ impl Application {
use helix_view::graphics::Rect;
match signal {
signal::SIGTSTP => {
self.compositor.save_cursor();
self.restore_term().unwrap();
low_level::emulate_default_handler(signal::SIGTSTP).unwrap();
}
Expand All @@ -352,7 +351,6 @@ impl Application {
// redraw the terminal
let Rect { width, height, .. } = self.compositor.size();
self.compositor.resize(width, height);
self.compositor.load_cursor();
self.render();
}
_ => unreachable!(),
Expand Down Expand Up @@ -712,7 +710,12 @@ impl Application {
}

async fn claim_term(&mut self) -> Result<(), Error> {
use helix_view::graphics::CursorKind;
use tui::backend::Backend;
terminal::enable_raw_mode()?;
if self.compositor.terminal.cursor_kind() == CursorKind::Hidden {
self.compositor.terminal.backend_mut().hide_cursor().ok();
}
let mut stdout = stdout();
execute!(stdout, terminal::EnterAlternateScreen)?;
execute!(stdout, terminal::Clear(terminal::ClearType::All))?;
Expand All @@ -723,7 +726,18 @@ impl Application {
}

fn restore_term(&mut self) -> Result<(), Error> {
use helix_view::graphics::CursorKind;
use tui::backend::Backend;
if self.compositor.terminal.cursor_kind() == CursorKind::Hidden {
self.compositor
.terminal
.backend_mut()
.show_cursor(CursorKind::Block)
.ok();
}

let mut stdout = stdout();

// reset cursor shape
write!(stdout, "\x1B[2 q")?;
// Ignore errors on disabling, this might trigger on windows if we call
Expand Down
19 changes: 2 additions & 17 deletions helix-term/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ pub trait Component: Any + AnyComponent {

use anyhow::Error;
use std::io::stdout;
use tui::backend::{Backend, CrosstermBackend};
use tui::backend::CrosstermBackend;
type Terminal = tui::terminal::Terminal<CrosstermBackend<std::io::Stdout>>;

pub struct Compositor {
layers: Vec<Box<dyn Component>>,
terminal: Terminal,
pub terminal: Terminal,
area: Rect,

pub(crate) last_picker: Option<Box<dyn Component>>,
Expand Down Expand Up @@ -105,21 +105,6 @@ impl Compositor {
self.area = self.terminal.size().expect("couldn't get terminal size");
}

pub fn save_cursor(&mut self) {
if self.terminal.cursor_kind() == CursorKind::Hidden {
self.terminal
.backend_mut()
.show_cursor(CursorKind::Block)
.ok();
}
}

pub fn load_cursor(&mut self) {
if self.terminal.cursor_kind() == CursorKind::Hidden {
self.terminal.backend_mut().hide_cursor().ok();
}
}

pub fn push(&mut self, mut layer: Box<dyn Component>) {
let size = self.size();
// trigger required_size on init
Expand Down

0 comments on commit 57d4a9b

Please sign in to comment.