remove Split, OpenFile and MoveFocus from CliArgs

This commit is contained in:
Kunal Mohan 2021-04-29 15:25:55 +05:30
parent 42079f8d04
commit 9110e444b8
5 changed files with 7 additions and 98 deletions

View file

@ -5,18 +5,6 @@ use structopt::StructOpt;
#[derive(StructOpt, Default, Debug, Clone)] #[derive(StructOpt, Default, Debug, Clone)]
#[structopt(name = "zellij")] #[structopt(name = "zellij")]
pub struct CliArgs { pub struct CliArgs {
/// Send "split (direction h == horizontal / v == vertical)" to active zellij session
#[structopt(short, long)]
pub split: Option<char>,
/// Send "move focused pane" to active zellij session
#[structopt(short, long)]
pub move_focus: bool,
/// Send "open file in new pane" to active zellij session
#[structopt(short, long)]
pub open_file: Option<PathBuf>,
/// Maximum panes on screen, caution: opening more panes will close old ones /// Maximum panes on screen, caution: opening more panes will close old ones
#[structopt(long)] #[structopt(long)]
pub max_panes: Option<usize>, pub max_panes: Option<usize>,

View file

@ -341,10 +341,6 @@ impl From<&ClientInstruction> for ClientContext {
/// Stack call representations corresponding to the different types of [`ServerInstruction`]s. /// Stack call representations corresponding to the different types of [`ServerInstruction`]s.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub enum ServerContext { pub enum ServerContext {
OpenFile,
SplitHorizontally,
SplitVertically,
MoveFocus,
NewClient, NewClient,
Action, Action,
Render, Render,
@ -356,10 +352,6 @@ pub enum ServerContext {
impl From<&ServerInstruction> for ServerContext { impl From<&ServerInstruction> for ServerContext {
fn from(server_instruction: &ServerInstruction) -> Self { fn from(server_instruction: &ServerInstruction) -> Self {
match *server_instruction { match *server_instruction {
ServerInstruction::OpenFile(_) => ServerContext::OpenFile,
ServerInstruction::SplitHorizontally => ServerContext::SplitHorizontally,
ServerInstruction::SplitVertically => ServerContext::SplitVertically,
ServerInstruction::MoveFocus => ServerContext::MoveFocus,
ServerInstruction::NewClient(..) => ServerContext::NewClient, ServerInstruction::NewClient(..) => ServerContext::NewClient,
ServerInstruction::Action(_) => ServerContext::Action, ServerInstruction::Action(_) => ServerContext::Action,
ServerInstruction::TerminalResize(_) => ServerContext::TerminalResize, ServerInstruction::TerminalResize(_) => ServerContext::TerminalResize,

View file

@ -112,7 +112,7 @@ impl InputHandler {
Action::SwitchToMode(mode) => { Action::SwitchToMode(mode) => {
self.mode = mode; self.mode = mode;
self.os_input self.os_input
.send_to_server(ServerInstruction::Action(action.clone())); .send_to_server(ServerInstruction::Action(action));
} }
Action::CloseFocus Action::CloseFocus
| Action::NewPane(_) | Action::NewPane(_)

View file

@ -6,7 +6,7 @@ mod server;
use client::{boundaries, layout, panes, start_client, tab}; use client::{boundaries, layout, panes, start_client, tab};
use common::{command_is_executing, errors, os_input_output, pty_bus, screen, utils, wasm_vm}; use common::{command_is_executing, errors, os_input_output, pty_bus, screen, utils, wasm_vm};
use directories_next::ProjectDirs; use directories_next::ProjectDirs;
use server::{start_server, ServerInstruction}; use server::start_server;
use structopt::StructOpt; use structopt::StructOpt;
@ -50,42 +50,11 @@ pub fn main() {
} }
let opts = CliArgs::from_args(); let opts = CliArgs::from_args();
let config = match Config::try_from(&opts) { atomic_create_dir(ZELLIJ_TMP_DIR).unwrap();
Ok(config) => config, atomic_create_dir(ZELLIJ_TMP_LOG_DIR).unwrap();
Err(e) => { let server_os_input = get_server_os_input();
eprintln!("There was an error in the config file:\n{}", e); let os_input = get_client_os_input();
std::process::exit(1); start(Box::new(os_input), opts, Box::new(server_os_input));
}
};
if let Some(split_dir) = opts.split {
match split_dir {
'h' => {
let os_input = get_client_os_input();
os_input.connect_to_server();
os_input.send_to_server(ServerInstruction::SplitHorizontally);
}
'v' => {
let os_input = get_client_os_input();
os_input.connect_to_server();
os_input.send_to_server(ServerInstruction::SplitVertically);
}
_ => {}
};
} else if opts.move_focus {
let os_input = get_client_os_input();
os_input.connect_to_server();
os_input.send_to_server(ServerInstruction::MoveFocus);
} else if let Some(file_to_open) = opts.open_file {
let os_input = get_client_os_input();
os_input.connect_to_server();
os_input.send_to_server(ServerInstruction::OpenFile(file_to_open));
} else {
atomic_create_dir(ZELLIJ_TMP_DIR).unwrap();
atomic_create_dir(ZELLIJ_TMP_LOG_DIR).unwrap();
let server_os_input = get_server_os_input();
let os_input = get_client_os_input();
start(Box::new(os_input), opts, Box::new(server_os_input));
}
} }
/// Start Zellij with the specified [`ClientOsApi`], [`ServerOsApi`] and command-line arguments. /// Start Zellij with the specified [`ClientOsApi`], [`ServerOsApi`] and command-line arguments.

View file

@ -35,10 +35,6 @@ use crate::utils::consts::ZELLIJ_IPC_PIPE;
/// ones sent by client to server /// ones sent by client to server
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub enum ServerInstruction { pub enum ServerInstruction {
OpenFile(PathBuf),
SplitHorizontally,
SplitVertically,
MoveFocus,
TerminalResize(PositionAndSize), TerminalResize(PositionAndSize),
NewClient(PositionAndSize), NewClient(PositionAndSize),
Action(Action), Action(Action),
@ -164,42 +160,6 @@ fn handle_client(
send_server_instructions.send(instruction).unwrap(); send_server_instructions.send(instruction).unwrap();
break; break;
} }
ServerInstruction::OpenFile(file_name) => {
rlocked_sessions
.as_ref()
.unwrap()
.send_pty_instructions
.send(PtyInstruction::SpawnTerminal(Some(file_name)))
.unwrap();
break;
}
ServerInstruction::SplitHorizontally => {
rlocked_sessions
.as_ref()
.unwrap()
.send_pty_instructions
.send(PtyInstruction::SpawnTerminalHorizontally(None))
.unwrap();
break;
}
ServerInstruction::SplitVertically => {
rlocked_sessions
.as_ref()
.unwrap()
.send_pty_instructions
.send(PtyInstruction::SpawnTerminalVertically(None))
.unwrap();
break;
}
ServerInstruction::MoveFocus => {
rlocked_sessions
.as_ref()
.unwrap()
.send_screen_instructions
.send(ScreenInstruction::FocusNextPane)
.unwrap();
break;
}
ServerInstruction::Action(action) => { ServerInstruction::Action(action) => {
route_action(action, rlocked_sessions.as_ref().unwrap()); route_action(action, rlocked_sessions.as_ref().unwrap());
} }