romm_cli/tui/screens/
settings.rs1use ratatui::layout::{Constraint, Layout, Rect};
2use ratatui::widgets::{Block, Borders, Paragraph};
3use ratatui::Frame;
4
5use crate::config::Config;
6
7pub struct SettingsScreen {
9 pub base_url: String,
10 pub auth_status: String,
11 pub version: String,
12 pub server_version: String,
13 pub github_url: String,
14}
15
16impl SettingsScreen {
17 pub fn new(config: &Config, romm_server_version: Option<&str>) -> Self {
18 let auth_status = match &config.auth {
19 Some(crate::config::AuthConfig::Basic { username, .. }) => {
20 format!("Basic (user: {})", username)
21 }
22 Some(crate::config::AuthConfig::Bearer { .. }) => "Bearer token".to_string(),
23 Some(crate::config::AuthConfig::ApiKey { header, .. }) => {
24 format!("API key (header: {})", header)
25 }
26 None => "None (no API credentials in env/keyring)".to_string(),
27 };
28
29 let server_version = romm_server_version
30 .map(String::from)
31 .unwrap_or_else(|| "unavailable (heartbeat failed)".to_string());
32
33 Self {
34 base_url: config.base_url.clone(),
35 auth_status,
36 version: env!("CARGO_PKG_VERSION").to_string(),
37 server_version,
38 github_url: "https://github.com/patricksmill/romm-cli".to_string(),
39 }
40 }
41
42 pub fn render(&self, f: &mut Frame, area: Rect) {
43 let chunks = Layout::default()
44 .constraints([Constraint::Min(8), Constraint::Length(5)])
45 .direction(ratatui::layout::Direction::Vertical)
46 .split(area);
47
48 let lines = [
49 format!("romm-cli: v{}", self.version),
50 format!("RomM server: {}", self.server_version),
51 format!("GitHub: {}", self.github_url),
52 String::new(),
53 format!("Base URL: {}", self.base_url),
54 format!("Auth: {}", self.auth_status),
55 String::new(),
56 "API auth is separate from logging into RomM in the browser.".to_string(),
57 "Change via env / ~/.config/romm-cli/.env / keyring; restart after edits.".to_string(),
58 ];
59 let text = lines.join("\n");
60 let p =
61 Paragraph::new(text).block(Block::default().title("Settings").borders(Borders::ALL));
62 f.render_widget(p, chunks[0]);
63
64 let help = "Esc: Back to menu";
65 let p = Paragraph::new(help).block(Block::default().borders(Borders::ALL));
66 f.render_widget(p, chunks[1]);
67 }
68}