hefesto-widgets 0.7.1

Ratatui widgets for the Hefesto TUI toolkit: popups, scrollable lists, trees, text input and spinners
Documentation
use super::*;
use crate::popups::{ChoosePopupState, FileBrowserState, FileEntry};
use insta::assert_snapshot;
use ratatui::{backend::TestBackend, Terminal};

fn render_stateful(name: &str, fb: FileBrowser, state: &mut FileBrowserState) {
    let backend = TestBackend::new(60, 12);
    let mut terminal = Terminal::new(backend).unwrap();
    terminal
        .draw(|f| f.render_stateful_widget(fb, f.area(), state))
        .unwrap();
    assert_snapshot!(name, terminal.backend());
}

fn make_state() -> FileBrowserState {
    FileBrowserState {
        entries: vec![
            FileEntry {
                name: "Documentos".to_string(),
                is_dir: true,
                path: "/home/user/Documentos".into(),
            },
            FileEntry {
                name: "foto.jpg".to_string(),
                is_dir: false,
                path: "/home/user/foto.jpg".into(),
            },
            FileEntry {
                name: "notas.txt".to_string(),
                is_dir: false,
                path: "/home/user/notas.txt".into(),
            },
        ],
        items: vec![
            ("📁 Documentos".to_string(), Style::new().fg(Color::Cyan)),
            ("📄 foto.jpg".to_string(), Style::default()),
            ("📄 notas.txt".to_string(), Style::default()),
        ],
        cwd: "/home/user".into(),
        choose_popup_state: ChoosePopupState::default(),
        show_hidden: false,
    }
}

// ── snapshots ──

#[test]
fn snapshot_default() {
    let fb = FileBrowser::new();
    let mut state = make_state();
    render_stateful("file_browser_default", fb, &mut state);
}

#[test]
fn snapshot_styled() {
    let fb = FileBrowser::new()
        .dir_style(Style::new().fg(Color::Green))
        .file_style(Style::new().fg(Color::Yellow));
    let mut state = make_state();
    render_stateful("file_browser_styled", fb, &mut state);
}

#[test]
fn snapshot_custom_icons() {
    let fb = FileBrowser::new()
        .dir_icon("🔷 ")
        .file_icon("🔹 ");
    let mut state = make_state();
    render_stateful("file_browser_custom_icons", fb, &mut state);
}

#[test]
fn snapshot_with_selection() {
    let fb = FileBrowser::new();
    let mut state = make_state();
    state.choose_popup_state.chosen_indices.insert(0);
    render_stateful("file_browser_with_selection", fb, &mut state);
}