|
| 1 | +// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +//! Splash screen shown on TUI startup — the "B2 Framed" design. |
| 5 | +//! |
| 6 | +//! Renders the ANSI Shadow block-letter logo (OPEN in white, SHELL in green) |
| 7 | +//! inside a double-line border, with the tagline and a version/prompt footer. |
| 8 | +
|
| 9 | +use ratatui::Frame; |
| 10 | +use ratatui::layout::{Alignment, Constraint, Direction, Layout, Rect}; |
| 11 | +use ratatui::style::{Modifier, Style}; |
| 12 | +use ratatui::text::{Line, Span}; |
| 13 | +use ratatui::widgets::{Block, BorderType, Borders, Clear, Padding, Paragraph}; |
| 14 | + |
| 15 | +use crate::theme::{colors, styles}; |
| 16 | + |
| 17 | +// --------------------------------------------------------------------------- |
| 18 | +// ANSI Shadow figlet art — OPEN (6 lines, 35 display cols) |
| 19 | +// --------------------------------------------------------------------------- |
| 20 | + |
| 21 | +const OPEN_ART: [&str; 6] = [ |
| 22 | + " ██████╗ ██████╗ ███████╗███╗ ██╗", |
| 23 | + "██╔═══██╗██╔══██╗██╔════╝████╗ ██║", |
| 24 | + "██║ ██║██████╔╝█████╗ ██╔██╗ ██║", |
| 25 | + "██║ ██║██╔═══╝ ██╔══╝ ██║╚██╗██║", |
| 26 | + "╚██████╔╝██║ ███████╗██║ ╚████║", |
| 27 | + " ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝", |
| 28 | +]; |
| 29 | + |
| 30 | +// --------------------------------------------------------------------------- |
| 31 | +// ANSI Shadow figlet art — SHELL (6 lines, 40 display cols) |
| 32 | +// --------------------------------------------------------------------------- |
| 33 | + |
| 34 | +const SHELL_ART: [&str; 6] = [ |
| 35 | + "███████╗██╗ ██╗███████╗██╗ ██╗", |
| 36 | + "██╔════╝██║ ██║██╔════╝██║ ██║", |
| 37 | + "███████╗███████║█████╗ ██║ ██║", |
| 38 | + "╚════██║██╔══██║██╔══╝ ██║ ██║", |
| 39 | + "███████║██║ ██║███████╗███████╗███████╗", |
| 40 | + "╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝", |
| 41 | +]; |
| 42 | + |
| 43 | +const TAGLINE: &str = "Shells Wide Shut."; |
| 44 | + |
| 45 | +/// Maximum display width of the art (SHELL line 5 is the widest at 40 cols). |
| 46 | +const ART_WIDTH: u16 = 40; |
| 47 | + |
| 48 | +/// Total content lines: 6 (OPEN) + 6 (SHELL) + 1 (blank) + 1 (tagline) = 14. |
| 49 | +const CONTENT_LINES: u16 = 14; |
| 50 | + |
| 51 | +// Border (2) + top/bottom inner padding (2) + content + blank before footer (1) + footer (1). |
| 52 | +const MODAL_HEIGHT: u16 = CONTENT_LINES + 6; |
| 53 | + |
| 54 | +// Art width + left/right padding (3+3) + borders (2). |
| 55 | +const MODAL_WIDTH: u16 = ART_WIDTH + 8; |
| 56 | + |
| 57 | +/// Draw the splash screen centered on the full terminal area. |
| 58 | +pub fn draw(frame: &mut Frame<'_>, area: Rect) { |
| 59 | + let modal_w = MODAL_WIDTH.min(area.width.saturating_sub(2)); |
| 60 | + let modal_h = MODAL_HEIGHT.min(area.height.saturating_sub(2)); |
| 61 | + |
| 62 | + // Center the modal. |
| 63 | + let popup = centered_rect(modal_w, modal_h, area); |
| 64 | + |
| 65 | + // Clear the area behind the modal. |
| 66 | + frame.render_widget(Clear, popup); |
| 67 | + |
| 68 | + // Outer double-line border. |
| 69 | + let block = Block::default() |
| 70 | + .borders(Borders::ALL) |
| 71 | + .border_type(BorderType::Double) |
| 72 | + .border_style(Style::new().fg(colors::EVERGLADE)) |
| 73 | + .padding(Padding::new(3, 3, 1, 1)); |
| 74 | + |
| 75 | + let inner = block.inner(popup); |
| 76 | + frame.render_widget(block, popup); |
| 77 | + |
| 78 | + // Split inner area: art content + spacer + footer. |
| 79 | + let chunks = Layout::default() |
| 80 | + .direction(Direction::Vertical) |
| 81 | + .constraints([ |
| 82 | + Constraint::Length(CONTENT_LINES), // OPEN + SHELL + blank + tagline |
| 83 | + Constraint::Min(0), // spacer |
| 84 | + Constraint::Length(1), // footer |
| 85 | + ]) |
| 86 | + .split(inner); |
| 87 | + |
| 88 | + // -- Art + tagline -- |
| 89 | + let open_style = Style::new().fg(colors::FG).add_modifier(Modifier::BOLD); |
| 90 | + let shell_style = Style::new() |
| 91 | + .fg(colors::NVIDIA_GREEN) |
| 92 | + .add_modifier(Modifier::BOLD); |
| 93 | + |
| 94 | + let mut content_lines: Vec<Line<'_>> = Vec::with_capacity(CONTENT_LINES as usize); |
| 95 | + |
| 96 | + for line in &OPEN_ART { |
| 97 | + content_lines.push(Line::from(Span::styled(*line, open_style))); |
| 98 | + } |
| 99 | + for line in &SHELL_ART { |
| 100 | + content_lines.push(Line::from(Span::styled(*line, shell_style))); |
| 101 | + } |
| 102 | + |
| 103 | + // Blank + tagline. |
| 104 | + content_lines.push(Line::from("")); |
| 105 | + content_lines |
| 106 | + .push(Line::from(Span::styled(TAGLINE, styles::MUTED)).alignment(Alignment::Center)); |
| 107 | + |
| 108 | + frame.render_widget(Paragraph::new(content_lines), chunks[0]); |
| 109 | + |
| 110 | + // -- Footer: version + ALPHA badge (left) + prompt (right) -- |
| 111 | + let version = format!("v{}", env!("CARGO_PKG_VERSION")); |
| 112 | + let spacer = " "; |
| 113 | + let alpha_badge = "ALPHA"; |
| 114 | + let prompt_text = "press any key"; |
| 115 | + |
| 116 | + // Pad between left group and prompt to fill the line. |
| 117 | + let used = version.len() + spacer.len() + alpha_badge.len() + prompt_text.len() + 2; // +2 for ░ and space |
| 118 | + let footer_width = chunks[2].width as usize; |
| 119 | + let gap = footer_width.saturating_sub(used); |
| 120 | + |
| 121 | + let footer = Line::from(vec![ |
| 122 | + Span::styled(version, Style::new().fg(colors::NVIDIA_GREEN)), |
| 123 | + Span::styled(spacer, styles::MUTED), |
| 124 | + Span::styled( |
| 125 | + alpha_badge, |
| 126 | + Style::new() |
| 127 | + .fg(colors::FG) |
| 128 | + .bg(colors::EVERGLADE) |
| 129 | + .add_modifier(Modifier::BOLD), |
| 130 | + ), |
| 131 | + Span::styled(" ".repeat(gap), styles::MUTED), |
| 132 | + Span::styled(prompt_text, styles::MUTED), |
| 133 | + Span::styled(" ░", styles::MUTED), |
| 134 | + ]); |
| 135 | + |
| 136 | + frame.render_widget(Paragraph::new(footer), chunks[2]); |
| 137 | +} |
| 138 | + |
| 139 | +fn centered_rect(width: u16, height: u16, area: Rect) -> Rect { |
| 140 | + let vert = Layout::default() |
| 141 | + .direction(Direction::Vertical) |
| 142 | + .constraints([ |
| 143 | + Constraint::Length((area.height.saturating_sub(height)) / 2), |
| 144 | + Constraint::Length(height), |
| 145 | + Constraint::Min(0), |
| 146 | + ]) |
| 147 | + .split(area); |
| 148 | + let horiz = Layout::default() |
| 149 | + .direction(Direction::Horizontal) |
| 150 | + .constraints([ |
| 151 | + Constraint::Length((area.width.saturating_sub(width)) / 2), |
| 152 | + Constraint::Length(width), |
| 153 | + Constraint::Min(0), |
| 154 | + ]) |
| 155 | + .split(vert[1]); |
| 156 | + horiz[1] |
| 157 | +} |
0 commit comments