tmx/ui/
session_switcher.rs1use anyhow::Result;
2use ratatui::style::Style;
3use ratatui::text::{Line, Span};
4
5use crate::tmux::Session;
6use crate::ui::picker::{PickerConfig, PickerItem, run_picker};
7use crate::ui::theme;
8
9impl PickerItem for Session {
10 fn fuzzy_key(&self) -> &str {
11 &self.name
12 }
13
14 fn render(&self, is_cursor: bool) -> Line<'static> {
15 let (cursor_marker, name_style) = if is_cursor {
16 (
17 Span::styled("▸ ", Style::default().fg(theme::VIOLET)),
18 theme::selected_style(),
19 )
20 } else {
21 (Span::raw(" "), theme::normal_style())
22 };
23
24 let mut spans = vec![
25 cursor_marker,
26 Span::styled(self.name.clone(), name_style),
27 Span::styled(format!(" {} window(s)", self.windows), theme::muted_style()),
28 ];
29 if self.attached {
30 spans.push(Span::styled(" ●", Style::default().fg(theme::GREEN)));
31 }
32 Line::from(spans)
33 }
34}
35
36pub fn run_session_switcher(sessions: Vec<Session>) -> Result<Option<Session>> {
37 run_picker(
38 sessions,
39 PickerConfig {
40 title: "tmux sessions",
41 search_placeholder: "Search sessions...",
42 empty_message: "No sessions found",
43 item_noun: "sessions",
44 },
45 )
46}