Lines
100 %
Functions
Branches
//! TurboVision frames: double-line active windows, single-line passive ones, dialogs, shadows.
use ratatui::buffer::Buffer;
use ratatui::layout::{Alignment, Rect};
use ratatui::style::Style;
use ratatui::widgets::{Block, BorderType, Borders};
use crate::{FrameMode, Role, Theme};
/// The first character of a kitty Unicode-placeholder cell, which carries an image.
const KITTY_PLACEHOLDER: char = '\u{10EEEE}';
fn framed(
title: &str,
border_type: BorderType,
[fill, border, title_style]: [Style; 3],
) -> Block<'static> {
let block = Block::new()
.borders(Borders::ALL)
.border_type(border_type)
.style(fill)
.border_style(border);
if title.is_empty() {
return block;
}
block
.title(format!(" {title} "))
.title_style(title_style)
.title_alignment(Alignment::Center)
/// A dialog frame: double-line, the title centred. A dialog being moved or sized has TV's
/// dragging frame: single-line, all in the icon colour; one that is not on top has TV's
/// passive frame: single-line in the frame colour.
#[must_use]
pub(crate) fn dialog(theme: &Theme, title: &str, mode: FrameMode) -> Block<'static> {
let fill = theme.style(Role::Dialog);
let frame = theme.style(Role::DialogFrame);
match mode {
FrameMode::Dragging => {
let icon = theme.style(Role::DialogIcon);
framed(title, BorderType::Plain, [fill, icon, icon])
FrameMode::Passive => framed(title, BorderType::Plain, [fill; 3]),
FrameMode::Active => {
let styles = [fill, frame, theme.style(Role::DialogTitle)];
framed(title, BorderType::Double, styles)
/// A menu drop-down frame: single-line, no title, in the menu colours.
pub fn menu_box(theme: &Theme) -> Block<'static> {
let menu = theme.style(Role::Menu);
framed("", BorderType::Plain, [menu; 3])
/// A list box frame: single-line, no title, in the list colours.
pub(crate) fn list_box(theme: &Theme) -> Block<'static> {
let list = theme.style(Role::List);
framed("", BorderType::Plain, [list; 3])
/// Darkens the two columns right of `area` and the row below it, as under a TurboVision dialog.
/// Cells keep their symbols; kitty placeholder cells and cells off the buffer are left alone.
pub(crate) fn shadow(buf: &mut Buffer, area: Rect, theme: &Theme) {
let style = Style::reset().patch(theme.style(Role::Shadow));
let right = Rect::new(area.right(), area.y.saturating_add(1), 2, area.height);
let below = Rect::new(area.x.saturating_add(2), area.bottom(), area.width, 1);
for strip in [right, below] {
for position in strip.intersection(buf.area).positions() {
if let Some(cell) = buf.cell_mut(position)
&& !cell.symbol().starts_with(KITTY_PLACEHOLDER)
{
cell.set_style(style);
#[cfg(test)]
mod tests;