'list' command now shows a symbol for the previous session

This commit is contained in:
Valerie Wolfe 2024-07-17 11:30:50 -04:00
parent 8ad16ad825
commit fdf3114c04
3 changed files with 31 additions and 12 deletions

View file

@ -135,6 +135,11 @@ Default: '>'
.It Ev REMUX_NEW_WINDOW .It Ev REMUX_NEW_WINDOW
Provides a default windows name when creating a new session. Unused if empty. Provides a default windows name when creating a new session. Unused if empty.
Default: (unset) 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 .It Ev REMUX_REPO_FILE
The filename to match on when trying to find the root of a repository. The filename to match on when trying to find the root of a repository.
Default: '.git' Default: '.git'

View file

@ -9,11 +9,19 @@ use tmux_interface::{
}; };
use crate::{ use crate::{
env::{ self, env_var }, env::{
self,
env_var,
SYMBOL_ATTACH, SYMBOL_CURRENT, SYMBOL_PREV
},
error, error,
flag, flag,
state::State, state::State,
util::{ self, NULL } util::{
self,
message,
MSG_PREVIOUS, NULL
}
}; };
pub fn attach(state: &mut State) { pub fn attach(state: &mut State) {
@ -127,8 +135,9 @@ pub fn list(state: &mut State) {
} }
// get attached session symbol // get attached session symbol
let attach_symbol = env_var(env::ATTACH_SYMBOL); let attach_symbol = env_var(SYMBOL_ATTACH);
let current_symbol = env_var(env::CURRENT_SYMBOL); let current_symbol = env_var(SYMBOL_CURRENT);
let prev_symbol = env_var(SYMBOL_PREV);
// pretty print session list // pretty print session list
if !state.flags.quiet { println!("sessions:"); } if !state.flags.quiet { println!("sessions:"); }
@ -141,13 +150,17 @@ pub fn list(state: &mut State) {
let id = session.id.unwrap(); let id = session.id.unwrap();
let attached = session.attached.unwrap_or(0) > 0; 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!( println!(
" {current} {name}{reset} ({bold}{blue}{id}{reset}) {bold}{green}{attach}{reset}", " {marker} {name}{reset} ({bold}{blue}{id}{reset}) {bold}{green}{attach}{reset}",
// values // values
attach = if attached { attach_symbol.clone() } else { "".to_string() }, attach = if attached { attach_symbol.clone() } else { "".to_string() },
current = if current { current_symbol.clone() } else { " ".to_string() },
// formatting // formatting
bold = style::Bold, bold = style::Bold,
blue = color::Fg(color::Blue), blue = color::Fg(color::Blue),

View file

@ -2,12 +2,13 @@ use std::env::var;
pub type EnvVar = (&'static str, &'static str); pub type EnvVar = (&'static str, &'static str);
pub static ATTACH_SYMBOL: EnvVar = ("REMUX_ATTACH_SYMBOL", "*"); pub const NEW_WINDOW_NAME: EnvVar = ("REMUX_NEW_WINDOW", "");
pub static CURRENT_SYMBOL: EnvVar = ("REMUX_CURRENT_SYMBOL", ">"); pub const REPO_FILE: EnvVar = ("REMUX_REPO_FILE", ".git");
pub static NEW_WINDOW_NAME: EnvVar = ("REMUX_NEW_WINDOW", ""); pub const SYMBOL_ATTACH: EnvVar = ("REMUX_ATTACH_SYMBOL", "*");
pub static REPO_FILE: EnvVar = ("REMUX_REPO_FILE", ".git"); 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 /// get or default an environment variable
pub fn env_var(envvar: EnvVar) -> String { pub fn env_var(envvar: EnvVar) -> String {