From 231b4203c88cb3a76ae97c20dce43b5a2100e547 Mon Sep 17 00:00:00 2001 From: Nuno David Date: Sat, 19 Oct 2024 17:49:35 +0100 Subject: [PATCH] feat: allow overriding the mode label --- src/line.rs | 17 ++--------------- src/main.rs | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/line.rs b/src/line.rs index c44c13f..b88516e 100644 --- a/src/line.rs +++ b/src/line.rs @@ -214,21 +214,8 @@ fn tab_line_prefix( }) } - let mode_part = match mode { - InputMode::Locked => " ".to_string(), - _ => { - let mode_string = format!("{:?}", mode); - format!( - "{} ", - mode_string - .chars() - .next() - .unwrap() - .to_uppercase() - .collect::() - ) - } - }; + let mut mode_part = user_conf.mode_display.get(&mode).unwrap().to_owned(); + mode_part.push(' '); let mode_part_len = mode_part.width(); let mode_part_styled_text = match mode { InputMode::Normal => style!(normal_mode_color, bg_color).bold().paint(mode_part), diff --git a/src/main.rs b/src/main.rs index 569a7be..1be50a6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ mod line; mod tab; use std::cmp::{max, min}; -use std::collections::BTreeMap; +use std::collections::{BTreeMap, HashMap}; use std::convert::TryInto; use tab::get_tab_to_focus; @@ -44,6 +44,7 @@ pub struct UserConfiguration { color_others: PaletteColor, display_session_directory: bool, default_tab_name: String, + mode_display: HashMap, } impl UserConfiguration { @@ -110,7 +111,43 @@ impl UserConfiguration { configuration: &BTreeMap, colors: &Palette, ) -> Self { + let mode_display: HashMap = [ + InputMode::Normal, + InputMode::Locked, + InputMode::Resize, + InputMode::Pane, + InputMode::Tab, + InputMode::Scroll, + InputMode::EnterSearch, + InputMode::Search, + InputMode::RenameTab, + InputMode::RenamePane, + InputMode::Session, + InputMode::Move, + InputMode::Prompt, + InputMode::Tmux, + ] + .iter() + .cloned() + .map(|mode| { + let mode_string = format!("{:?}", mode); + let fallback = if mode == InputMode::Locked { + String::new() + } else { + mode_string.chars().next().unwrap().to_uppercase().collect() + }; + ( + mode, + Self::get_string_from_configuration( + &configuration, + format!("{mode_string}ModeLabel").as_str(), + &fallback, + ), + ) + }) + .collect(); Self { + mode_display, color_fg: Self::get_color_from_configuration( &configuration, "FgColor",