fix: Allow terminal title passthrough even when not drawing pane frames. (#1113)

* fix: Allow terminal title passthrough even when not drawing pane frames.

* Minor formatting fix.

* Handle case where the session name is not set.
This commit is contained in:
Kerfuffle 2022-02-28 09:54:41 -07:00 committed by GitHub
parent c2e06a1a70
commit e2081f2649
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 12 deletions

View file

@ -16,6 +16,7 @@ use zellij_utils::zellij_tile::prelude::{Event, InputMode, Mouse, PaletteColor};
use zellij_utils::{ use zellij_utils::{
channels::SenderWithContext, channels::SenderWithContext,
pane_size::{Dimension, PaneGeom}, pane_size::{Dimension, PaneGeom},
shared::make_terminal_title,
}; };
pub(crate) struct PluginPane { pub(crate) struct PluginPane {
@ -253,6 +254,16 @@ impl Pane for PluginPane {
) -> Option<String> { ) -> Option<String> {
None None
} }
fn render_terminal_title(&mut self, input_mode: InputMode) -> String {
let pane_title = if self.pane_name.is_empty() && input_mode == InputMode::RenamePane {
"Enter name..."
} else if self.pane_name.is_empty() {
&self.pane_title
} else {
&self.pane_name
};
make_terminal_title(pane_title)
}
fn update_name(&mut self, name: &str) { fn update_name(&mut self, name: &str) {
match name { match name {
"\0" => { "\0" => {

View file

@ -17,6 +17,7 @@ use zellij_utils::pane_size::Offset;
use zellij_utils::{ use zellij_utils::{
pane_size::{Dimension, PaneGeom}, pane_size::{Dimension, PaneGeom},
position::Position, position::Position,
shared::make_terminal_title,
vte, vte,
zellij_tile::data::{InputMode, Palette, PaletteColor}, zellij_tile::data::{InputMode, Palette, PaletteColor},
}; };
@ -303,6 +304,16 @@ impl Pane for TerminalPane {
} }
vte_output vte_output
} }
fn render_terminal_title(&mut self, input_mode: InputMode) -> String {
let pane_title = if self.pane_name.is_empty() && input_mode == InputMode::RenamePane {
"Enter name..."
} else if self.pane_name.is_empty() {
self.grid.title.as_deref().unwrap_or(&self.pane_title)
} else {
&self.pane_name
};
make_terminal_title(pane_title)
}
fn update_name(&mut self, name: &str) { fn update_name(&mut self, name: &str) {
match name { match name {
"\0" => { "\0" => {

View file

@ -169,6 +169,7 @@ pub trait Pane {
cursor_color: PaletteColor, cursor_color: PaletteColor,
text_color: PaletteColor, text_color: PaletteColor,
) -> Option<String>; ) -> Option<String>;
fn render_terminal_title(&mut self, _input_mode: InputMode) -> String;
fn update_name(&mut self, name: &str); fn update_name(&mut self, name: &str);
fn pid(&self) -> PaneId; fn pid(&self) -> PaneId;
fn reduce_height(&mut self, percent: f64); fn reduce_height(&mut self, percent: f64);
@ -1225,6 +1226,7 @@ impl Tab {
self.session_is_mirrored, self.session_is_mirrored,
); );
} }
pane_contents_and_ui.render_terminal_title_if_needed(client_id, client_mode);
// this is done for panes that don't have their own cursor (eg. panes of // this is done for panes that don't have their own cursor (eg. panes of
// another user) // another user)
pane_contents_and_ui.render_fake_cursor_if_needed(client_id); pane_contents_and_ui.render_fake_cursor_if_needed(client_id);

View file

@ -2,8 +2,8 @@ use crate::output::CharacterChunk;
use crate::panes::{AnsiCode, CharacterStyles, TerminalCharacter, EMPTY_TERMINAL_CHARACTER}; use crate::panes::{AnsiCode, CharacterStyles, TerminalCharacter, EMPTY_TERMINAL_CHARACTER};
use crate::ui::boundaries::boundary_type; use crate::ui::boundaries::boundary_type;
use crate::ClientId; use crate::ClientId;
use zellij_utils::pane_size::Viewport;
use zellij_utils::zellij_tile::prelude::{client_id_to_colors, Palette, PaletteColor}; use zellij_utils::zellij_tile::prelude::{client_id_to_colors, Palette, PaletteColor};
use zellij_utils::{envs::get_session_name, pane_size::Viewport};
use unicode_width::{UnicodeWidthChar, UnicodeWidthStr}; use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
@ -603,15 +603,6 @@ impl PaneFrame {
character_chunks.push(CharacterChunk::new(boundary_character_right, x, y)); character_chunks.push(CharacterChunk::new(boundary_character_right, x, y));
} }
} }
let vte_output = if self.is_main_client { (character_chunks, None)
Some(format!(
"\u{1b}]0;Zellij ({}) - {}\u{07}",
get_session_name().unwrap(),
self.title
))
} else {
None
};
(character_chunks, vte_output)
} }
} }

View file

@ -8,7 +8,6 @@ use std::collections::HashMap;
use zellij_tile::data::{ use zellij_tile::data::{
client_id_to_colors, single_client_color, InputMode, Palette, PaletteColor, client_id_to_colors, single_client_color, InputMode, Palette, PaletteColor,
}; };
pub struct PaneContentsAndUi<'a> { pub struct PaneContentsAndUi<'a> {
pane: &'a mut Box<dyn Pane>, pane: &'a mut Box<dyn Pane>,
output: &'a mut Output, output: &'a mut Output,
@ -111,6 +110,14 @@ impl<'a> PaneContentsAndUi<'a> {
} }
} }
} }
pub fn render_terminal_title_if_needed(&mut self, client_id: ClientId, client_mode: InputMode) {
if !self.focused_clients.contains(&client_id) {
return;
}
let vte_output = self.pane.render_terminal_title(client_mode);
self.output
.add_post_vte_instruction_to_client(client_id, &vte_output);
}
pub fn render_pane_frame( pub fn render_pane_frame(
&mut self, &mut self,
client_id: ClientId, client_id: ClientId,

View file

@ -2,6 +2,7 @@
use std::{iter, str::from_utf8}; use std::{iter, str::from_utf8};
use crate::envs::get_session_name;
use colorsys::Rgb; use colorsys::Rgb;
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
use std::path::Path; use std::path::Path;
@ -40,6 +41,16 @@ pub fn adjust_to_size(s: &str, rows: usize, columns: usize) -> String {
.join("\n\r") .join("\n\r")
} }
pub fn make_terminal_title(pane_title: &str) -> String {
format!(
"\u{1b}]0;Zellij {}- {}\u{07}",
get_session_name()
.map(|n| format!("({}) ", n))
.unwrap_or_default(),
pane_title,
)
}
// Colors // Colors
pub mod colors { pub mod colors {
pub const WHITE: u8 = 255; pub const WHITE: u8 = 255;