summaryrefslogtreecommitdiffstats
path: root/zellij-server/src/lib.rs
diff options
context:
space:
mode:
authora-kenji <aks.kenji@protonmail.com>2021-07-09 23:37:36 +0200
committera-kenji <aks.kenji@protonmail.com>2021-07-23 17:13:35 +0200
commit5ede25dc37ceb192032524ac9200bb1ca95e5863 (patch)
tree1b2a19f3110ca12ec8705dcb0c07502746c06ff5 /zellij-server/src/lib.rs
parent3df0210647e65170576f1ea97328cce26c211a43 (diff)
Add `tabs` to `layouts`
fixes #603, fixes #349 * The layout has now a unique `tabs` section, that can be used, like the `parts` section, everything that is not inside the tabs section is assumed to be present on every single tab that is opened. This is a BREAKING CHANGE for people that use custom `layouts` already, since the `tabs` section is not optional - for clarity and intentionality reasons. The functionality to specify multiple tabs is already there, but is still gated behind a panic, until #621 is fixed. So for now one tab can be specified to load on startup. * The `NewTab` action can optionally be bound to open a layout that is assumed to be in the new `tabs` section This is a BREAKING CHANGE for people that have the `NewTab` action already bound in the config file: ``` - action: [NewTab, ] key: [F: 5,] ``` must now be specified as: ``` - action: [NewTab: ,] key: [F: 5,] ``` Optionally a layout that should be opened on the new tab can be specified: ``` - action: [NewTab: { direction: Vertical, parts: [ {direction: Horizontal, split_size: {Percent: 50}}, {direction: Horizontal, run: {command: {cmd: "htop"}}},], key: [F: 6,] ``` or: ``` - action: [NewTab: {direction: Vertical, run: {command: {cmd: "htop"} }},] key: [F: 7,] ``` or ``` - action: [NewTab: { direction: Vertical, parts: [ {direction: Vertical, split_size: {Percent: 25},run: {plugin: "strider" }}, {direction: Horizontal}],}, MoveFocus: Left,] key: [F: 8,] ```
Diffstat (limited to 'zellij-server/src/lib.rs')
-rw-r--r--zellij-server/src/lib.rs60
1 files changed, 43 insertions, 17 deletions
diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs
index 660acdc95..2dfe6de75 100644
--- a/zellij-server/src/lib.rs
+++ b/zellij-server/src/lib.rs
@@ -9,11 +9,11 @@ mod thread_bus;
mod ui;
mod wasm_vm;
-use zellij_utils::zellij_tile;
-
-use std::path::PathBuf;
-use std::sync::{Arc, Mutex, RwLock};
-use std::thread;
+use std::{
+ path::PathBuf,
+ sync::{Arc, Mutex, RwLock},
+ thread,
+};
use wasmer::Store;
use zellij_tile::data::{Event, Palette, PluginCapabilities};
@@ -32,17 +32,23 @@ use zellij_utils::{
input::{
command::{RunCommand, TerminalAction},
get_mode_info,
- layout::Layout,
+ layout::MainLayout,
options::Options,
},
ipc::{ClientAttributes, ClientToServerMsg, ExitReason, ServerToClientMsg},
setup::get_default_data_dir,
+ zellij_tile,
};
/// Instructions related to server-side application
#[derive(Debug, Clone)]
pub(crate) enum ServerInstruction {
- NewClient(ClientAttributes, Box<CliArgs>, Box<Options>, Option<Layout>),
+ NewClient(
+ ClientAttributes,
+ Box<CliArgs>,
+ Box<Options>,
+ Option<MainLayout>,
+ ),
Render(Option<String>),
UnblockInputThread,
ClientExit,
@@ -204,7 +210,7 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
to_server.clone(),
client_attributes,
session_state.clone(),
- layout,
+ layout.clone(),
);
*session_data.write().unwrap() = Some(session);
*session_state.write().unwrap() = SessionState::Attached;
@@ -216,14 +222,34 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
})
});
- session_data
- .read()
- .unwrap()
- .as_ref()
- .unwrap()
- .senders
- .send_to_pty(PtyInstruction::NewTab(default_shell.clone()))
- .unwrap();
+ let spawn_tabs = |tab_layout| {
+ session_data
+ .read()
+ .unwrap()
+ .as_ref()
+ .unwrap()
+ .senders
+ .send_to_pty(PtyInstruction::NewTab(default_shell.clone(), tab_layout))
+ .unwrap()
+ };
+
+ match layout {
+ None => {
+ spawn_tabs(None);
+ }
+ Some(layout) => {
+ 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);
+ }
+ }
+ }
}
ServerInstruction::AttachClient(attrs, _, options) => {
*session_state.write().unwrap() = SessionState::Attached;
@@ -299,7 +325,7 @@ fn init_session(
to_server: SenderWithContext<ServerInstruction>,
client_attributes: ClientAttributes,
session_state: Arc<RwLock<SessionState>>,
- layout: Option<Layout>,
+ layout: Option<MainLayout>,
) -> SessionMetaData {
let (to_screen, screen_receiver): ChannelWithContext<ScreenInstruction> = channels::unbounded();
let to_screen = SenderWithContext::new(to_screen);