From e930af102738f1be2fa03f51a3d176248caed16f Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 1 Jul 2024 09:12:38 -0400 Subject: [PATCH] list command now shows a symbol in front of the current session --- src/command/share.rs | 14 +++++++++----- src/env.rs | 1 + src/help.rs | 7 ++++++- src/main.rs | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/command/share.rs b/src/command/share.rs index 2797c60..e75b1ee 100644 --- a/src/command/share.rs +++ b/src/command/share.rs @@ -83,7 +83,7 @@ pub fn context_action(state: &State) { return; } else { // fallback behavior is list - list(); + list(&state); } } @@ -138,7 +138,7 @@ pub fn has(state: &mut State) { exit( if success { 0 } else { 1 }); } -pub fn list() { +pub fn list(state: &State) { // get session list let sessions = util::get_sessions().unwrap_or(Vec::new()); @@ -149,24 +149,28 @@ pub fn list() { } // get attached session symbol - let attach_symbol = env_var(env::ATTACH_SYMBOL); + let attach_symbol = env_var(env::ATTACH_SYMBOL); + let current_symbol = env_var(env::CURRENT_SYMBOL); // pretty print session list println!("sessions:"); for session in sessions.into_iter() { let name = session.name.unwrap_or("[untitled]".to_string()); let id = session.id.unwrap(); + let attached = session.attached.unwrap_or(0) > 0; + let current = Some(name.clone()) == state.title; println!( - " {name} ({bold}{blue}{id}{reset}) {bold}{green}{attach}{reset}", + " {current} {name}{reset} ({bold}{blue}{id}{reset}) {bold}{green}{attach}{reset}", // values attach = if attached { attach_symbol.clone() } else { "".to_string() }, + current = if current { current_symbol.clone() } else { " ".to_string() }, // formatting bold = style::Bold, blue = color::Fg(color::Blue), green = color::Fg(color::LightGreen), - reset = style::Reset + reset = style::Reset, ); } } diff --git a/src/env.rs b/src/env.rs index 4376a30..37bc192 100644 --- a/src/env.rs +++ b/src/env.rs @@ -3,6 +3,7 @@ use std::env::var; pub type EnvVar = (&'static str, &'static str); pub static ATTACH_SYMBOL: EnvVar = ("REMUX_ATTACH_SYMBOL", "*"); +pub static CURRENT_SYMBOL: EnvVar = ("REMUX_CURRENT_SYMBOL", ">"); pub static NEW_WINDOW_NAME: EnvVar = ("REMUX_NEW_WINDOW", ""); pub static TMUX: &str = "TMUX"; diff --git a/src/help.rs b/src/help.rs index d9baa88..d789deb 100644 --- a/src/help.rs +++ b/src/help.rs @@ -148,10 +148,15 @@ REMUX_ATTACH_SYMBOL by the 'list' command. Default: '*' +REMUX_CURRENT_SYMBOL + Changes the symbol displayed to denote the current session + in the 'list' command. + Default: '>' + REMUX_NEW_WINDOW Provides a default window name when creating a session with the 'new' command, if not empty. - Default: ''"), + Default: (unset)"), // not found _ => error::no_help(topic.unwrap()) diff --git a/src/main.rs b/src/main.rs index 6e8b2dc..14f8f04 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,7 +50,7 @@ fn main() { => command::share::has(&mut state), Some("l" | "ls" | "list") - => command::share::list(), + => command::share::list(&state), Some("n" | "new") => command::share::new(&mut state),