Merge pull request #549 from a-kenji/default-mode-attach

Add default_mode to attach
This commit is contained in:
a-kenji 2021-05-29 20:53:32 +02:00 committed by GitHub
commit 80bd53b8f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 12 deletions

View File

@ -13,6 +13,7 @@ use zellij_utils::{
cli::{CliArgs, Command, Sessions}, cli::{CliArgs, Command, Sessions},
consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR}, consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR},
input::config::Config, input::config::Config,
input::options::Options,
logging::*, logging::*,
setup::{get_default_data_dir, Setup}, setup::{get_default_data_dir, Setup},
structopt::StructOpt, structopt::StructOpt,
@ -63,11 +64,14 @@ pub fn main() {
} else { } else {
session_name = Some(get_active_session()); session_name = Some(get_active_session());
} }
let config_options = Options::from_cli(&config.options, opts.command.clone());
start_client( start_client(
Box::new(os_input), Box::new(os_input),
opts, opts,
config, config,
ClientInfo::Attach(session_name.unwrap(), force), ClientInfo::Attach(session_name.unwrap(), force, config_options),
); );
} else { } else {
let session_name = opts let session_name = opts

View File

@ -77,7 +77,7 @@ fn spawn_server(socket_path: &Path) -> io::Result<()> {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum ClientInfo { pub enum ClientInfo {
Attach(String, bool), Attach(String, bool, Options),
New(String), New(String),
} }
@ -112,11 +112,11 @@ pub fn start_client(
#[cfg(not(any(feature = "test", test)))] #[cfg(not(any(feature = "test", test)))]
let first_msg = match info { let first_msg = match info {
ClientInfo::Attach(name, force) => { ClientInfo::Attach(name, force, config_options) => {
SESSION_NAME.set(name).unwrap(); SESSION_NAME.set(name).unwrap();
std::env::set_var(&"ZELLIJ_SESSION_NAME", SESSION_NAME.get().unwrap()); std::env::set_var(&"ZELLIJ_SESSION_NAME", SESSION_NAME.get().unwrap());
ClientToServerMsg::AttachClient(client_attributes, force) ClientToServerMsg::AttachClient(client_attributes, force, config_options)
} }
ClientInfo::New(name) => { ClientInfo::New(name) => {
SESSION_NAME.set(name).unwrap(); SESSION_NAME.set(name).unwrap();

View File

@ -15,7 +15,7 @@ use std::path::PathBuf;
use std::sync::{Arc, Mutex, RwLock}; use std::sync::{Arc, Mutex, RwLock};
use std::thread; use std::thread;
use wasmer::Store; use wasmer::Store;
use zellij_tile::data::{Event, InputMode, PluginCapabilities}; use zellij_tile::data::{Event, PluginCapabilities};
use crate::{ use crate::{
os_input_output::ServerOsApi, os_input_output::ServerOsApi,
@ -44,7 +44,7 @@ pub(crate) enum ServerInstruction {
ClientExit, ClientExit,
Error(String), Error(String),
DetachSession, DetachSession,
AttachClient(ClientAttributes, bool), AttachClient(ClientAttributes, bool, Options),
} }
impl From<ClientToServerMsg> for ServerInstruction { impl From<ClientToServerMsg> for ServerInstruction {
@ -53,8 +53,8 @@ impl From<ClientToServerMsg> for ServerInstruction {
ClientToServerMsg::NewClient(attrs, opts, options) => { ClientToServerMsg::NewClient(attrs, opts, options) => {
ServerInstruction::NewClient(attrs, opts, options) ServerInstruction::NewClient(attrs, opts, options)
} }
ClientToServerMsg::AttachClient(attrs, force) => { ClientToServerMsg::AttachClient(attrs, force, options) => {
ServerInstruction::AttachClient(attrs, force) ServerInstruction::AttachClient(attrs, force, options)
} }
_ => unreachable!(), _ => unreachable!(),
} }
@ -225,7 +225,7 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
.send_to_pty(PtyInstruction::NewTab) .send_to_pty(PtyInstruction::NewTab)
.unwrap(); .unwrap();
} }
ServerInstruction::AttachClient(attrs, _) => { ServerInstruction::AttachClient(attrs, _, options) => {
*session_state.write().unwrap() = SessionState::Attached; *session_state.write().unwrap() = SessionState::Attached;
let rlock = session_data.read().unwrap(); let rlock = session_data.read().unwrap();
let session_data = rlock.as_ref().unwrap(); let session_data = rlock.as_ref().unwrap();
@ -233,8 +233,9 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
.senders .senders
.send_to_screen(ScreenInstruction::TerminalResize(attrs.position_and_size)) .send_to_screen(ScreenInstruction::TerminalResize(attrs.position_and_size))
.unwrap(); .unwrap();
let default_mode = options.default_mode.unwrap_or_default();
let mode_info = let mode_info =
get_mode_info(InputMode::Normal, attrs.palette, session_data.capabilities); get_mode_info(default_mode, attrs.palette, session_data.capabilities);
session_data session_data
.senders .senders
.send_to_screen(ScreenInstruction::ChangeMode(mode_info.clone())) .send_to_screen(ScreenInstruction::ChangeMode(mode_info.clone()))

View File

@ -238,7 +238,7 @@ pub(crate) fn route_thread_main(
to_server.send(instruction.into()).unwrap(); to_server.send(instruction.into()).unwrap();
} }
} }
ClientToServerMsg::AttachClient(_, force) => { ClientToServerMsg::AttachClient(_, force, _) => {
if *session_state.read().unwrap() == SessionState::Attached && !force { if *session_state.read().unwrap() == SessionState::Attached && !force {
os_input.send_to_temp_client(ServerToClientMsg::Exit(ExitReason::CannotAttach)); os_input.send_to_temp_client(ServerToClientMsg::Exit(ExitReason::CannotAttach));
} else { } else {

View File

@ -57,7 +57,7 @@ pub enum ClientToServerMsg {
DisconnectFromSession,*/ DisconnectFromSession,*/
TerminalResize(PositionAndSize), TerminalResize(PositionAndSize),
NewClient(ClientAttributes, Box<CliArgs>, Box<Options>), NewClient(ClientAttributes, Box<CliArgs>, Box<Options>),
AttachClient(ClientAttributes, bool), AttachClient(ClientAttributes, bool, Options),
Action(Action), Action(Action),
ClientExited, ClientExited,
} }