diff --git a/src/main.rs b/src/main.rs index 245b9ea..d8151fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,11 +80,17 @@ fn main() -> Result<()> { let config_path = resolve_config_path(cli.config); let json = std::fs::read_to_string(&config_path) .with_context(|| format!("failed to read config file {}", config_path.display()))?; - let config = load_config(&json)?; + let mut config = load_config(&json)?; check_base_exists("deployments_base", &config.deployments_base, &config_path)?; check_base_exists("venvs_base", &config.deployments_base, &config_path)?; + // Populate the config with deployments found on disk so they are available + // to both `lookup_entry` and the TUI. Configured entries take precedence. + for (label, entry) in config.discovered_entries() { + config.entries.entry(label).or_insert(entry); + } + match cli.command { Command::Pick => { if let Some(launch) = tui::run(&config, DEFAULT_ENV_FILE)? { diff --git a/src/tui/entries.rs b/src/tui/entries.rs index 5729e38..46c92c6 100644 --- a/src/tui/entries.rs +++ b/src/tui/entries.rs @@ -11,8 +11,8 @@ use crate::config::LauncherEntry; /// Which entry point to launch for the selected entry. #[derive(Clone, Copy, PartialEq)] enum LaunchChoice { - Gui, Server, + Gui, } /// The entries list: configured entries plus discovered deployments, with a @@ -117,7 +117,7 @@ impl EntriesTab { let items: Vec = self .entries .iter() - .map(|(label, _)| ListItem::new(label.as_str())) + .map(|(label, _)| ListItem::new(display_label(label))) .collect(); let list = List::new(items) .block(Block::default().borders(Borders::ALL).title("Entries")) @@ -158,8 +158,8 @@ impl EntriesTab { }; let text = Text::from(vec![ - Line::styled(" Launch GUI ", gui_style), Line::styled(" Launch Server ", server_style), + Line::styled(" Launch GUI ", gui_style), Line::from(""), Line::from("↑/↓ choose · Enter confirm · Esc cancel"), ]); @@ -168,6 +168,12 @@ impl EntriesTab { } } +/// The label shown in the list: the default `/.venv` virtualenv suffix (used by +/// discovered deployments) is dropped for readability. +fn display_label(label: &str) -> &str { + label.strip_suffix("/.venv").unwrap_or(label) +} + /// A rectangle centered within `area`, sized as a percentage of it. fn centered_rect(width_pct: u16, height_pct: u16, area: Rect) -> Rect { let [area] = Layout::vertical([Constraint::Percentage(height_pct)]) @@ -178,3 +184,23 @@ fn centered_rect(width_pct: u16, height_pct: u16, area: Rect) -> Rect { .areas(area); area } + +#[cfg(test)] +mod tests { + use super::display_label; + + #[test] + fn strips_default_venv_suffix() { + assert_eq!(display_label("mydeploy/.venv"), "mydeploy"); + } + + #[test] + fn keeps_named_venv() { + assert_eq!(display_label("mydeploy/pxii"), "mydeploy/pxii"); + } + + #[test] + fn leaves_plain_labels_untouched() { + assert_eq!(display_label("x10sa"), "x10sa"); + } +} diff --git a/src/tui/mod.rs b/src/tui/mod.rs index 6960587..78e52b7 100644 --- a/src/tui/mod.rs +++ b/src/tui/mod.rs @@ -36,13 +36,13 @@ struct App { impl App { fn new(config: &Config, env_file: &str) -> Self { - // Configured entries first, then the deployments discovered on disk. - let mut entries: Vec<(String, LauncherEntry)> = config + // Entries (configured + deployments discovered at startup) come straight + // from the config. + let entries: Vec<(String, LauncherEntry)> = config .entries .iter() .map(|(label, entry)| (label.clone(), entry.clone())) .collect(); - entries.extend(config.discovered_entries()); App { entries: EntriesTab::new(entries),