Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assistance on transition to termwiz #1847

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ use crate::{

use log::{error, warn};
use std::{
io::{stdin, stdout, Write},
io::stdin,
sync::Arc,
time::{Duration, Instant},
};

use anyhow::Error;

use crossterm::{
event::{DisableMouseCapture, EnableMouseCapture, Event, EventStream},
event::{DisableMouseCapture, Event, EventStream},
execute, terminal,
tty::IsTty,
};
use termwiz::istty::IsTty;
#[cfg(not(windows))]
use {
signal_hook::{consts::signal, low_level},
Expand Down Expand Up @@ -805,26 +805,12 @@ impl Application {
}
}

async fn claim_term(&mut self) -> Result<(), Error> {
terminal::enable_raw_mode()?;
let mut stdout = stdout();
execute!(stdout, terminal::EnterAlternateScreen)?;
if self.config.editor.mouse {
execute!(stdout, EnableMouseCapture)?;
}
Ok(())
async fn claim_term(&mut self) -> Result<(), termwiz::Error> {
self.compositor.claim_term()
}

fn restore_term(&mut self) -> Result<(), Error> {
let mut stdout = stdout();
// reset cursor shape
write!(stdout, "\x1B[2 q")?;
// Ignore errors on disabling, this might trigger on windows if we call
// disable without calling enable previously
let _ = execute!(stdout, DisableMouseCapture);
execute!(stdout, terminal::LeaveAlternateScreen)?;
terminal::disable_raw_mode()?;
Ok(())
fn restore_term(&mut self) -> Result<(), termwiz::Error> {
self.compositor.clear()
}

pub async fn run(&mut self) -> Result<i32, Error> {
Expand Down
19 changes: 15 additions & 4 deletions helix-term/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ pub trait Component: Any + AnyComponent {
}

use termwiz::{
caps::Capabilities, surface::CursorVisibility, terminal::buffered::BufferedTerminal,
terminal::SystemTerminal,
caps::Capabilities,
surface::CursorVisibility,
terminal::{buffered::BufferedTerminal, SystemTerminal, Terminal},
};
type Terminal = BufferedTerminal<SystemTerminal>;

pub struct Compositor {
layers: Vec<Box<dyn Component>>,
terminal: Terminal,
terminal: BufferedTerminal<SystemTerminal>,
surface: Surface,

pub(crate) last_picker: Option<Box<dyn Component>>,
Expand Down Expand Up @@ -248,6 +248,17 @@ impl Compositor {
.find(|component| component.id() == Some(id))
.and_then(|component| component.as_any_mut().downcast_mut())
}

pub fn claim_term(&mut self) -> Result<(), termwiz::Error> {
self.terminal.terminal().enter_alternate_screen()?;
self.terminal.terminal().set_raw_mode()
}

pub(crate) fn clear(&mut self) -> Result<(), termwiz::Error> {
let inner_term = self.terminal.terminal();
inner_term.exit_alternate_screen()?;
inner_term.set_cooked_mode()
}
Comment on lines +252 to +261
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's kinda confusing that one is called claim_term and the other clear.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be claim_term and restore_term

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cursor methods should be similarly renamed from save_cursor/load_cursor

}

// View casting, taken straight from Cursive
Expand Down