-
-
Notifications
You must be signed in to change notification settings - Fork 639
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First attempt to provide an overlay prompt (#871)
- Loading branch information
Showing
11 changed files
with
217 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod boundaries; | ||
pub mod overlay; | ||
pub mod pane_boundaries_frame; | ||
pub mod pane_resizer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
//! This module handles the overlay's over the [`Screen`] | ||
//! | ||
//! They consist of: | ||
//! | ||
//! prompt's: | ||
//! | ||
//! notification's: | ||
|
||
pub mod prompt; | ||
|
||
use crate::ServerInstruction; | ||
use zellij_utils::pane_size::Size; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Overlay { | ||
pub overlay_type: OverlayType, | ||
} | ||
|
||
pub trait Overlayable { | ||
/// Generates vte_output that can be passed into | ||
/// the `render()` function | ||
fn generate_overlay(&self, size: Size) -> String; | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
struct Padding { | ||
rows: usize, | ||
cols: usize, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum OverlayType { | ||
Prompt(prompt::Prompt), | ||
} | ||
|
||
impl Overlayable for OverlayType { | ||
fn generate_overlay(&self, size: Size) -> String { | ||
match &self { | ||
OverlayType::Prompt(prompt) => prompt.generate_overlay(size), | ||
} | ||
} | ||
} | ||
|
||
/// Entrypoint from [`Screen`], which holds the context in which | ||
/// the overlays are being rendered. | ||
/// The most recent overlays draw over the previous overlays. | ||
#[derive(Clone, Debug)] | ||
pub struct OverlayWindow { | ||
pub overlay_stack: Vec<Overlay>, | ||
} | ||
|
||
impl Default for OverlayWindow { | ||
fn default() -> Self { | ||
Self { | ||
overlay_stack: vec![], | ||
} | ||
} | ||
} | ||
|
||
impl Overlayable for OverlayWindow { | ||
fn generate_overlay(&self, size: Size) -> String { | ||
let mut output = String::new(); | ||
//let clear_display = "\u{1b}[2J"; | ||
//output.push_str(&clear_display); | ||
for overlay in &self.overlay_stack { | ||
let vte_output = overlay.generate_overlay(size); | ||
output.push_str(&vte_output); | ||
} | ||
output | ||
} | ||
} | ||
|
||
impl Overlay { | ||
pub fn prompt_confirm(self) -> Option<Box<ServerInstruction>> { | ||
match self.overlay_type { | ||
OverlayType::Prompt(p) => p.confirm(), | ||
} | ||
} | ||
pub fn prompt_deny(self) -> Option<Box<ServerInstruction>> { | ||
match self.overlay_type { | ||
OverlayType::Prompt(p) => p.deny(), | ||
} | ||
} | ||
} | ||
|
||
impl Overlayable for Overlay { | ||
fn generate_overlay(&self, size: Size) -> String { | ||
self.overlay_type.generate_overlay(size) | ||
} | ||
} | ||
|
||
impl Overlay { | ||
pub fn new(overlay_type: OverlayType) -> Self { | ||
Self { overlay_type } | ||
} | ||
|
||
fn pad_cols(output: &mut String, cols: usize) { | ||
if let Some(padding) = cols.checked_sub(output.len()) { | ||
for _ in 0..padding { | ||
output.push(' '); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use zellij_utils::pane_size::Size; | ||
|
||
use super::{Overlay, OverlayType, Overlayable}; | ||
use crate::{ClientId, ServerInstruction}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Prompt { | ||
pub message: String, | ||
on_confirm: Option<Box<ServerInstruction>>, | ||
on_deny: Option<Box<ServerInstruction>>, | ||
} | ||
|
||
impl Prompt { | ||
pub fn new( | ||
message: String, | ||
on_confirm: Option<Box<ServerInstruction>>, | ||
on_deny: Option<Box<ServerInstruction>>, | ||
) -> Self { | ||
Self { | ||
message, | ||
on_confirm, | ||
on_deny, | ||
} | ||
} | ||
pub fn confirm(self) -> Option<Box<ServerInstruction>> { | ||
self.on_confirm | ||
} | ||
pub fn deny(self) -> Option<Box<ServerInstruction>> { | ||
self.on_deny | ||
} | ||
} | ||
|
||
impl Overlayable for Prompt { | ||
fn generate_overlay(&self, size: Size) -> String { | ||
let mut output = String::new(); | ||
let rows = size.rows; | ||
let mut vte_output = self.message.clone(); | ||
Overlay::pad_cols(&mut vte_output, size.cols); | ||
for (x, h) in vte_output.chars().enumerate() { | ||
output.push_str(&format!("\u{1b}[{};{}H\u{1b}[48;5;238m{}", rows, x + 1, h,)); | ||
} | ||
output | ||
} | ||
} | ||
|
||
pub fn _generate_quit_prompt(client_id: ClientId) -> Overlay { | ||
let prompt = Prompt::new( | ||
(" Do you want to quit zellij? [Y]es / [N]o").to_string(), | ||
Some(Box::new(ServerInstruction::ClientExit(client_id))), | ||
None, | ||
); | ||
Overlay { | ||
overlay_type: OverlayType::Prompt(prompt), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters