From fdf3114c04060f9c9e18fe65a924a0cd9b9be604 Mon Sep 17 00:00:00 2001 From: Valerie Date: Wed, 17 Jul 2024 11:30:50 -0400 Subject: [PATCH] 'list' command now shows a symbol for the previous session --- man/remux.1 | 5 +++++ src/command/share.rs | 27 ++++++++++++++++++++------- src/env.rs | 11 ++++++----- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/man/remux.1 b/man/remux.1 index a9a2f12..c003f7a 100644 --- a/man/remux.1 +++ b/man/remux.1 @@ -135,6 +135,11 @@ Default: '>' .It Ev REMUX_NEW_WINDOW Provides a default windows name when creating a new session. Unused if empty. Default: (unset) +.It Ev REMUX_PREVIOUS_SYMBOL +Changes the symbol displayed for the previous session in the +.Ic list +command. +Default: '-' .It Ev REMUX_REPO_FILE The filename to match on when trying to find the root of a repository. Default: '.git' diff --git a/src/command/share.rs b/src/command/share.rs index 3acec88..14c502b 100644 --- a/src/command/share.rs +++ b/src/command/share.rs @@ -9,11 +9,19 @@ use tmux_interface::{ }; use crate::{ - env::{ self, env_var }, + env::{ + self, + env_var, + SYMBOL_ATTACH, SYMBOL_CURRENT, SYMBOL_PREV + }, error, flag, state::State, - util::{ self, NULL } + util::{ + self, + message, + MSG_PREVIOUS, NULL + } }; pub fn attach(state: &mut State) { @@ -127,8 +135,9 @@ pub fn list(state: &mut State) { } // get attached session symbol - let attach_symbol = env_var(env::ATTACH_SYMBOL); - let current_symbol = env_var(env::CURRENT_SYMBOL); + let attach_symbol = env_var(SYMBOL_ATTACH); + let current_symbol = env_var(SYMBOL_CURRENT); + let prev_symbol = env_var(SYMBOL_PREV); // pretty print session list if !state.flags.quiet { println!("sessions:"); } @@ -141,13 +150,17 @@ pub fn list(state: &mut State) { let id = session.id.unwrap(); let attached = session.attached.unwrap_or(0) > 0; - let current = Some(name.clone()) == state.title; + + let compare = Some(name.clone()); + let marker = + if compare == state.title { current_symbol.clone() } + else if compare == message(MSG_PREVIOUS) { prev_symbol.clone() } + else { " ".to_string() }; println!( - " {current} {name}{reset} ({bold}{blue}{id}{reset}) {bold}{green}{attach}{reset}", + " {marker} {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), diff --git a/src/env.rs b/src/env.rs index 208fa64..9898884 100644 --- a/src/env.rs +++ b/src/env.rs @@ -2,12 +2,13 @@ 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 REPO_FILE: EnvVar = ("REMUX_REPO_FILE", ".git"); +pub const NEW_WINDOW_NAME: EnvVar = ("REMUX_NEW_WINDOW", ""); +pub const REPO_FILE: EnvVar = ("REMUX_REPO_FILE", ".git"); +pub const SYMBOL_ATTACH: EnvVar = ("REMUX_ATTACH_SYMBOL", "*"); +pub const SYMBOL_CURRENT: EnvVar = ("REMUX_CURRENT_SYMBOL", ">"); +pub const SYMBOL_PREV: EnvVar = ("REMUX_PREVIOUS_SYMBOL", "-"); -pub static TMUX: &str = "TMUX"; +pub const TMUX: &str = "TMUX"; /// get or default an environment variable pub fn env_var(envvar: EnvVar) -> String {