Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Parsing Implemented

* Functionality itself works now, but
the plugin doesn't show the active
mode untill a manual refresh
  • Loading branch information
a-kenji committed May 15, 2021
1 parent f1bff23 commit 909035f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::common::{
thread_bus::{SenderType, SenderWithContext, SyncChannelWithContext},
};
use crate::server::ServerInstruction;
use zellij_tile::data::InputMode;

/// Instructions related to the client-side application and sent from server to client
#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -54,7 +55,7 @@ pub fn start_client(mut os_input: Box<dyn ClientOsApi>, opts: CliArgs, config: C
os_input.send_to_server(ServerInstruction::NewClient(
full_screen_ws,
opts,
config_options,
config_options.clone(),
));
os_input.set_raw_mode(0);
let _ = os_input
Expand Down Expand Up @@ -83,12 +84,14 @@ pub fn start_client(mut os_input: Box<dyn ClientOsApi>, opts: CliArgs, config: C
let send_client_instructions = send_client_instructions.clone();
let command_is_executing = command_is_executing.clone();
let os_input = os_input.clone();
let default_mode = config_options.default_mode.unwrap_or(InputMode::Normal);
move || {
input_loop(
os_input,
config,
command_is_executing,
send_client_instructions,
default_mode,
)
}
});
Expand Down
5 changes: 4 additions & 1 deletion src/common/input/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ impl InputHandler {
command_is_executing: CommandIsExecuting,
config: Config,
send_client_instructions: SenderWithContext<ClientInstruction>,
mode: InputMode,
) -> Self {
InputHandler {
mode: InputMode::Normal,
mode,
os_input,
config,
command_is_executing,
Expand Down Expand Up @@ -225,12 +226,14 @@ pub fn input_loop(
config: Config,
command_is_executing: CommandIsExecuting,
send_client_instructions: SenderWithContext<ClientInstruction>,
default_mode: InputMode,
) {
let _handler = InputHandler::new(
os_input,
command_is_executing,
config,
send_client_instructions,
default_mode,
)
.handle_input();
}
Expand Down
14 changes: 13 additions & 1 deletion src/common/input/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::cli::ConfigCli;
use serde::{Deserialize, Serialize};
use structopt::StructOpt;
use zellij_tile::data::InputMode;

#[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize, StructOpt)]
/// Options that can be set either through the config file,
Expand All @@ -11,6 +12,9 @@ pub struct Options {
/// that is compatible with more fonts
#[structopt(long)]
pub simplified_ui: bool,
/// Allows to specify the default mode
#[structopt(long)]
pub default_mode: Option<InputMode>,
}

impl Options {
Expand All @@ -32,7 +36,15 @@ impl Options {
self.simplified_ui
};

Options { simplified_ui }
let default_mode = match other.default_mode {
None => self.default_mode,
other => other,
};

Options {
simplified_ui,
default_mode,
}
}

pub fn from_cli(&self, other: Option<ConfigCli>) -> Options {
Expand Down
18 changes: 18 additions & 0 deletions zellij-tile/src/data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
use std::str::FromStr;
use strum_macros::{EnumDiscriminants, EnumIter, EnumString, ToString};

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
Expand Down Expand Up @@ -89,6 +90,23 @@ impl Default for PaletteColor {
}
}

impl FromStr for InputMode {
type Err = Box<dyn std::error::Error>;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"normal" => Ok(InputMode::Normal),
"resize" => Ok(InputMode::Resize),
"locked" => Ok(InputMode::Locked),
"pane" => Ok(InputMode::Pane),
"tab" => Ok(InputMode::Tab),
"scroll" => Ok(InputMode::Scroll),
"renametab" => Ok(InputMode::RenameTab),
e => Err(e.to_string().into()),
}
}
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum PaletteSource {
Default,
Expand Down

0 comments on commit 909035f

Please sign in to comment.