feat(screen): support specifying tab's name in layout (#715)

Signed-off-by: Tw <tw19881113@gmail.com>
This commit is contained in:
Tw 2021-09-13 17:56:33 +08:00 committed by GitHub
parent 7c959ee3a2
commit da2a9b5c18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -95,8 +95,28 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: LayoutFromYaml) {
pty.set_active_pane(pane_id); pty.set_active_pane(pane_id);
} }
PtyInstruction::NewTab(terminal_action, tab_layout) => { 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); let merged_layout = layout.template.clone().insert_tab_layout(tab_layout);
pty.spawn_terminals_for_layout(merged_layout.into(), terminal_action.clone()); 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) => { PtyInstruction::ClosePane(id) => {
pty.close_pane(id); pty.close_pane(id);

View File

@ -224,6 +224,8 @@ pub struct TabLayout {
pub parts: Vec<TabLayout>, pub parts: Vec<TabLayout>,
pub split_size: Option<SplitSize>, pub split_size: Option<SplitSize>,
pub run: Option<Run>, pub run: Option<Run>,
#[serde(default)]
pub name: String,
} }
impl Layout { impl Layout {
@ -427,6 +429,7 @@ impl Default for TabLayout {
parts: vec![], parts: vec![],
split_size: None, split_size: None,
run: None, run: None,
name: String::new(),
} }
} }
} }