Lines
93.75 %
Functions
100 %
Branches
//! The history mark Turbo Vision draws after an input line with a drop-down: `▐↓▌`.
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::widgets::Widget;
use crate::{Role, Theme};
/// The cells the `▐↓▌` history mark of a form select field takes after its input line.
pub const HISTORY_CELLS: u16 = 3;
const MARK: [(char, Role); HISTORY_CELLS as usize] = [
('\u{2590}', Role::History),
('\u{2193}', Role::HistoryArrow),
('\u{258c}', Role::History),
];
/// The mark in the last [`HISTORY_CELLS`] cells of `area`; an area narrower than that gets none.
pub struct History<'a> {
theme: &'a Theme,
}
impl<'a> History<'a> {
#[must_use]
pub fn new(theme: &'a Theme) -> Self {
History { theme }
/// The cells of the mark at the end of a field in `area`.
pub fn area(area: Rect) -> Rect {
if area.width < HISTORY_CELLS || area.is_empty() {
return Rect::default();
Rect::new(area.right() - HISTORY_CELLS, area.y, HISTORY_CELLS, 1)
impl Widget for History<'_> {
fn render(self, area: Rect, buf: &mut Buffer) {
let mark = Self::area(area);
for (x, (glyph, role)) in (mark.x..mark.right()).zip(&MARK) {
if let Some(cell) = buf.cell_mut((x, mark.y)) {
cell.set_char(*glyph).set_style(self.theme.style(*role));
#[cfg(test)]
mod tests;