mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 09:26:19 +04:00
This term specific behavior really doesn't belong to compositor
This commit is contained in:
parent
14f987807d
commit
57d4a9ba21
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user