From 4fcf558156dec6cfebd9fc6ba8605594369fded6 Mon Sep 17 00:00:00 2001 From: Lovecraftian Horror Date: Thu, 8 Jul 2021 14:16:25 -0400 Subject: [PATCH 1/5] Display session name within session --- default-plugins/tab-bar/src/line.rs | 11 +++++-- default-plugins/tab-bar/src/main.rs | 1 + zellij-server/src/lib.rs | 5 ++- zellij-server/src/route.rs | 7 ++-- zellij-server/src/screen.rs | 11 +++---- zellij-tile/src/data.rs | 44 +++++++++++++++++++++++++ zellij-utils/src/input/mod.rs | 51 +---------------------------- 7 files changed, 64 insertions(+), 66 deletions(-) diff --git a/default-plugins/tab-bar/src/line.rs b/default-plugins/tab-bar/src/line.rs index cad5b720..3ebeaac3 100644 --- a/default-plugins/tab-bar/src/line.rs +++ b/default-plugins/tab-bar/src/line.rs @@ -144,8 +144,12 @@ fn add_next_tabs_msg( title_bar.push(right_more_message); } -fn tab_line_prefix(palette: Palette) -> LinePart { - let prefix_text = " Zellij ".to_string(); +fn tab_line_prefix(session_name: Option<&str>, palette: Palette) -> LinePart { + 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_styled_text = style!(palette.white, palette.cyan) .bold() @@ -165,6 +169,7 @@ pub fn tab_separator(capabilities: PluginCapabilities) -> &'static str { } pub fn tab_line( + session_name: Option<&str>, mut all_tabs: Vec, active_tab_index: usize, cols: usize, @@ -181,7 +186,7 @@ pub fn tab_line( }; 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( &mut tabs_before_active, &mut tabs_after_active, diff --git a/default-plugins/tab-bar/src/main.rs b/default-plugins/tab-bar/src/main.rs index 1f83dcde..a185ccc3 100644 --- a/default-plugins/tab-bar/src/main.rs +++ b/default-plugins/tab-bar/src/main.rs @@ -64,6 +64,7 @@ impl ZellijPlugin for State { all_tabs.push(tab); } let tab_line = tab_line( + self.mode_info.session_name.as_deref(), all_tabs, active_tab_index, cols, diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index 660acdc9..a15eb4c9 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -15,7 +15,7 @@ use std::path::PathBuf; use std::sync::{Arc, Mutex, RwLock}; use std::thread; use wasmer::Store; -use zellij_tile::data::{Event, Palette, PluginCapabilities}; +use zellij_tile::data::{Event, ModeInfo, Palette, PluginCapabilities}; use crate::{ os_input_output::ServerOsApi, @@ -31,7 +31,6 @@ use zellij_utils::{ errors::{ContextType, ErrorInstruction, ServerContext}, input::{ command::{RunCommand, TerminalAction}, - get_mode_info, layout::Layout, options::Options, }, @@ -235,7 +234,7 @@ pub fn start_server(os_input: Box, socket_path: PathBuf) { .unwrap(); let default_mode = options.default_mode.unwrap_or_default(); let mode_info = - get_mode_info(default_mode, attrs.palette, session_data.capabilities); + ModeInfo::new(default_mode, attrs.palette, session_data.capabilities); session_data .senders .send_to_screen(ScreenInstruction::ChangeMode(mode_info.clone())) diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index 22d843f0..0796ac74 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -1,6 +1,6 @@ use std::sync::{Arc, RwLock}; -use zellij_utils::zellij_tile::data::Event; +use zellij_utils::zellij_tile::data::{Event, ModeInfo}; use crate::{ os_input_output::ServerOsApi, pty::PtyInstruction, screen::ScreenInstruction, @@ -11,7 +11,6 @@ use zellij_utils::{ input::{ actions::{Action, Direction}, command::TerminalAction, - get_mode_info, }, ipc::{ClientToServerMsg, ExitReason, ServerToClientMsg}, }; @@ -43,12 +42,12 @@ fn route_action( .senders .send_to_plugin(PluginInstruction::Update( None, - Event::ModeUpdate(get_mode_info(mode, palette, session.capabilities)), + Event::ModeUpdate(ModeInfo::new(mode, palette, session.capabilities)), )) .unwrap(); session .senders - .send_to_screen(ScreenInstruction::ChangeMode(get_mode_info( + .send_to_screen(ScreenInstruction::ChangeMode(ModeInfo::new( mode, palette, session.capabilities, diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index 9005d795..9f5435de 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -434,14 +434,13 @@ pub(crate) fn screen_thread_main( bus, &client_attributes, max_panes, - ModeInfo { - palette: client_attributes.palette, - capabilities: PluginCapabilities { + ModeInfo::new( + default_mode, + client_attributes.palette, + PluginCapabilities { arrow_fonts: capabilities, }, - mode: default_mode, - ..ModeInfo::default() - }, + ), default_mode, session_state, ); diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs index 4e4b6823..48ef4df9 100644 --- a/zellij-tile/src/data.rs +++ b/zellij-tile/src/data.rs @@ -148,6 +148,50 @@ pub struct ModeInfo { pub keybinds: Vec<(String, String)>, // => pub palette: Palette, pub capabilities: PluginCapabilities, + pub session_name: Option, +} + +impl ModeInfo { + /// Creates a [`ModeInfo`] struct indicating the current [`InputMode`] and its keybinds + /// (as pairs of [`String`]s). + pub fn new(mode: InputMode, palette: Palette, capabilities: PluginCapabilities) -> Self { + let keybinds = match mode { + InputMode::Normal | InputMode::Locked => Vec::new(), + InputMode::Resize => vec![("←↓↑→".to_string(), "Resize".to_string())], + InputMode::Pane => vec![ + ("←↓↑→".to_string(), "Move focus".to_string()), + ("p".to_string(), "Next".to_string()), + ("n".to_string(), "New".to_string()), + ("d".to_string(), "Down split".to_string()), + ("r".to_string(), "Right split".to_string()), + ("x".to_string(), "Close".to_string()), + ("f".to_string(), "Fullscreen".to_string()), + ], + InputMode::Tab => vec![ + ("←↓↑→".to_string(), "Move focus".to_string()), + ("n".to_string(), "New".to_string()), + ("x".to_string(), "Close".to_string()), + ("r".to_string(), "Rename".to_string()), + ("s".to_string(), "Sync".to_string()), + ], + InputMode::Scroll => vec![ + ("↓↑".to_string(), "Scroll".to_string()), + ("PgUp/PgDn".to_string(), "Scroll Page".to_string()), + ], + InputMode::RenameTab => vec![("Enter".to_string(), "when done".to_string())], + InputMode::Session => vec![("d".to_string(), "Detach".to_string())], + }; + + let session_name = std::env::var("ZELLIJ_SESSION_NAME").ok(); + + Self { + mode, + keybinds, + palette, + capabilities, + session_name, + } + } } #[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] diff --git a/zellij-utils/src/input/mod.rs b/zellij-utils/src/input/mod.rs index 11c5a843..e037fe66 100644 --- a/zellij-utils/src/input/mod.rs +++ b/zellij-utils/src/input/mod.rs @@ -10,56 +10,7 @@ pub mod options; pub mod theme; use termion::input::TermRead; -use zellij_tile::data::{InputMode, Key, ModeInfo, Palette, PluginCapabilities}; - -/// Creates a [`Help`] struct indicating the current [`InputMode`] and its keybinds -/// (as pairs of [`String`]s). -// TODO this should probably be automatically generated in some way -pub fn get_mode_info( - mode: InputMode, - palette: Palette, - capabilities: PluginCapabilities, -) -> ModeInfo { - let mut keybinds: Vec<(String, String)> = vec![]; - match mode { - InputMode::Normal | InputMode::Locked => {} - InputMode::Resize => { - keybinds.push(("←↓↑→".to_string(), "Resize".to_string())); - } - InputMode::Pane => { - keybinds.push(("←↓↑→".to_string(), "Move focus".to_string())); - keybinds.push(("p".to_string(), "Next".to_string())); - keybinds.push(("n".to_string(), "New".to_string())); - keybinds.push(("d".to_string(), "Down split".to_string())); - keybinds.push(("r".to_string(), "Right split".to_string())); - keybinds.push(("x".to_string(), "Close".to_string())); - keybinds.push(("f".to_string(), "Fullscreen".to_string())); - } - InputMode::Tab => { - keybinds.push(("←↓↑→".to_string(), "Move focus".to_string())); - keybinds.push(("n".to_string(), "New".to_string())); - keybinds.push(("x".to_string(), "Close".to_string())); - keybinds.push(("r".to_string(), "Rename".to_string())); - keybinds.push(("s".to_string(), "Sync".to_string())); - } - InputMode::Scroll => { - keybinds.push(("↓↑".to_string(), "Scroll".to_string())); - keybinds.push(("PgUp/PgDn".to_string(), "Scroll Page".to_string())); - } - InputMode::RenameTab => { - keybinds.push(("Enter".to_string(), "when done".to_string())); - } - InputMode::Session => { - keybinds.push(("d".to_string(), "Detach".to_string())); - } - } - ModeInfo { - mode, - keybinds, - palette, - capabilities, - } -} +use zellij_tile::data::Key; pub fn parse_keys(input_bytes: &[u8]) -> Vec { input_bytes.keys().flatten().map(cast_termion_key).collect() From eb6e49c260be568800e76fd3276fc96ad909d4eb Mon Sep 17 00:00:00 2001 From: Lovecraftian Horror Date: Fri, 9 Jul 2021 15:21:47 -0400 Subject: [PATCH 2/5] Move `ModeInfo::new()` back to `get_mode_info()` --- zellij-server/src/lib.rs | 5 ++-- zellij-server/src/route.rs | 7 +++--- zellij-server/src/screen.rs | 4 +-- zellij-tile/src/data.rs | 43 -------------------------------- zellij-utils/src/input/mod.rs | 47 ++++++++++++++++++++++++++++++++++- 5 files changed, 55 insertions(+), 51 deletions(-) diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index a15eb4c9..660acdc9 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -15,7 +15,7 @@ use std::path::PathBuf; use std::sync::{Arc, Mutex, RwLock}; use std::thread; use wasmer::Store; -use zellij_tile::data::{Event, ModeInfo, Palette, PluginCapabilities}; +use zellij_tile::data::{Event, Palette, PluginCapabilities}; use crate::{ os_input_output::ServerOsApi, @@ -31,6 +31,7 @@ use zellij_utils::{ errors::{ContextType, ErrorInstruction, ServerContext}, input::{ command::{RunCommand, TerminalAction}, + get_mode_info, layout::Layout, options::Options, }, @@ -234,7 +235,7 @@ pub fn start_server(os_input: Box, socket_path: PathBuf) { .unwrap(); let default_mode = options.default_mode.unwrap_or_default(); let mode_info = - ModeInfo::new(default_mode, attrs.palette, session_data.capabilities); + get_mode_info(default_mode, attrs.palette, session_data.capabilities); session_data .senders .send_to_screen(ScreenInstruction::ChangeMode(mode_info.clone())) diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index 0796ac74..22d843f0 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -1,6 +1,6 @@ use std::sync::{Arc, RwLock}; -use zellij_utils::zellij_tile::data::{Event, ModeInfo}; +use zellij_utils::zellij_tile::data::Event; use crate::{ os_input_output::ServerOsApi, pty::PtyInstruction, screen::ScreenInstruction, @@ -11,6 +11,7 @@ use zellij_utils::{ input::{ actions::{Action, Direction}, command::TerminalAction, + get_mode_info, }, ipc::{ClientToServerMsg, ExitReason, ServerToClientMsg}, }; @@ -42,12 +43,12 @@ fn route_action( .senders .send_to_plugin(PluginInstruction::Update( None, - Event::ModeUpdate(ModeInfo::new(mode, palette, session.capabilities)), + Event::ModeUpdate(get_mode_info(mode, palette, session.capabilities)), )) .unwrap(); session .senders - .send_to_screen(ScreenInstruction::ChangeMode(ModeInfo::new( + .send_to_screen(ScreenInstruction::ChangeMode(get_mode_info( mode, palette, session.capabilities, diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index 9f5435de..9400599c 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -18,7 +18,7 @@ use crate::{ use zellij_tile::data::{Event, InputMode, ModeInfo, Palette, PluginCapabilities, TabInfo}; use zellij_utils::{ errors::{ContextType, ScreenContext}, - input::options::Options, + input::{get_mode_info, options::Options}, ipc::ClientAttributes, pane_size::PositionAndSize, }; @@ -434,7 +434,7 @@ pub(crate) fn screen_thread_main( bus, &client_attributes, max_panes, - ModeInfo::new( + get_mode_info( default_mode, client_attributes.palette, PluginCapabilities { diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs index 48ef4df9..cdf57e69 100644 --- a/zellij-tile/src/data.rs +++ b/zellij-tile/src/data.rs @@ -151,49 +151,6 @@ pub struct ModeInfo { pub session_name: Option, } -impl ModeInfo { - /// Creates a [`ModeInfo`] struct indicating the current [`InputMode`] and its keybinds - /// (as pairs of [`String`]s). - pub fn new(mode: InputMode, palette: Palette, capabilities: PluginCapabilities) -> Self { - let keybinds = match mode { - InputMode::Normal | InputMode::Locked => Vec::new(), - InputMode::Resize => vec![("←↓↑→".to_string(), "Resize".to_string())], - InputMode::Pane => vec![ - ("←↓↑→".to_string(), "Move focus".to_string()), - ("p".to_string(), "Next".to_string()), - ("n".to_string(), "New".to_string()), - ("d".to_string(), "Down split".to_string()), - ("r".to_string(), "Right split".to_string()), - ("x".to_string(), "Close".to_string()), - ("f".to_string(), "Fullscreen".to_string()), - ], - InputMode::Tab => vec![ - ("←↓↑→".to_string(), "Move focus".to_string()), - ("n".to_string(), "New".to_string()), - ("x".to_string(), "Close".to_string()), - ("r".to_string(), "Rename".to_string()), - ("s".to_string(), "Sync".to_string()), - ], - InputMode::Scroll => vec![ - ("↓↑".to_string(), "Scroll".to_string()), - ("PgUp/PgDn".to_string(), "Scroll Page".to_string()), - ], - InputMode::RenameTab => vec![("Enter".to_string(), "when done".to_string())], - InputMode::Session => vec![("d".to_string(), "Detach".to_string())], - }; - - let session_name = std::env::var("ZELLIJ_SESSION_NAME").ok(); - - Self { - mode, - keybinds, - palette, - capabilities, - session_name, - } - } -} - #[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct TabInfo { /* subset of fields to publish to plugins */ diff --git a/zellij-utils/src/input/mod.rs b/zellij-utils/src/input/mod.rs index e037fe66..746d5861 100644 --- a/zellij-utils/src/input/mod.rs +++ b/zellij-utils/src/input/mod.rs @@ -10,7 +10,52 @@ pub mod options; pub mod theme; use termion::input::TermRead; -use zellij_tile::data::Key; +use zellij_tile::data::{InputMode, Key, ModeInfo, Palette, PluginCapabilities}; + +/// Creates a [`ModeInfo`] struct indicating the current [`InputMode`] and its keybinds +/// (as pairs of [`String`]s). +pub fn get_mode_info( + mode: InputMode, + palette: Palette, + capabilities: PluginCapabilities, +) -> ModeInfo { + let keybinds = match mode { + InputMode::Normal | InputMode::Locked => Vec::new(), + InputMode::Resize => vec![("←↓↑→".to_string(), "Resize".to_string())], + InputMode::Pane => vec![ + ("←↓↑→".to_string(), "Move focus".to_string()), + ("p".to_string(), "Next".to_string()), + ("n".to_string(), "New".to_string()), + ("d".to_string(), "Down split".to_string()), + ("r".to_string(), "Right split".to_string()), + ("x".to_string(), "Close".to_string()), + ("f".to_string(), "Fullscreen".to_string()), + ], + InputMode::Tab => vec![ + ("←↓↑→".to_string(), "Move focus".to_string()), + ("n".to_string(), "New".to_string()), + ("x".to_string(), "Close".to_string()), + ("r".to_string(), "Rename".to_string()), + ("s".to_string(), "Sync".to_string()), + ], + InputMode::Scroll => vec![ + ("↓↑".to_string(), "Scroll".to_string()), + ("PgUp/PgDn".to_string(), "Scroll Page".to_string()), + ], + InputMode::RenameTab => vec![("Enter".to_string(), "when done".to_string())], + InputMode::Session => vec![("d".to_string(), "Detach".to_string())], + }; + + let session_name = std::env::var("ZELLIJ_SESSION_NAME").ok(); + + ModeInfo { + mode, + keybinds, + palette, + capabilities, + session_name, + } +} pub fn parse_keys(input_bytes: &[u8]) -> Vec { input_bytes.keys().flatten().map(cast_termion_key).collect() From b25842a563215bada9844367011fe147407c73d8 Mon Sep 17 00:00:00 2001 From: Lovecraftian Horror Date: Fri, 9 Jul 2021 15:45:39 -0400 Subject: [PATCH 3/5] Display just session name with tab names --- default-plugins/tab-bar/src/line.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/default-plugins/tab-bar/src/line.rs b/default-plugins/tab-bar/src/line.rs index 3ebeaac3..fbd9cba0 100644 --- a/default-plugins/tab-bar/src/line.rs +++ b/default-plugins/tab-bar/src/line.rs @@ -145,10 +145,8 @@ fn add_next_tabs_msg( } fn tab_line_prefix(session_name: Option<&str>, palette: Palette) -> LinePart { - let mut prefix_text = " Zellij ".to_string(); - if let Some(name) = session_name { - prefix_text.push_str(&format!("({}) ", name)); - } + let session_name = session_name.unwrap_or("Zellij"); + let prefix_text = format!(" {} ", session_name); let prefix_text_len = prefix_text.chars().count(); let prefix_styled_text = style!(palette.white, palette.cyan) From c5a25f267fdc42ff66a5de6f75720150985b0dce Mon Sep 17 00:00:00 2001 From: Lovecraftian Horror Date: Tue, 20 Jul 2021 13:14:13 -0400 Subject: [PATCH 4/5] Revert "Display just session name with tab names" This reverts commit b25842a563215bada9844367011fe147407c73d8. --- default-plugins/tab-bar/src/line.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/default-plugins/tab-bar/src/line.rs b/default-plugins/tab-bar/src/line.rs index fbd9cba0..3ebeaac3 100644 --- a/default-plugins/tab-bar/src/line.rs +++ b/default-plugins/tab-bar/src/line.rs @@ -145,8 +145,10 @@ fn add_next_tabs_msg( } fn tab_line_prefix(session_name: Option<&str>, palette: Palette) -> LinePart { - let session_name = session_name.unwrap_or("Zellij"); - let prefix_text = format!(" {} ", session_name); + 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_styled_text = style!(palette.white, palette.cyan) From c42b0f867e0300c86243ab709d8d3620e362964b Mon Sep 17 00:00:00 2001 From: a-kenji Date: Thu, 22 Jul 2021 16:30:06 +0200 Subject: [PATCH 5/5] fixup! merge * Missed something while merging --- zellij-server/src/screen.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index e265e8c5..86ecd688 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -429,7 +429,7 @@ pub(crate) fn screen_thread_main( &client_attributes, max_panes, get_mode_info( - default_mode, + config_options.default_mode.unwrap_or_default(), client_attributes.palette, PluginCapabilities { arrow_fonts: capabilities,