Skip to content

Commit

Permalink
feat: allow overriding the mode label
Browse files Browse the repository at this point in the history
  • Loading branch information
ndavd committed Oct 19, 2024
1 parent ed8bfde commit 231b420
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
17 changes: 2 additions & 15 deletions src/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>()
)
}
};
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),
Expand Down
39 changes: 38 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,6 +44,7 @@ pub struct UserConfiguration {
color_others: PaletteColor,
display_session_directory: bool,
default_tab_name: String,
mode_display: HashMap<InputMode, String>,
}

impl UserConfiguration {
Expand Down Expand Up @@ -110,7 +111,43 @@ impl UserConfiguration {
configuration: &BTreeMap<String, String>,
colors: &Palette,
) -> Self {
let mode_display: HashMap<InputMode, String> = [
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",
Expand Down

0 comments on commit 231b420

Please sign in to comment.