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

Code before:
    invisible: bool,
    color: Option<PaletteColor>,
}

impl BoundarySymbol {
    pub fn new(boundary_type: BoundaryType) -> Self {
        BoundarySymbol {
            boundary_type,
            invisible: false,
            color: Some(PaletteColor::EightBit(colors::GRAY)),
        }
    }
    pub fn color(&mut self, color: Option<PaletteColor>) -> Self {
        self.color = color;
        *self
    }
    pub fn as_terminal_character(&self) -> Result<TerminalCharacter> {
        let tc = if self.invisible {
            EMPTY_TERMINAL_CHARACTER
        } else {
            let character = self.boundary_type.chars().next().with_context(|| {
                format!(
                    "failed to as terminal character for boundary type {}",
                    self.boundary_type
                )
            })?;
            TerminalCharacter {
                character,
                width: 1,
                styles: RESET_STYLES
                    .foreground(self.color.map(|palette_color| palette_color.into())),
            }
        };
        Ok(tc)
    }
}

impl Display for BoundarySymbol {
    fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
        match self.invisible {
            true => write!(f, " "),
            false => match self.color {
                Some(color) => match color {
                    PaletteColor::Rgb((r, g, b)) => {
                        write!(f, "{}", RGB(r, g, b).paint(self.boundary_type))
                    },
                    PaletteColor::EightBit(color) => {
                        write!(f, "{}", Fixed(color).paint(self.boundary_type))
                    },
                },
                None => write!(f, "{}", self.boundary_type),

Review comment (bug):
I think we should expand this a little. The `unwrap` here originally unwrapped on an `Option`. A `None`, however, doesn't tell us what "Error" occured here, because that is context specific. I would suggest something like this:

```rust
                .context("no boundary symbols defined")  // <-- Tells us why "None" here is actually an error for us
                .with_context(|| format!("failed to convert boundary symbol {} into terminal character", ...))?;  // <-- Gives us the usual error context
```

Code after:
    invisible: bool,
    color: Option<PaletteColor>,
}

impl BoundarySymbol {
    pub fn new(boundary_type: BoundaryType) -> Self {
        BoundarySymbol {
            boundary_type,
            invisible: false,
            color: Some(PaletteColor::EightBit(colors::GRAY)),
        }
    }
    pub fn color(&mut self, color: Option<PaletteColor>) -> Self {
        self.color = color;
        *self
    }
    pub fn as_terminal_character(&self) -> Result<TerminalCharacter> {
        let tc = if self.invisible {
            EMPTY_TERMINAL_CHARACTER
        } else {
            let character = self
                .boundary_type
                .chars()
                .next()
                .context("no boundary symbols defined")
                .with_context(|| {
                    format!(
                        "failed to convert boundary symbol {} into terminal character",
                        self.boundary_type
                    )
                })?;
            TerminalCharacter {
                character,
                width: 1,
                styles: RESET_STYLES
                    .foreground(self.color.map(|palette_color| palette_color.into())),
            }
        };
        Ok(tc)
    }
}

impl Display for BoundarySymbol {
    fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
        match self.invisible {
            true => write!(f, " "),
            false => match self.color {
                Some(color) => match color {
                    PaletteColor::Rgb((r, g, b)) => {
                        write!(f, "{}", RGB(r, g, b).paint(self.boundary_type))
                    },