Merge pull request #608 from LovecraftianHorror/display-session-name

Display session name within `zellij`
This commit is contained in:
a-kenji 2021-07-22 16:46:49 +02:00 committed by GitHub
commit 69173acd5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 44 deletions

View file

@ -144,8 +144,12 @@ fn add_next_tabs_msg(
title_bar.push(right_more_message); title_bar.push(right_more_message);
} }
fn tab_line_prefix(palette: Palette) -> LinePart { fn tab_line_prefix(session_name: Option<&str>, palette: Palette) -> LinePart {
let prefix_text = " Zellij ".to_string(); let mut prefix_text = " Zellij ".to_string();
if let Some(name) = session_name {
prefix_text.push_str(&format!("({}) ", name));
}
let prefix_text_len = prefix_text.chars().count(); let prefix_text_len = prefix_text.chars().count();
let prefix_styled_text = style!(palette.white, palette.cyan) let prefix_styled_text = style!(palette.white, palette.cyan)
.bold() .bold()
@ -165,6 +169,7 @@ pub fn tab_separator(capabilities: PluginCapabilities) -> &'static str {
} }
pub fn tab_line( pub fn tab_line(
session_name: Option<&str>,
mut all_tabs: Vec<LinePart>, mut all_tabs: Vec<LinePart>,
active_tab_index: usize, active_tab_index: usize,
cols: usize, cols: usize,
@ -181,7 +186,7 @@ pub fn tab_line(
}; };
tabs_to_render.push(active_tab); tabs_to_render.push(active_tab);
let prefix = tab_line_prefix(palette); let prefix = tab_line_prefix(session_name, palette);
populate_tabs_in_tab_line( populate_tabs_in_tab_line(
&mut tabs_before_active, &mut tabs_before_active,
&mut tabs_after_active, &mut tabs_after_active,

View file

@ -64,6 +64,7 @@ impl ZellijPlugin for State {
all_tabs.push(tab); all_tabs.push(tab);
} }
let tab_line = tab_line( let tab_line = tab_line(
self.mode_info.session_name.as_deref(),
all_tabs, all_tabs,
active_tab_index, active_tab_index,
cols, cols,

View file

@ -18,7 +18,7 @@ use crate::{
use zellij_tile::data::{Event, ModeInfo, Palette, PluginCapabilities, TabInfo}; use zellij_tile::data::{Event, ModeInfo, Palette, PluginCapabilities, TabInfo};
use zellij_utils::{ use zellij_utils::{
errors::{ContextType, ScreenContext}, errors::{ContextType, ScreenContext},
input::options::Options, input::{get_mode_info, options::Options},
ipc::ClientAttributes, ipc::ClientAttributes,
pane_size::PositionAndSize, pane_size::PositionAndSize,
}; };
@ -428,13 +428,13 @@ pub(crate) fn screen_thread_main(
bus, bus,
&client_attributes, &client_attributes,
max_panes, max_panes,
ModeInfo { get_mode_info(
palette: client_attributes.palette, config_options.default_mode.unwrap_or_default(),
capabilities: PluginCapabilities { client_attributes.palette,
PluginCapabilities {
arrow_fonts: capabilities, arrow_fonts: capabilities,
}, },
..ModeInfo::default() ),
},
session_state, session_state,
); );
loop { loop {

View file

@ -148,6 +148,7 @@ pub struct ModeInfo {
pub keybinds: Vec<(String, String)>, // <shortcut> => <shortcut description> pub keybinds: Vec<(String, String)>, // <shortcut> => <shortcut description>
pub palette: Palette, pub palette: Palette,
pub capabilities: PluginCapabilities, pub capabilities: PluginCapabilities,
pub session_name: Option<String>,
} }
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] #[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]

View file

@ -12,52 +12,48 @@ pub mod theme;
use termion::input::TermRead; use termion::input::TermRead;
use zellij_tile::data::{InputMode, Key, ModeInfo, Palette, PluginCapabilities}; use zellij_tile::data::{InputMode, Key, ModeInfo, Palette, PluginCapabilities};
/// Creates a [`Help`] struct indicating the current [`InputMode`] and its keybinds /// Creates a [`ModeInfo`] struct indicating the current [`InputMode`] and its keybinds
/// (as pairs of [`String`]s). /// (as pairs of [`String`]s).
// TODO this should probably be automatically generated in some way
pub fn get_mode_info( pub fn get_mode_info(
mode: InputMode, mode: InputMode,
palette: Palette, palette: Palette,
capabilities: PluginCapabilities, capabilities: PluginCapabilities,
) -> ModeInfo { ) -> ModeInfo {
let mut keybinds: Vec<(String, String)> = vec![]; let keybinds = match mode {
match mode { InputMode::Normal | InputMode::Locked => Vec::new(),
InputMode::Normal | InputMode::Locked => {} InputMode::Resize => vec![("←↓↑→".to_string(), "Resize".to_string())],
InputMode::Resize => { InputMode::Pane => vec![
keybinds.push(("←↓↑→".to_string(), "Resize".to_string())); ("←↓↑→".to_string(), "Move focus".to_string()),
} ("p".to_string(), "Next".to_string()),
InputMode::Pane => { ("n".to_string(), "New".to_string()),
keybinds.push(("←↓↑→".to_string(), "Move focus".to_string())); ("d".to_string(), "Down split".to_string()),
keybinds.push(("p".to_string(), "Next".to_string())); ("r".to_string(), "Right split".to_string()),
keybinds.push(("n".to_string(), "New".to_string())); ("x".to_string(), "Close".to_string()),
keybinds.push(("d".to_string(), "Down split".to_string())); ("f".to_string(), "Fullscreen".to_string()),
keybinds.push(("r".to_string(), "Right split".to_string())); ],
keybinds.push(("x".to_string(), "Close".to_string())); InputMode::Tab => vec![
keybinds.push(("f".to_string(), "Fullscreen".to_string())); ("←↓↑→".to_string(), "Move focus".to_string()),
} ("n".to_string(), "New".to_string()),
InputMode::Tab => { ("x".to_string(), "Close".to_string()),
keybinds.push(("←↓↑→".to_string(), "Move focus".to_string())); ("r".to_string(), "Rename".to_string()),
keybinds.push(("n".to_string(), "New".to_string())); ("s".to_string(), "Sync".to_string()),
keybinds.push(("x".to_string(), "Close".to_string())); ],
keybinds.push(("r".to_string(), "Rename".to_string())); InputMode::Scroll => vec![
keybinds.push(("s".to_string(), "Sync".to_string())); ("↓↑".to_string(), "Scroll".to_string()),
} ("PgUp/PgDn".to_string(), "Scroll Page".to_string()),
InputMode::Scroll => { ],
keybinds.push(("↓↑".to_string(), "Scroll".to_string())); InputMode::RenameTab => vec![("Enter".to_string(), "when done".to_string())],
keybinds.push(("PgUp/PgDn".to_string(), "Scroll Page".to_string())); InputMode::Session => vec![("d".to_string(), "Detach".to_string())],
} };
InputMode::RenameTab => {
keybinds.push(("Enter".to_string(), "when done".to_string())); let session_name = std::env::var("ZELLIJ_SESSION_NAME").ok();
}
InputMode::Session => {
keybinds.push(("d".to_string(), "Detach".to_string()));
}
}
ModeInfo { ModeInfo {
mode, mode,
keybinds, keybinds,
palette, palette,
capabilities, capabilities,
session_name,
} }
} }