Skip to content

Commit

Permalink
feat(screen): support specifying tab's name in layout (#715)
Browse files Browse the repository at this point in the history
Signed-off-by: Tw <tw19881113@gmail.com>
  • Loading branch information
tw4452852 committed Sep 13, 2021
1 parent 7c959ee commit da2a9b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions zellij-server/src/pty.rs
Expand Up @@ -95,8 +95,28 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: LayoutFromYaml) {
pty.set_active_pane(pane_id);
}
PtyInstruction::NewTab(terminal_action, tab_layout) => {
let tab_name = tab_layout.as_ref().and_then(|layout| {
if layout.name.is_empty() {
None
} else {
Some(layout.name.clone())
}
});

let merged_layout = layout.template.clone().insert_tab_layout(tab_layout);
pty.spawn_terminals_for_layout(merged_layout.into(), terminal_action.clone());

if let Some(tab_name) = tab_name {
// clear current name at first
pty.bus
.senders
.send_to_screen(ScreenInstruction::UpdateTabName(vec![0]))
.unwrap();
pty.bus
.senders
.send_to_screen(ScreenInstruction::UpdateTabName(tab_name.into_bytes()))
.unwrap();
}
}
PtyInstruction::ClosePane(id) => {
pty.close_pane(id);
Expand Down
3 changes: 3 additions & 0 deletions zellij-utils/src/input/layout.rs
Expand Up @@ -224,6 +224,8 @@ pub struct TabLayout {
pub parts: Vec<TabLayout>,
pub split_size: Option<SplitSize>,
pub run: Option<Run>,
#[serde(default)]
pub name: String,
}

impl Layout {
Expand Down Expand Up @@ -427,6 +429,7 @@ impl Default for TabLayout {
parts: vec![],
split_size: None,
run: None,
name: String::new(),
}
}
}
Expand Down

0 comments on commit da2a9b5

Please sign in to comment.