overlay: initial prep
An overlay is a little termwiz app that can be overlaid over the content of a gui tab. The intent is for these to provide the mechanism for meta operations; listing all tabs in a long-form list and switching between them, dropping into configuration or error log review and so on.
This commit is contained in:
1 parent
78ab99e0d0
commit
0822c67e32
4 files changed
+121
-19
No files matched your search
@@ -9,6 +9,7 @@ use std::rc::Rc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
mod glyphcache;
|
||||
mod overlay;
|
||||
mod quad;
|
||||
mod renderstate;
|
||||
mod scrollbar;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
use crate::frontend::gui::termwindow::TermWindow;
|
||||
use crate::mux::tab::{Tab, TabId};
|
||||
use crate::termwiztermtab::{allocate, TermWizTerminal, TermWizTerminalTab};
|
||||
use std::rc::Rc;
|
||||
use window::Window;
|
||||
|
||||
pub fn start<T, F>(
|
||||
term_window: &TermWindow,
|
||||
tab: &Rc<dyn Tab>,
|
||||
func: F,
|
||||
) -> (
|
||||
Rc<dyn Tab>,
|
||||
Box<dyn std::future::Future<Output = Option<anyhow::Result<T>>>>,
|
||||
)
|
||||
where
|
||||
T: Send + 'static,
|
||||
F: Send + 'static + FnOnce(TabId, TermWizTerminal) -> anyhow::Result<T>,
|
||||
{
|
||||
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::new(future))
|
||||
}
|
||||
@@ -6,6 +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::scrollbar::*;
|
||||
use crate::frontend::gui::selection::*;
|
||||
use crate::frontend::gui::tabbar::{TabBarItem, TabBarState};
|
||||
@@ -113,17 +114,21 @@ impl PrevCursorPos {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Default)]
|
||||
struct TabState {
|
||||
/// If is_some(), the top row of the visible screen.
|
||||
/// Otherwise, the viewport is at the bottom of the
|
||||
/// scrollback.
|
||||
viewport: Option<StableRowIndex>,
|
||||
selection: Selection,
|
||||
/// If is_some(), rather than display the actual tab
|
||||
/// contents, we're overlaying a little internal application
|
||||
/// tab. We'll also route input to it.
|
||||
overlay: Option<Rc<dyn Tab>>,
|
||||
}
|
||||
|
||||
pub struct TermWindow {
|
||||
window: Option<Window>,
|
||||
pub window: Option<Window>,
|
||||
/// When we most recently received keyboard focus
|
||||
focused: Option<Instant>,
|
||||
fonts: Rc<FontConfiguration>,
|
||||
@@ -234,7 +239,7 @@ impl WindowCallbacks for TermWindow {
|
||||
|
||||
fn mouse_event(&mut self, event: &MouseEvent, context: &dyn WindowOps) {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = match mux.get_active_tab_for_window(self.mux_window_id) {
|
||||
let tab = match self.get_active_tab_or_overlay() {
|
||||
Some(tab) => tab,
|
||||
None => return,
|
||||
};
|
||||
@@ -311,7 +316,7 @@ impl WindowCallbacks for TermWindow {
|
||||
if let Some(from_top) = self.scroll_drag_start.as_ref() {
|
||||
// Dragging the scroll bar
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = match mux.get_active_tab_for_window(self.mux_window_id) {
|
||||
let tab = match self.get_active_tab_or_overlay() {
|
||||
Some(tab) => tab,
|
||||
None => return,
|
||||
};
|
||||
@@ -370,7 +375,7 @@ impl WindowCallbacks for TermWindow {
|
||||
// log::error!("key_event {:?}", key);
|
||||
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = match mux.get_active_tab_for_window(self.mux_window_id) {
|
||||
let tab = match self.get_active_tab_or_overlay() {
|
||||
Some(tab) => tab,
|
||||
None => return false,
|
||||
};
|
||||
@@ -423,7 +428,7 @@ impl WindowCallbacks for TermWindow {
|
||||
|
||||
fn paint(&mut self, ctx: &mut dyn PaintContext) {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = match mux.get_active_tab_for_window(self.mux_window_id) {
|
||||
let tab = match self.get_active_tab_or_overlay() {
|
||||
Some(tab) => tab,
|
||||
None => {
|
||||
ctx.clear(Color::rgb(0, 0, 0));
|
||||
@@ -459,7 +464,7 @@ impl WindowCallbacks for TermWindow {
|
||||
|
||||
fn paint_opengl(&mut self, frame: &mut glium::Frame) {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = match mux.get_active_tab_for_window(self.mux_window_id) {
|
||||
let tab = match self.get_active_tab_or_overlay() {
|
||||
Some(tab) => tab,
|
||||
None => {
|
||||
frame.clear_color(0., 0., 0., 1.);
|
||||
@@ -595,7 +600,7 @@ impl TermWindow {
|
||||
if let Some(myself) = myself.downcast_mut::<Self>() {
|
||||
let mux = Mux::get().unwrap();
|
||||
|
||||
if let Some(tab) = mux.get_active_tab_for_window(mux_window_id) {
|
||||
if let Some(tab) = myself.get_active_tab_or_overlay() {
|
||||
// If the config was reloaded, ask the window to apply
|
||||
// and render any changes
|
||||
myself.check_for_config_reload();
|
||||
@@ -864,7 +869,7 @@ impl TermWindow {
|
||||
}
|
||||
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = match mux.get_active_tab_for_window(self.mux_window_id) {
|
||||
let tab = match self.get_active_tab_or_overlay() {
|
||||
Some(tab) => tab,
|
||||
None => return,
|
||||
};
|
||||
@@ -1009,7 +1014,7 @@ impl TermWindow {
|
||||
|
||||
fn scroll_by_page(&mut self, amount: isize) -> anyhow::Result<()> {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = match mux.get_active_tab_for_window(self.mux_window_id) {
|
||||
let tab = match self.get_active_tab_or_overlay() {
|
||||
Some(tab) => tab,
|
||||
None => return Ok(()),
|
||||
};
|
||||
@@ -2757,6 +2762,37 @@ impl TermWindow {
|
||||
fn scroll_to_bottom(&mut self, tab: &Rc<dyn Tab>) {
|
||||
self.tab_state(tab.tab_id()).viewport = None;
|
||||
}
|
||||
|
||||
/// Returns a Tab that we can interact with; this will typically be
|
||||
/// the active tab for the window, but if the window has an overlay,
|
||||
/// then that will be returned instead.
|
||||
fn get_active_tab_or_overlay(&self) -> Option<Rc<dyn Tab>> {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = match mux.get_active_tab_for_window(self.mux_window_id) {
|
||||
Some(tab) => tab,
|
||||
None => return None,
|
||||
};
|
||||
|
||||
let tab_id = tab.tab_id();
|
||||
self.tab_state(tab_id).overlay.clone().or_else(|| Some(tab))
|
||||
}
|
||||
|
||||
/// Removes any overlay for the specified tab
|
||||
fn cancel_overlay_for_tab(&self, tab_id: TabId) {
|
||||
self.tab_state(tab_id).overlay.take();
|
||||
if let Some(window) = self.window.as_ref() {
|
||||
window.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn schedule_cancel_overlay(window: Window, tab_id: TabId) {
|
||||
window.apply(move |myself, _| {
|
||||
if let Some(myself) = myself.downcast_mut::<Self>() {
|
||||
myself.cancel_overlay_for_tab(tab_id);
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn rgbcolor_to_window_color(color: RgbColor) -> Color {
|
||||
|
||||
+42
-9
@@ -193,8 +193,24 @@ impl Drop for TermWizTerminalTab {
|
||||
}
|
||||
|
||||
impl TermWizTerminalTab {
|
||||
fn new(domain_id: DomainId, inner: RenderableInner) -> Self {
|
||||
fn new(
|
||||
domain_id: DomainId,
|
||||
width: usize,
|
||||
height: usize,
|
||||
input_tx: Sender<InputEvent>,
|
||||
render_rx: Receiver<Vec<Change>>,
|
||||
) -> Self {
|
||||
let tab_id = alloc_tab_id();
|
||||
|
||||
let inner = RenderableInner {
|
||||
surface: Surface::new(width, height),
|
||||
local_sequence: 0,
|
||||
dead: false,
|
||||
something_changed: Arc::new(AtomicBool::new(false)),
|
||||
input_tx,
|
||||
render_rx,
|
||||
};
|
||||
|
||||
let renderable = RefCell::new(RenderableState {
|
||||
inner: RefCell::new(inner),
|
||||
});
|
||||
@@ -412,6 +428,26 @@ impl termwiz::terminal::Terminal for &mut TermWizTerminal {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn allocate(width: usize, height: usize) -> (TermWizTerminal, TermWizTerminalTab) {
|
||||
let (render_tx, render_rx) = channel();
|
||||
let (input_tx, input_rx) = channel();
|
||||
|
||||
let tw_term = TermWizTerminal {
|
||||
render_tx,
|
||||
input_rx,
|
||||
screen_size: ScreenSize {
|
||||
cols: width,
|
||||
rows: height,
|
||||
xpixel: 0,
|
||||
ypixel: 0,
|
||||
},
|
||||
};
|
||||
|
||||
let domain_id = 0;
|
||||
let tab = TermWizTerminalTab::new(domain_id, width, height, input_tx, render_rx);
|
||||
(tw_term, tab)
|
||||
}
|
||||
|
||||
/// This function spawns a thread and constructs a GUI window with an
|
||||
/// associated termwiz Terminal object to execute the provided function.
|
||||
/// The function is expected to run in a loop to manage input and output
|
||||
@@ -454,16 +490,13 @@ pub async fn run<
|
||||
|
||||
let window_id = mux.new_empty_window();
|
||||
|
||||
let inner = RenderableInner {
|
||||
surface: Surface::new(width, height),
|
||||
local_sequence: 0,
|
||||
dead: false,
|
||||
something_changed: Arc::new(AtomicBool::new(false)),
|
||||
let tab: Rc<dyn Tab> = Rc::new(TermWizTerminalTab::new(
|
||||
domain.domain_id(),
|
||||
width,
|
||||
height,
|
||||
input_tx,
|
||||
render_rx,
|
||||
};
|
||||
|
||||
let tab: Rc<dyn Tab> = Rc::new(TermWizTerminalTab::new(domain.domain_id(), inner));
|
||||
));
|
||||
|
||||
mux.add_tab(&tab)?;
|
||||
mux.add_tab_to_window(&tab, window_id)?;
|
||||
|
||||
Reference in new issue
Block a user