Repository: zellij-org/zellij
File: zellij-server/src/ui/overlay/mod.rs (Rust)

Code before:
use crate::ServerInstruction;
use zellij_utils::errors::prelude::*;
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) -> Result<String>;
}

#[derive(Clone, Debug)]
pub enum OverlayType {
    Prompt(prompt::Prompt),
}

impl Overlayable for OverlayType {
    fn generate_overlay(&self, size: Size) -> Result<String> {
        match &self {
            OverlayType::Prompt(prompt) => prompt
                .generate_overlay(size)
                .context("failed to generate overlay for overlay type"),
        }
    }
}

/// 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, Default)]
pub struct OverlayWindow {
    pub overlay_stack: Vec<Overlay>,
}

impl Overlayable for OverlayWindow {
    fn generate_overlay(&self, size: Size) -> Result<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)
                .context("failed to generate overlay for overlay window")?;
            output.push_str(&vte_output);
        }
        Ok(output)
    }

Review comment (bug):
Since we're implementing this trait below an a real type called `Overlay` we should word the context a little different here. Given the docstring for `Overlayable`, what do you think about the following?

```suggestion
                .context("failed to generate VTE output from overlay type"),
```

Code after:
use crate::ServerInstruction;
use zellij_utils::errors::prelude::*;
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) -> Result<String>;
}

#[derive(Clone, Debug)]
pub enum OverlayType {
    Prompt(prompt::Prompt),
}

impl Overlayable for OverlayType {
    fn generate_overlay(&self, size: Size) -> Result<String> {
        match &self {
            OverlayType::Prompt(prompt) => prompt
                .generate_overlay(size)
                .context("failed to generate VTE output from overlay type"),
        }
    }
}

/// 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, Default)]
pub struct OverlayWindow {
    pub overlay_stack: Vec<Overlay>,
}

impl Overlayable for OverlayWindow {
    fn generate_overlay(&self, size: Size) -> Result<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)
                .context("failed to generate VTE output from overlay window")?;
            output.push_str(&vte_output);
        }
        Ok(output)
    }