Skip to content

Commit

Permalink
add(overlay): add overlay
Browse files Browse the repository at this point in the history
* add overlay instructions to the `render` function

  this is a continuation of zellij-org#871
  • Loading branch information
a-kenji committed Nov 16, 2021
1 parent 4eee6ca commit 70a3f59
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 9 deletions.
59 changes: 51 additions & 8 deletions zellij-server/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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>>,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion zellij-server/src/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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!(
Expand Down

0 comments on commit 70a3f59

Please sign in to comment.