add(overlay): add overlay (#875)
* add overlay instructions to the `render` function this is a continuation of #871
This commit is contained in:
parent
4eee6cae00
commit
198950e0b9
2 changed files with 58 additions and 9 deletions
|
|
@ -12,7 +12,7 @@ use crate::{
|
|||
pty::{ClientOrTabIndex, PtyInstruction, VteBytes},
|
||||
tab::{Output, Tab},
|
||||
thread_bus::Bus,
|
||||
ui::overlay::{Overlay, OverlayWindow},
|
||||
ui::overlay::{Overlay, OverlayWindow, Overlayable},
|
||||
wasm_vm::PluginInstruction,
|
||||
ClientId, ServerInstruction,
|
||||
};
|
||||
|
|
@ -179,7 +179,7 @@ pub(crate) struct Screen {
|
|||
/// The full size of this [`Screen`].
|
||||
size: Size,
|
||||
/// The overlay that is drawn on top of [`Pane`]'s', [`Tab`]'s and the [`Screen`]
|
||||
_overlay: OverlayWindow,
|
||||
overlay: OverlayWindow,
|
||||
/// The indices of this [`Screen`]'s active [`Tab`]s.
|
||||
active_tab_indices: BTreeMap<ClientId, usize>,
|
||||
tab_history: BTreeMap<ClientId, Vec<usize>>,
|
||||
|
|
@ -204,7 +204,7 @@ impl Screen {
|
|||
colors: client_attributes.palette,
|
||||
active_tab_indices: BTreeMap::new(),
|
||||
tabs: BTreeMap::new(),
|
||||
_overlay: OverlayWindow::default(),
|
||||
overlay: OverlayWindow::default(),
|
||||
tab_history: BTreeMap::new(),
|
||||
mode_info,
|
||||
draw_pane_frames,
|
||||
|
|
@ -359,9 +359,12 @@ impl Screen {
|
|||
pub fn render(&mut self) {
|
||||
let mut output = Output::default();
|
||||
let mut tabs_to_close = vec![];
|
||||
let size = self.size;
|
||||
let overlay = self.overlay.clone();
|
||||
for (tab_index, tab) in self.tabs.iter_mut() {
|
||||
if tab.has_active_panes() {
|
||||
tab.render(&mut output);
|
||||
let vte_overlay = overlay.generate_overlay(size);
|
||||
tab.render(&mut output, Some(vte_overlay));
|
||||
} else {
|
||||
tabs_to_close.push(*tab_index);
|
||||
}
|
||||
|
|
@ -405,6 +408,11 @@ impl Screen {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to this [`Screen`]'s active [`Overlays`].
|
||||
pub fn get_active_overlays_mut(&mut self) -> &mut Vec<Overlay> {
|
||||
&mut self.overlay.overlay_stack
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to this [`Screen`]'s indexed [`Tab`].
|
||||
pub fn get_indexed_tab_mut(&mut self, tab_index: usize) -> Option<&mut Tab> {
|
||||
self.get_tabs_mut().get_mut(&tab_index)
|
||||
|
|
@ -1100,10 +1108,45 @@ pub(crate) fn screen_thread_main(
|
|||
|
||||
screen.render();
|
||||
}
|
||||
ScreenInstruction::AddOverlay(_, _) => {}
|
||||
ScreenInstruction::RemoveOverlay(_) => {}
|
||||
ScreenInstruction::ConfirmPrompt(_) => {}
|
||||
ScreenInstruction::DenyPrompt(_) => {}
|
||||
ScreenInstruction::AddOverlay(overlay, _client_id) => {
|
||||
screen.get_active_overlays_mut().pop();
|
||||
screen.get_active_overlays_mut().push(overlay);
|
||||
screen
|
||||
.bus
|
||||
.senders
|
||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
||||
.unwrap();
|
||||
}
|
||||
ScreenInstruction::RemoveOverlay(_client_id) => {
|
||||
screen.get_active_overlays_mut().pop();
|
||||
screen.render();
|
||||
screen
|
||||
.bus
|
||||
.senders
|
||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
||||
.unwrap();
|
||||
}
|
||||
ScreenInstruction::ConfirmPrompt(_client_id) => {
|
||||
let overlay = screen.get_active_overlays_mut().pop();
|
||||
let instruction = overlay.map(|o| o.prompt_confirm()).flatten();
|
||||
if let Some(instruction) = instruction {
|
||||
screen.bus.senders.send_to_server(*instruction).unwrap();
|
||||
}
|
||||
screen
|
||||
.bus
|
||||
.senders
|
||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
||||
.unwrap();
|
||||
}
|
||||
ScreenInstruction::DenyPrompt(_client_id) => {
|
||||
screen.get_active_overlays_mut().pop();
|
||||
screen.render();
|
||||
screen
|
||||
.bus
|
||||
.senders
|
||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -872,7 +872,7 @@ impl Tab {
|
|||
resize_pty!(pane, self.os_api);
|
||||
}
|
||||
}
|
||||
pub fn render(&mut self, output: &mut Output) {
|
||||
pub fn render(&mut self, output: &mut Output, overlay: Option<String>) {
|
||||
if self.connected_clients.is_empty() || self.active_panes.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
|
@ -923,6 +923,12 @@ impl Tab {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Once clients can be distinguished
|
||||
if let Some(overlay_vte) = &overlay {
|
||||
output.push_str_to_all_clients(overlay_vte);
|
||||
}
|
||||
|
||||
if let Some(vte_output) = pane.render() {
|
||||
// FIXME: Use Termion for cursor and style clearing?
|
||||
output.push_str_to_all_clients(&format!(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue