This term specific behavior really doesn't belong to compositor

This commit is contained in:
Blaž Hrastnik 2022-03-29 10:01:02 +09:00
parent 14f987807d
commit 57d4a9ba21
No known key found for this signature in database
GPG Key ID: 1238B9C4AD889640
2 changed files with 18 additions and 19 deletions

View File

@ -343,7 +343,6 @@ pub async fn handle_signals(&mut self, signal: i32) {
use helix_view::graphics::Rect; use helix_view::graphics::Rect;
match signal { match signal {
signal::SIGTSTP => { signal::SIGTSTP => {
self.compositor.save_cursor();
self.restore_term().unwrap(); self.restore_term().unwrap();
low_level::emulate_default_handler(signal::SIGTSTP).unwrap(); low_level::emulate_default_handler(signal::SIGTSTP).unwrap();
} }
@ -352,7 +351,6 @@ pub async fn handle_signals(&mut self, signal: i32) {
// redraw the terminal // redraw the terminal
let Rect { width, height, .. } = self.compositor.size(); let Rect { width, height, .. } = self.compositor.size();
self.compositor.resize(width, height); self.compositor.resize(width, height);
self.compositor.load_cursor();
self.render(); self.render();
} }
_ => unreachable!(), _ => unreachable!(),
@ -712,7 +710,12 @@ pub async fn handle_language_server_message(
} }
async fn claim_term(&mut self) -> Result<(), Error> { async fn claim_term(&mut self) -> Result<(), Error> {
use helix_view::graphics::CursorKind;
use tui::backend::Backend;
terminal::enable_raw_mode()?; terminal::enable_raw_mode()?;
if self.compositor.terminal.cursor_kind() == CursorKind::Hidden {
self.compositor.terminal.backend_mut().hide_cursor().ok();
}
let mut stdout = stdout(); let mut stdout = stdout();
execute!(stdout, terminal::EnterAlternateScreen)?; execute!(stdout, terminal::EnterAlternateScreen)?;
execute!(stdout, terminal::Clear(terminal::ClearType::All))?; execute!(stdout, terminal::Clear(terminal::ClearType::All))?;
@ -723,7 +726,18 @@ async fn claim_term(&mut self) -> Result<(), Error> {
} }
fn restore_term(&mut self) -> Result<(), Error> { 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(); let mut stdout = stdout();
// reset cursor shape // reset cursor shape
write!(stdout, "\x1B[2 q")?; write!(stdout, "\x1B[2 q")?;
// Ignore errors on disabling, this might trigger on windows if we call // Ignore errors on disabling, this might trigger on windows if we call

View File

@ -69,12 +69,12 @@ fn id(&self) -> Option<&'static str> {
use anyhow::Error; use anyhow::Error;
use std::io::stdout; use std::io::stdout;
use tui::backend::{Backend, CrosstermBackend}; use tui::backend::CrosstermBackend;
type Terminal = tui::terminal::Terminal<CrosstermBackend<std::io::Stdout>>; type Terminal = tui::terminal::Terminal<CrosstermBackend<std::io::Stdout>>;
pub struct Compositor { pub struct Compositor {
layers: Vec<Box<dyn Component>>, layers: Vec<Box<dyn Component>>,
terminal: Terminal, pub terminal: Terminal,
area: Rect, area: Rect,
pub(crate) last_picker: Option<Box<dyn Component>>, pub(crate) last_picker: Option<Box<dyn Component>>,
@ -105,21 +105,6 @@ pub fn resize(&mut self, width: u16, height: u16) {
self.area = self.terminal.size().expect("couldn't get terminal size"); 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>) { pub fn push(&mut self, mut layer: Box<dyn Component>) {
let size = self.size(); let size = self.size();
// trigger required_size on init // trigger required_size on init