alt-9 pops up an overlay on the current tab
This is placeholder for the moment, but proves the concept
This commit is contained in:
1 parent
3940684b4e
commit
ff82b63fb8
4 files changed
+47
-4
No files matched your search
@@ -81,6 +81,7 @@ impl std::convert::TryInto<KeyAssignment> for &Key {
|
||||
.ok_or_else(|| anyhow!("missing arg for {:?}", self))?
|
||||
.parse()?,
|
||||
),
|
||||
KeyAction::ShowTabNavigator => KeyAssignment::ShowTabNavigator,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -108,6 +109,7 @@ pub enum KeyAction {
|
||||
MoveTab,
|
||||
MoveTabRelative,
|
||||
ScrollByPage,
|
||||
ShowTabNavigator,
|
||||
}
|
||||
|
||||
fn de_keycode<'de, D>(deserializer: D) -> Result<KeyCode, D::Error>
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
use crate::frontend::gui::termwindow::TermWindow;
|
||||
use crate::mux::tab::{Tab, TabId};
|
||||
use crate::termwiztermtab::{allocate, TermWizTerminal, TermWizTerminalTab};
|
||||
use std::pin::Pin;
|
||||
use std::rc::Rc;
|
||||
use termwiz::lineedit::*;
|
||||
use termwiz::surface::{Change, SequenceNo, Surface};
|
||||
use termwiz::terminal::{ScreenSize, Terminal, TerminalWaker};
|
||||
use window::Window;
|
||||
|
||||
pub fn start<T, F>(
|
||||
pub fn start_overlay<T, F>(
|
||||
term_window: &TermWindow,
|
||||
tab: &Rc<dyn Tab>,
|
||||
func: F,
|
||||
) -> (
|
||||
Rc<dyn Tab>,
|
||||
Box<dyn std::future::Future<Output = Option<anyhow::Result<T>>>>,
|
||||
Pin<Box<dyn std::future::Future<Output = Option<anyhow::Result<T>>>>>,
|
||||
)
|
||||
where
|
||||
T: Send + 'static,
|
||||
@@ -28,5 +32,20 @@ where
|
||||
res
|
||||
});
|
||||
|
||||
(Rc::new(tw_tab), Box::new(future))
|
||||
(Rc::new(tw_tab), Box::pin(future))
|
||||
}
|
||||
|
||||
pub fn tab_navigator(tab_id: TabId, mut term: TermWizTerminal) -> anyhow::Result<()> {
|
||||
term.render(&[
|
||||
Change::Title("Tab Navigator".to_string()),
|
||||
Change::Text("Navigate!\r\n".to_string()),
|
||||
])?;
|
||||
|
||||
let mut editor = LineEditor::new(term);
|
||||
editor.set_prompt("(press enter to return to your tab)");
|
||||
|
||||
let mut host = NopLineEditorHost::default();
|
||||
editor.read_line(&mut host).ok();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -6,7 +6,7 @@ use crate::config::{configuration, ConfigHandle};
|
||||
use crate::font::units::*;
|
||||
use crate::font::FontConfiguration;
|
||||
use crate::frontend::front_end;
|
||||
use crate::frontend::gui::overlay::*;
|
||||
use crate::frontend::gui::overlay::{start_overlay, tab_navigator};
|
||||
use crate::frontend::gui::scrollbar::*;
|
||||
use crate::frontend::gui::selection::*;
|
||||
use crate::frontend::gui::tabbar::{TabBarItem, TabBarState};
|
||||
@@ -1012,6 +1012,18 @@ impl TermWindow {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn show_tab_navigator(&mut self) {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = match mux.get_active_tab_for_window(self.mux_window_id) {
|
||||
Some(tab) => tab,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let (overlay, future) = start_overlay(self, &tab, tab_navigator);
|
||||
self.assign_overlay(tab.tab_id(), overlay);
|
||||
promise::spawn::spawn(future);
|
||||
}
|
||||
|
||||
fn scroll_by_page(&mut self, amount: isize) -> anyhow::Result<()> {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = match self.get_active_tab_or_overlay() {
|
||||
@@ -1204,6 +1216,7 @@ impl TermWindow {
|
||||
MoveTab(n) => self.move_tab(*n)?,
|
||||
MoveTabRelative(n) => self.move_tab_relative(*n)?,
|
||||
ScrollByPage(n) => self.scroll_by_page(*n)?,
|
||||
ShowTabNavigator => self.show_tab_navigator(),
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
@@ -2779,6 +2792,7 @@ impl TermWindow {
|
||||
|
||||
/// Removes any overlay for the specified tab
|
||||
fn cancel_overlay_for_tab(&self, tab_id: TabId) {
|
||||
eprintln!("cancel_overlay_for_tab {}", tab_id);
|
||||
self.tab_state(tab_id).overlay.take();
|
||||
if let Some(window) = self.window.as_ref() {
|
||||
window.invalidate();
|
||||
@@ -2786,6 +2800,7 @@ impl TermWindow {
|
||||
}
|
||||
|
||||
pub fn schedule_cancel_overlay(window: Window, tab_id: TabId) {
|
||||
eprintln!("schedule_cancel_overlay {}", tab_id);
|
||||
window.apply(move |myself, _| {
|
||||
if let Some(myself) = myself.downcast_mut::<Self>() {
|
||||
myself.cancel_overlay_for_tab(tab_id);
|
||||
@@ -2793,6 +2808,11 @@ impl TermWindow {
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
|
||||
pub fn assign_overlay(&self, tab_id: TabId, overlay: Rc<dyn Tab>) {
|
||||
eprintln!("assign_overlay {}", tab_id);
|
||||
self.tab_state(tab_id).overlay.replace(overlay);
|
||||
}
|
||||
}
|
||||
|
||||
fn rgbcolor_to_window_color(color: RgbColor) -> Color {
|
||||
|
||||
@@ -38,6 +38,7 @@ pub enum KeyAssignment {
|
||||
MoveTabRelative(isize),
|
||||
MoveTab(usize),
|
||||
ScrollByPage(isize),
|
||||
ShowTabNavigator,
|
||||
}
|
||||
|
||||
pub struct KeyMap(HashMap<(KeyCode, KeyModifiers), KeyAssignment>);
|
||||
@@ -146,6 +147,7 @@ impl KeyMap {
|
||||
[ctrl_shift, KeyCode::PageDown, MoveTabRelative(1)],
|
||||
[KeyModifiers::SHIFT, KeyCode::PageUp, ScrollByPage(-1)],
|
||||
[KeyModifiers::SHIFT, KeyCode::PageDown, ScrollByPage(1)],
|
||||
[KeyModifiers::ALT, KeyCode::Char('9'), ShowTabNavigator],
|
||||
);
|
||||
|
||||
Self(map)
|
||||
|
||||
Reference in new issue
Block a user