zilliz 1.4.3

TUI and CLI tool for managing Zilliz Cloud clusters and Milvus operations
Documentation
use ratatui::prelude::*;

use crate::tui::app::{App, Screen};
use crate::tui::widgets::card::{self, Card};

pub fn render(frame: &mut Frame, app: &App, area: Rect) {
    let host = app.screen_below_top().cloned().unwrap_or(Screen::Home);
    let body = help_for(&host, app);
    card::render(
        frame,
        area,
        &Card {
            eyebrow: Some("HELP"),
            title: Some(title_for(&host)),
            body,
            footer: None,
            error: None,
            step: None,
            max_width: 70,
        },
    );
}

fn title_for(host: &Screen) -> &'static str {
    match host {
        Screen::Home => "Home keybindings",
        Screen::SignInRegion => "Sign-in · Region",
        Screen::SignInMethod => "Sign-in · Method",
        Screen::SignInBrowser => "Sign-in · Browser",
        Screen::SignInApiKey => "Sign-in · API key",
        Screen::LogoutConfirm => "Sign out",
        Screen::Help => "Help",
    }
}

fn help_for(host: &Screen, app: &App) -> Vec<Line<'static>> {
    let rows: Vec<(&'static str, &'static str)> = match host {
        Screen::Home => {
            if app.auth.is_signed_in() {
                vec![
                    ("l", "Sign out"),
                    ("?", "Toggle this help"),
                    ("q / esc", "Quit"),
                ]
            } else {
                vec![
                    ("l", "Start sign-in"),
                    ("?", "Toggle this help"),
                    ("q / esc / ^C", "Quit"),
                ]
            }
        }
        Screen::SignInRegion => vec![
            ("↑ ↓ / j k", "Move selection"),
            ("g", "Pick Global"),
            ("c", "Pick China"),
            ("enter", "Continue"),
            ("esc", "Cancel"),
        ],
        Screen::SignInMethod => vec![
            ("↑ ↓ / j k", "Move selection"),
            ("1", "Pick Browser (Auth0)"),
            ("2", "Pick API key"),
            ("enter", "Continue"),
            ("b", "Back"),
            ("esc", "Cancel"),
        ],
        Screen::SignInBrowser => vec![("o", "Re-open browser"), ("esc", "Cancel sign-in")],
        Screen::SignInApiKey => vec![
            ("type", "Edit API key"),
            ("^H", "Show / hide value"),
            ("^V", "Paste from clipboard"),
            ("tab / ↑ ↓", "Move focus to save toggle"),
            ("space", "Toggle save"),
            ("enter", "Sign in"),
            ("b", "Back"),
            ("esc", "Cancel"),
        ],
        Screen::LogoutConfirm => vec![("y / enter", "Confirm sign-out"), ("n / esc", "Cancel")],
        Screen::Help => vec![("esc", "Close help")],
    };

    rows.into_iter()
        .map(|(k, label)| {
            Line::from(vec![
                Span::styled(
                    format!(" {:<14}", k),
                    Style::default()
                        .fg(Color::White)
                        .add_modifier(Modifier::BOLD),
                ),
                Span::styled(label, Style::default().fg(Color::Gray)),
            ])
        })
        .collect()
}