diff options
author | Michael Davis | 2023-03-05 18:06:12 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2023-03-08 01:49:32 +0000 |
commit | 3d850247177f61601296fe5b1cdada8819137783 (patch) | |
tree | 6c9639cea8fba74e0d8a61d34a49e5ee19d24cbe /helix-tui/src/terminal.rs | |
parent | 48b6aa9a699df0680a6d31e9611ebd1ca9909de4 (diff) |
Move terminal claim/restore code to helix-tui
This moves the `Application::claim_term` and
`helix-term::application::restore_term` functions into the helix-tui
crate. How the terminal should be claimed and restored is a TUI concern
and is implemented differently through different TUI backends.
This cleans out a lot of crossterm and TUI code in Application and
makes it easier to modify claim/restore based on information we query
from the terminal host. The child commit will take advantage of this
to cache the check for whether the host terminal supports the keyboard
enhancement protocol. Without this change, caching that information
takes much more code which is not easily reusable for anything else.
The code to restore the terminal is somewhat duplicated by this patch:
we want to restore the terminal in cases of panics. Panic handler hooks
must live for `'static` and the Application's terminal does not.
Diffstat (limited to 'helix-tui/src/terminal.rs')
-rw-r--r-- | helix-tui/src/terminal.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/helix-tui/src/terminal.rs b/helix-tui/src/terminal.rs index 22e9232f..802a8c1d 100644 --- a/helix-tui/src/terminal.rs +++ b/helix-tui/src/terminal.rs @@ -1,4 +1,5 @@ use crate::{backend::Backend, buffer::Buffer}; +use helix_view::editor::Config as EditorConfig; use helix_view::graphics::{CursorKind, Rect}; use std::io; @@ -16,6 +17,19 @@ pub struct Viewport { resize_behavior: ResizeBehavior, } +#[derive(Debug)] +pub struct Config { + pub enable_mouse_capture: bool, +} + +impl From<EditorConfig> for Config { + fn from(config: EditorConfig) -> Self { + Self { + enable_mouse_capture: config.mouse, + } + } +} + impl Viewport { /// UNSTABLE pub fn fixed(area: Rect) -> Viewport { @@ -98,6 +112,14 @@ where }) } + pub fn claim(&mut self, config: Config) -> io::Result<()> { + self.backend.claim(config) + } + + pub fn restore(&mut self, config: Config) -> io::Result<()> { + self.backend.restore(config) + } + // /// Get a Frame object which provides a consistent view into the terminal state for rendering. // pub fn get_frame(&mut self) -> Frame<B> { // Frame { |