From c5e172534f07828082f4c136dd676061645532a6 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 1 Mar 2020 17:00:14 -0800 Subject: [PATCH] split tab navigator into separate module --- src/frontend/gui/overlay/mod.rs | 35 ++++++++++++++++ .../{overlay.rs => overlay/tabnavigator.rs} | 42 +++---------------- 2 files changed, 40 insertions(+), 37 deletions(-) create mode 100644 src/frontend/gui/overlay/mod.rs rename src/frontend/gui/{overlay.rs => overlay/tabnavigator.rs} (78%) diff --git a/src/frontend/gui/overlay/mod.rs b/src/frontend/gui/overlay/mod.rs new file mode 100644 index 000000000..502aba7f5 --- /dev/null +++ b/src/frontend/gui/overlay/mod.rs @@ -0,0 +1,35 @@ +use crate::frontend::gui::termwindow::TermWindow; +use crate::mux::tab::{Tab, TabId}; +use crate::termwiztermtab::{allocate, TermWizTerminal}; +use std::pin::Pin; +use std::rc::Rc; + +mod tabnavigator; +pub use tabnavigator::tab_navigator; + +pub fn start_overlay( + term_window: &TermWindow, + tab: &Rc, + func: F, +) -> ( + Rc, + Pin>>>>, +) +where + T: Send + 'static, + F: Send + 'static + FnOnce(TabId, TermWizTerminal) -> anyhow::Result, +{ + let tab_id = tab.tab_id(); + let dims = tab.renderer().get_dimensions(); + let (tw_term, tw_tab) = allocate(dims.cols, dims.viewport_rows); + + let window = term_window.window.clone().unwrap(); + + let future = promise::spawn::spawn_into_new_thread(move || { + let res = func(tab_id, tw_term); + TermWindow::schedule_cancel_overlay(window, tab_id); + res + }); + + (Rc::new(tw_tab), Box::pin(future)) +} diff --git a/src/frontend/gui/overlay.rs b/src/frontend/gui/overlay/tabnavigator.rs similarity index 78% rename from src/frontend/gui/overlay.rs rename to src/frontend/gui/overlay/tabnavigator.rs index 8af3e024d..cdc9fcfe6 100644 --- a/src/frontend/gui/overlay.rs +++ b/src/frontend/gui/overlay/tabnavigator.rs @@ -1,52 +1,20 @@ -use crate::frontend::gui::termwindow::TermWindow; -use crate::mux::tab::{Tab, TabId}; +use crate::mux::tab::TabId; use crate::mux::window::WindowId; use crate::mux::Mux; -use crate::termwiztermtab::{allocate, TermWizTerminal}; +use crate::termwiztermtab::TermWizTerminal; use anyhow::anyhow; -use std::pin::Pin; -use std::rc::Rc; +use termwiz::cell::{AttributeChange, CellAttributes}; use termwiz::color::ColorAttribute; -use termwiz::surface::Change; +use termwiz::input::{InputEvent, KeyCode, KeyEvent}; +use termwiz::surface::{Change, Position}; use termwiz::terminal::Terminal; -pub fn start_overlay( - term_window: &TermWindow, - tab: &Rc, - func: F, -) -> ( - Rc, - Pin>>>>, -) -where - T: Send + 'static, - F: Send + 'static + FnOnce(TabId, TermWizTerminal) -> anyhow::Result, -{ - let tab_id = tab.tab_id(); - let dims = tab.renderer().get_dimensions(); - let (tw_term, tw_tab) = allocate(dims.cols, dims.viewport_rows); - - let window = term_window.window.clone().unwrap(); - - let future = promise::spawn::spawn_into_new_thread(move || { - let res = func(tab_id, tw_term); - TermWindow::schedule_cancel_overlay(window, tab_id); - res - }); - - (Rc::new(tw_tab), Box::pin(future)) -} - pub fn tab_navigator( tab_id: TabId, mut term: TermWizTerminal, tab_list: Vec<(String, TabId)>, mux_window_id: WindowId, ) -> anyhow::Result<()> { - use termwiz::cell::{AttributeChange, CellAttributes}; - use termwiz::input::{InputEvent, KeyCode, KeyEvent}; - use termwiz::surface::Position; - let mut active_tab_idx = tab_list .iter() .position(|(_title, id)| *id == tab_id)