use crate::agent_commands_store::AgentCommandStore;
use crate::command_palette::catalog::{
PaletteEntry, agent_palette_entries, plugin_palette_entries,
};
use crate::config::Config;
use crate::crash_triage::CrashTriageState;
use crate::status_bar::StatusBarUI;
#[cfg(feature = "mux")]
use crate::app::tmux_handler::tmux_state::TmuxState;
pub(crate) fn palette_runtime_rows(
status_bar_ui: &StatusBarUI,
agent_commands: &AgentCommandStore,
crash_triage: &mut CrashTriageState,
config: &Config,
profiles: &crate::profile::ProfileManager,
#[cfg(feature = "mux")] tmux_state: &TmuxState,
) -> Vec<PaletteEntry> {
let mut rows = plugin_palette_entries(&status_bar_ui.plugin_host().palette_actions());
rows.extend(profile_palette_entries(profiles));
rows.extend(agent_commands.palette_rows());
rows.extend(agent_palette_entries(&config.agents));
rows.extend(crash_triage.palette_entries());
#[cfg(feature = "mux")]
{
let map = &tmux_state.tmux_pane_owners;
rows.extend(
tmux_state
.agent_roster
.palette_rows(&|pane| map.contains_key(&pane)),
);
rows.extend(tmux_state.mux_palette_rows());
rows.extend(crate::app::window_state::WindowState::mux_session_palette_rows(tmux_state));
}
rows
}
pub(crate) fn profile_palette_entries(
profiles: &crate::profile::ProfileManager,
) -> Vec<PaletteEntry> {
use crate::profile::actions::{ProfileAction, ProfileSplit};
profiles
.profiles_ordered()
.into_iter()
.flat_map(|p| {
[
("Open Profile", ProfileAction::OpenTab(p.id)),
(
"Open Profile in New Window",
ProfileAction::OpenWindow(p.id),
),
(
"Split with Profile",
ProfileAction::Split(p.id, ProfileSplit::Right),
),
("Change Tab Profile", ProfileAction::SetTabProfile(p.id)),
]
.map(|(verb, action)| PaletteEntry {
action_id: action.id(),
label: format!("{verb}: {}", p.name),
chord: None,
priority: 0,
})
})
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_profile_gets_its_four_palette_rows() {
let mut profiles = crate::profile::ProfileManager::new();
let work = crate::profile::Profile::new("Work");
let id = work.id;
profiles.add(work);
let rows = profile_palette_entries(&profiles);
let pairs: Vec<(String, String)> = rows
.iter()
.map(|r| (r.label.clone(), r.action_id.clone()))
.collect();
assert_eq!(
pairs,
[
(
"Open Profile: Work".to_string(),
format!("open_profile:{id}")
),
(
"Open Profile in New Window: Work".to_string(),
format!("open_profile_window:{id}")
),
(
"Split with Profile: Work".to_string(),
format!("split_profile:{id}:right")
),
(
"Change Tab Profile: Work".to_string(),
format!("set_tab_profile:{id}")
),
]
);
for row in &rows {
assert_eq!(
crate::command_palette::meta::category(&row.action_id),
"Profiles"
);
assert!(crate::command_palette::meta::description(&row.action_id).is_some());
}
}
}