diff options
author | a-kenji <aks.kenji@protonmail.com> | 2021-08-26 15:06:59 +0200 |
---|---|---|
committer | a-kenji <aks.kenji@protonmail.com> | 2021-08-26 15:06:59 +0200 |
commit | cd0b0119a022926e659d941f3013b618164e6881 (patch) | |
tree | 10575129e6ff3c9da604f8fe622511cbb9987a43 | |
parent | 06e3be6205bdde46b01f21d95180fcb641e42816 (diff) |
Split tab-layout into `template` & `tabs` section
* adjust example layouts and move them from `./example` to
`./example/layouts`
* simplify the deserialization of the layout
* layouts are now constructed as follows:
```
---
template:
direction: Horizontal
parts:
- direction: Vertical
borderless: true
split_size:
Fixed: 1
run:
plugin: tab-bar
- direction: Vertical
body: true # <== The body section specifies the position of the
# inserted tab
- direction: Vertical
borderless: true
split_size:
Fixed: 2
run:
plugin: status-bar
tabs:
- direction: Vertical
- direction: Vertical
```
19 files changed, 507 insertions, 613 deletions
diff --git a/example/layouts/multiple_tabs_layout.yaml b/example/layouts/multiple_tabs_layout.yaml new file mode 100644 index 000000000..cba76b88d --- /dev/null +++ b/example/layouts/multiple_tabs_layout.yaml @@ -0,0 +1,87 @@ +--- +template: + direction: Horizontal + parts: + - direction: Vertical + split_size: + Fixed: 1 + run: + plugin: tab-bar + borderless: true + - direction: Vertical + body: true + - direction: Vertical + split_size: + Fixed: 2 + run: + plugin: status-bar + borderless: true + +tabs: +- direction: Vertical + parts: + - direction: Vertical + split_size: + Percent: 50 + - direction: Vertical + split_size: + Percent: 50 +- direction: Vertical +- direction: Vertical + parts: + - direction: Vertical + split_size: + Percent: 50 + - direction: Vertical + split_size: + Percent: 50 +- direction: Vertical + parts: + - direction: Vertical + split_size: + Percent: 50 + - direction: Horizontal + split_size: + Percent: 50 + parts: + - direction: Vertical + split_size: + Percent: 50 + - direction: Vertical + split_size: + Percent: 50 +- direction: Vertical +- direction: Vertical +- direction: Vertical +- direction: Vertical + parts: + - direction: Vertical + split_size: + Percent: 20 + run: + plugin: strider + - direction: Horizontal + split_size: + Percent: 80 + parts: + - direction: Vertical + split_size: + Percent: 50 + - direction: Vertical + split_size: + Percent: 50 +- direction: Vertical + parts: + - direction: Vertical + split_size: + Percent: 40 + - direction: Horizontal + split_size: + Percent: 60 + parts: + - direction: Vertical + split_size: + Percent: 50 + - direction: Vertical + split_size: + Percent: 50 diff --git a/example/layouts/multiple_tabs_layout_htop_command.yaml b/example/layouts/multiple_tabs_layout_htop_command.yaml new file mode 100644 index 000000000..13901c130 --- /dev/null +++ b/example/layouts/multiple_tabs_layout_htop_command.yaml @@ -0,0 +1,90 @@ +--- +template: + direction: Horizontal + parts: + - direction: Vertical + split_size: + Fixed: 1 + run: + plugin: tab-bar + borderless: true + - direction: Vertical + body: true + - direction: Vertical + split_size: + Fixed: 2 + run: + plugin: status-bar + borderless: true + +tabs: +- direction: Vertical + parts: + - direction: Vertical + split_size: + Percent: 50 + run: + command: {cmd: htop} + - direction: Vertical + split_size: + Percent: 50 +- direction: Vertical + parts: + - direction: Vertical + split_size: + Percent: 50 + - direction: Vertical + split_size: + Percent: 50 +- direction: Vertical + parts: + - direction: Vertical + split_size: + Percent: 50 + - direction: Horizontal + split_size: + Percent: 50 + parts: + - direction: Vertical + split_size: + Percent: 50 + - direction: Vertical + split_size: + Percent: 50 +- direction: Vertical +- direction: Vertical + run: + command: {cmd: htop, args: ["-C"]} +- direction: Vertical +- direction: Vertical + parts: + - direction: Vertical + split_size: + Percent: 20 + run: + plugin: strider + - direction: Horizontal + split_size: + Percent: 80 + parts: + - direction: Vertical + split_size: + Percent: 50 + - direction: Vertical + split_size: + Percent: 50 +- direction: Vertical + parts: + - direction: Vertical + split_size: + Percent: 40 + - direction: Horizontal + split_size: + Percent: 60 + parts: + - direction: Vertical + split_size: + Percent: 50 + - direction: Vertical + split_size: + Percent: 50 diff --git a/example/layouts/run_htop_layout.yaml b/example/layouts/run_htop_layout.yaml new file mode 100644 index 000000000..91f4f63cb --- /dev/null +++ b/example/layouts/run_htop_layout.yaml @@ -0,0 +1,21 @@ +--- +tabs: + - direction: Vertical + parts: + - direction: Horizontal + split_size: + Percent: 50 + parts: + - direction: Vertical + split_size: + Percent: 50 + - direction: Vertical + split_size: + Percent: 50 + run: + command: {cmd: htop} + - direction: Horizontal + split_size: + Percent: 50 + run: + command: {cmd: htop} diff --git a/example/layouts/run_htop_layout_with_plugins.yaml b/example/layouts/run_htop_layout_with_plugins.yaml new file mode 100644 index 000000000..2868cba52 --- /dev/null +++ b/example/layouts/run_htop_layout_with_plugins.yaml @@ -0,0 +1,33 @@ +--- +tabs: + - direction: Horizontal + parts: + - direction: Vertical + split_size: + Fixed: 1 + run: + plugin: tab-bar + borderless: true + - direction: Vertical + parts: + - direction: Vertical + parts: + - direction: Vertical + split_size: + Percent: 50 + run: + command: {cmd: htop} + - direction: Vertical + split_size: + Percent: 50 + run: + command: {cmd: htop, args: ["-C"]} + - direction: Vertical + split_size: + Fixed: 5 + - direction: Vertical + split_size: + Fixed: 2 + run: + plugin: status-bar + borderless: true diff --git a/example/multiple_tabs_layout.yaml b/example/multiple_tabs_layout.yaml deleted file mode 100644 index 6c4d15980..000000000 --- a/example/multiple_tabs_layout.yaml +++ /dev/null @@ -1,82 +0,0 @@ ---- -direction: Horizontal -parts: - - direction: Vertical - split_size: - Fixed: 1 - run: - plugin: tab-bar - - direction: Vertical - tabs: - - direction: Vertical - parts: - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - - direction: Vertical - parts: - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - parts: - - direction: Vertical - split_size: - Percent: 50 - - direction: Horizontal - split_size: - Percent: 50 - parts: - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - - direction: Vertical - - direction: Vertical - - direction: Vertical - parts: - - direction: Vertical - split_size: - Percent: 20 - run: - plugin: strider - - direction: Horizontal - split_size: - Percent: 80 - parts: - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - parts: - - direction: Vertical - split_size: - Percent: 40 - - direction: Horizontal - split_size: - Percent: 60 - parts: - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - split_size: - Fixed: 2 - run: - plugin: status-bar diff --git a/example/multiple_tabs_layout_htop_command.yaml b/example/multiple_tabs_layout_htop_command.yaml deleted file mode 100644 index 6739eba8f..000000000 --- a/example/multiple_tabs_layout_htop_command.yaml +++ /dev/null @@ -1,85 +0,0 @@ ---- -direction: Horizontal -parts: - - direction: Vertical - split_size: - Fixed: 1 - run: - plugin: tab-bar - - direction: Vertical - tabs: - - direction: Vertical - parts: - - direction: Vertical - split_size: - Percent: 50 - run: - command: {cmd: htop} - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - parts: - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - parts: - - direction: Vertical - split_size: - Percent: 50 - - direction: Horizontal - split_size: - Percent: 50 - parts: - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - - direction: Vertical - run: - command: {cmd: htop, args: ["-C"]} - - direction: Vertical - - direction: Vertical - parts: - - direction: Vertical - split_size: - Percent: 20 - run: - plugin: strider - - direction: Horizontal - split_size: - Percent: 80 - parts: - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - parts: - - direction: Vertical - split_size: - Percent: 40 - - direction: Horizontal - split_size: - Percent: 60 - parts: - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - split_size: - Fixed: 2 - run: - plugin: status-bar diff --git a/example/run_htop_layout.yaml b/example/run_htop_layout.yaml deleted file mode 100644 index 949435d69..000000000 --- a/example/run_htop_layout.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -direction: Vertical -parts: - - direction: Horizontal - split_size: - Percent: 50 - parts: - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - split_size: - Percent: 50 - run: - command: {cmd: htop} - - direction: Horizontal - split_size: - Percent: 50 - run: - command: {cmd: htop} diff --git a/example/run_htop_layout_with_plugins.yaml b/example/run_htop_layout_with_plugins.yaml deleted file mode 100644 index 99f72edbe..000000000 --- a/example/run_htop_layout_with_plugins.yaml +++ /dev/null @@ -1,30 +0,0 @@ ---- -direction: Horizontal -parts: - - direction: Vertical - split_size: - Fixed: 1 - run: - plugin: tab-bar - - direction: Vertical - parts: - - direction: Vertical - parts: - - direction: Vertical - split_size: - Percent: 50 - run: - command: {cmd: htop} - - direction: Vertical - split_size: - Percent: 50 - run: - command: {cmd: htop, args: ["-C"]} - - direction: Vertical - split_size: - Fixed: 5 - - direction: Vertical - split_size: - Fixed: 2 - run: - plugin: status-bar diff --git a/nonexistent.yaml b/nonexistent.yaml new file mode 100644 index 000000000..740bde92a --- /dev/null +++ b/nonexistent.yaml @@ -0,0 +1,2 @@ +--- +borderless: false diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs index f74a74ddf..e806ec3bf 100644 --- a/zellij-client/src/lib.rs +++ b/zellij-client/src/lib.rs @@ -14,14 +14,14 @@ use crate::{ command_is_executing::CommandIsExecuting, input_handler::input_loop, os_input_output::ClientOsApi, }; -use zellij_utils::cli::CliArgs; use zellij_utils::{ channels::{self, ChannelWithContext, SenderWithContext}, consts::{SESSION_NAME, ZELLIJ_IPC_PIPE}, errors::{ClientContext, ContextType, ErrorInstruction}, - input::{actions::Action, config::Config, layout::LayoutTemplate, options::Options}, + input::{actions::Action, config::Config, options::Options}, ipc::{ClientAttributes, ClientToServerMsg, ExitReason, ServerToClientMsg}, }; +use zellij_utils::{cli::CliArgs, input::layout::LayoutFromYaml}; /// Instructions related to the client-side application #[derive(Debug, Clone)] @@ -87,7 +87,7 @@ pub fn start_client( opts: CliArgs, config: Config, info: ClientInfo, - layout: Option<LayoutTemplate>, + layout: Option<LayoutFromYaml>, ) { info!("Starting Zellij client!"); let clear_client_terminal_attributes = "\u{1b}[?1l\u{1b}=\u{1b}[r\u{1b}12l\u{1b}[?1000l\u{1b}[?1002l\u{1b}[?1003l\u{1b}[?1005l\u{1b}[?1006l\u{1b}[?12l"; diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index d0b3b5d27..e9848e702 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -36,7 +36,7 @@ use zellij_utils::{ input::{ command::{RunCommand, TerminalAction}, get_mode_info, - layout::LayoutTemplate, + layout::LayoutFromYaml, options::Options, }, ipc::{ClientAttributes, ClientToServerMsg, ExitReason, ServerToClientMsg}, @@ -50,7 +50,7 @@ pub(crate) enum ServerInstruction { ClientAttributes, Box<CliArgs>, Box<Options>, - Option<LayoutTemplate>, + Option<LayoutFromYaml>, ), Render(Option<String>), UnblockInputThread, @@ -245,9 +245,6 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) { if !&layout.tabs.is_empty() { for tab_layout in layout.tabs { spawn_tabs(Some(tab_layout.clone())); - // Spawning tabs in too quick succession might mess up the layout - // TODO: investigate why - thread::sleep(std::time::Duration::from_millis(250)); } } else { spawn_tabs(None); @@ -329,7 +326,7 @@ fn init_session( to_server: SenderWithContext<ServerInstruction>, client_attributes: ClientAttributes, session_state: Arc<RwLock<SessionState>>, - layout: Option<LayoutTemplate>, + layout: Option<LayoutFromYaml>, ) -> SessionMetaData { let (to_screen, screen_receiver): ChannelWithContext<ScreenInstruction> = channels::unbounded(); let to_screen = SenderWithContext::new(to_screen); diff --git a/zellij-server/src/pty.rs b/zellij-server/src/pty.rs index 5c0e4a269..011b45cab 100644 --- a/zellij-server/src/pty.rs +++ b/zellij-server/src/pty.rs @@ -20,7 +20,7 @@ use zellij_utils::{ errors::{get_current_ctx, ContextType, PtyContext}, input::{ command::TerminalAction, - layout::{Layout, LayoutTemplate, Run, TabLayout}, + layout::{Layout, LayoutFromYaml, Run, TabLayout}, }, logging::debug_to_file, }; @@ -60,7 +60,7 @@ pub(crate) struct Pty { task_handles: HashMap<RawFd, JoinHandle<()>>, } -pub(crate) fn pty_thread_main(mut pty: Pty, maybe_layout: Option<LayoutTemplate>) { +pub(crate) fn pty_thread_main(mut pty: Pty, maybe_layout: Option<LayoutFromYaml>) { loop { let (event, mut err_ctx) = pty.bus.recv().expect("failed to receive event on channel"); err_ctx.add_call(ContextType::Pty((&event).into())); @@ -88,8 +88,8 @@ pub(crate) fn pty_thread_main(mut pty: Pty, maybe_layout: Option<LayoutTemplate> } PtyInstruction::NewTab(terminal_action, tab_layout) => { if let Some(layout) = maybe_layout.clone() { - let merged_layout = layout.construct_tab_layout(tab_layout); - pty.spawn_terminals_for_layout(merged_layout, terminal_action.clone()); + let merged_layout = layout.template.insert_tab_layout(tab_layout); + pty.spawn_terminals_for_layout(merged_layout.into(), terminal_action.clone()); } else { let pid = pty.spawn_terminal(terminal_action.clone()); pty.bus diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index 15c964fe2..a3da6abab 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -20,8 +20,6 @@ use std::path::{Path, PathBuf}; use std::vec::Vec; use std::{fs::File, io::prelude::*}; -use super::config::{LayoutMissingTabSectionError, LayoutPartAndTabError}; - #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(crate = "self::serde")] pub enum Direction { @@ -52,8 +50,6 @@ pub struct Layout { pub direction: Direction, #[serde(default)] pub parts: Vec<Layout>, - #[serde(default)] - pub tabs: Vec<TabLayout>, pub split_size: Option<SplitSize>, pub run: Option<Run>, #[serde(default)] @@ -64,9 +60,10 @@ pub struct Layout { // a yaml configuration file #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(crate = "self::serde")] +#[serde(default)] pub struct LayoutFromYaml { - //#[serde(default)] - pub template: LayoutTemplateFromYaml, + #[serde(default)] + pub template: LayoutTemplate, #[serde(default)] pub borderless: bool, #[serde(default)] @@ -84,6 +81,7 @@ impl LayoutFromYaml { let mut layout = String::new(); layout_file.read_to_string(&mut layout)?; let layout: LayoutFromYaml = serde_yaml::from_str(&layout)?; + Ok(layout) } @@ -112,16 +110,6 @@ impl LayoutFromYaml { )) }) } - - pub fn construct_layout_template(&self) -> LayoutTemplate { - let (pre_tab, post_tab) = self.template.split_template().unwrap(); - LayoutTemplate { - pre_tab: pre_tab.into(), - post_tab: Layout::from_vec_template_layout(post_tab), - tabs: self.tabs.clone(), - } - } - // Currently still needed but on nightly // this is already possible: // HashMap<&'static str, Vec<u8>> @@ -162,58 +150,43 @@ impl LayoutFromYaml { // construct the layout #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(crate = "self::serde")] -pub struct LayoutTemplateFromYaml { +pub struct LayoutTemplate { pub direction: Direction, #[serde(default)] pub borderless: bool, #[serde(default)] - pub parts: Vec<LayoutTemplateFromYaml>, + pub parts: Vec<LayoutTemplate>, #[serde(default)] pub body: bool, pub split_size: Option<SplitSize>, pub run: Option<Run>, } -impl LayoutTemplateFromYaml { - // Split the layout into parts that can be reassebled per tab - // returns the layout pre tab and the parts post tab - pub fn split_template( - &self, - ) -> Result<(LayoutTemplateFromYaml, Vec<LayoutTemplateFromYaml>), LayoutPartAndTabError> { - let mut main_layout = self.clone(); - let mut pre_tab_layout = self.clone(); - let mut post_tab_layout = vec![]; - let mut post_tab = false; - - pre_tab_layout.parts.clear(); |