aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src
diff options
context:
space:
mode:
authorqepasa <pawelpalenica11@gmail.com>2021-07-20 22:19:03 -0700
committerGitHub <noreply@github.com>2021-07-20 22:19:03 -0700
commitf0bc2977434d54079e0ca50bd1c18cd8bb7e1830 (patch)
tree501314d4f6fcb6116acac0314cf21fa1c3e75223 /zellij-utils/src
parentRead from LoggingPipe returns error (diff)
parentdocs(changelog): noop for mouse actions on plugins (diff)
downloadsl0ppij-f0bc2977434d54079e0ca50bd1c18cd8bb7e1830.tar.gz
sl0ppij-f0bc2977434d54079e0ca50bd1c18cd8bb7e1830.tar.xz
sl0ppij-f0bc2977434d54079e0ca50bd1c18cd8bb7e1830.zip
Merge branch 'main' into unified-logging
Diffstat (limited to 'zellij-utils/src')
-rw-r--r--zellij-utils/src/input/actions.rs10
-rw-r--r--zellij-utils/src/input/command.rs1
-rw-r--r--zellij-utils/src/input/layout.rs36
-rw-r--r--zellij-utils/src/input/options.rs71
4 files changed, 84 insertions, 34 deletions
diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs
index ecd515a4..bfd7d255 100644
--- a/zellij-utils/src/input/actions.rs
+++ b/zellij-utils/src/input/actions.rs
@@ -1,6 +1,7 @@
//! Definition of the actions that can be bound to keys.
use super::command::RunCommandAction;
+use crate::input::options::OnForceClose;
use serde::{Deserialize, Serialize};
use zellij_tile::data::InputMode;
@@ -81,3 +82,12 @@ pub enum Action {
MouseHold(Position),
Copy,
}
+
+impl From<OnForceClose> for Action {
+ fn from(ofc: OnForceClose) -> Action {
+ match ofc {
+ OnForceClose::Quit => Action::Quit,
+ OnForceClose::Detach => Action::Detach,
+ }
+ }
+}
diff --git a/zellij-utils/src/input/command.rs b/zellij-utils/src/input/command.rs
index b66c7500..2054f208 100644
--- a/zellij-utils/src/input/command.rs
+++ b/zellij-utils/src/input/command.rs
@@ -11,6 +11,7 @@ pub enum TerminalAction {
#[derive(Clone, Debug, Deserialize, Default, Serialize, PartialEq, Eq)]
pub struct RunCommand {
+ #[serde(alias = "cmd")]
pub command: PathBuf,
#[serde(default)]
pub args: Vec<String>,
diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs
index 16309db1..a48c3521 100644
--- a/zellij-utils/src/input/layout.rs
+++ b/zellij-utils/src/input/layout.rs
@@ -8,7 +8,11 @@
// place.
// If plugins should be able to depend on the layout system
// then [`zellij-utils`] could be a proper place.
-use crate::{input::config::ConfigError, pane_size::PositionAndSize, setup};
+use crate::{
+ input::{command::RunCommand, config::ConfigError},
+ pane_size::PositionAndSize,
+ setup,
+};
use crate::{serde, serde_yaml};
use serde::{Deserialize, Serialize};
@@ -31,12 +35,21 @@ pub enum SplitSize {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(crate = "self::serde")]
+pub enum Run {
+ #[serde(rename = "plugin")]
+ Plugin(Option<PathBuf>),
+ #[serde(rename = "command")]
+ Command(RunCommand),
+}
+
+#[derive(Debug, Serialize, Deserialize, Clone)]
+#[serde(crate = "self::serde")]
pub struct Layout {
pub direction: Direction,
#[serde(default)]
pub parts: Vec<Layout>,
pub split_size: Option<SplitSize>,
- pub plugin: Option<PathBuf>,
+ pub run: Option<Run>,
}
type LayoutResult = Result<Layout, ConfigError>;
@@ -127,13 +140,28 @@ impl Layout {
let mut total_panes = 0;
total_panes += self.parts.len();
for part in self.parts.iter() {
- if part.plugin.is_none() {
- total_panes += part.total_terminal_panes();
+ match part.run {
+ Some(Run::Command(_)) | None => {
+ total_panes += part.total_terminal_panes();
+ }
+ Some(Run::Plugin(_)) => {}
}
}
total_panes
}
+ pub fn extract_run_instructions(&self) -> Vec<Option<Run>> {
+ let mut run_instructions = vec![];
+ if self.parts.is_empty() {
+ run_instructions.push(self.run.clone());
+ }
+ for part in self.parts.iter() {
+ let mut current_runnables = part.extract_run_instructions();
+ run_instructions.append(&mut current_runnables);
+ }
+ run_instructions
+ }
+
pub fn position_panes_in_space(
&self,
space: &PositionAndSize,
diff --git a/zellij-utils/src/input/options.rs b/zellij-utils/src/input/options.rs
index 2ba2be86..a2f9231c 100644
--- a/zellij-utils/src/input/options.rs
+++ b/zellij-utils/src/input/options.rs
@@ -2,12 +2,39 @@
use crate::cli::Command;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
+use std::str::FromStr;
use structopt::StructOpt;
use zellij_tile::data::InputMode;
+#[derive(Copy, Clone, Debug, PartialEq, Deserialize, Serialize)]
+pub enum OnForceClose {
+ #[serde(alias = "quit")]
+ Quit,
+ #[serde(alias = "detach")]
+ Detach,
+}
+
+impl Default for OnForceClose {
+ fn default() -> Self {
+ Self::Detach
+ }
+}
+
+impl FromStr for OnForceClose {
+ type Err = Box<dyn std::error::Error>;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ match s {
+ "quit" => Ok(Self::Quit),
+ "detach" => Ok(Self::Detach),
+ e => Err(e.to_string().into()),
+ }
+ }
+}
+
#[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize, StructOpt)]
/// Options that can be set either through the config file,
-/// or cli flags
+/// or cli flags - cli flags should take precedence over the config file
pub struct Options {
/// Allow plugins to use a more simplified layout
/// that is compatible with more fonts
@@ -29,7 +56,11 @@ pub struct Options {
pub layout_dir: Option<PathBuf>,
#[structopt(long)]
#[serde(default)]
+ /// Disable handling of mouse events
pub disable_mouse_mode: bool,
+ /// Set behaviour on force close (quit or detach)
+ #[structopt(long)]
+ pub on_force_close: Option<OnForceClose>,
}
impl Options {
@@ -45,37 +76,16 @@ impl Options {
/// will supercede a `Some` in `self`
// TODO: Maybe a good candidate for a macro?
pub fn merge(&self, other: Options) -> Options {
- let simplified_ui = if other.simplified_ui {
- true
- } else {
- self.simplified_ui
- };
+ let merge_bool = |opt_other, opt_self| if opt_other { true } else { opt_self };
- let default_mode = match other.default_mode {
- None => self.default_mode,
- other => other,
- };
+ let simplified_ui = merge_bool(other.simplified_ui, self.simplified_ui);
+ let disable_mouse_mode = merge_bool(other.disable_mouse_mode, self.disable_mouse_mode);
- let default_shell = match other.default_shell {
- None => self.default_shell.clone(),
- other => other,
- };
-
- let layout_dir = match other.layout_dir {
- None => self.layout_dir.clone(),
- other => other,
- };
-
- let theme = match other.theme {
- None => self.theme.clone(),
- other => other,
- };
-
- let disable_mouse_mode = if other.disable_mouse_mode {
- true
- } else {
- self.disable_mouse_mode
- };
+ let default_mode = other.default_mode.or(self.default_mode);
+ let default_shell = other.default_shell.or_else(|| self.default_shell.clone());
+ let layout_dir = other.layout_dir.or_else(|| self.layout_dir.clone());
+ let theme = other.theme.or_else(|| self.theme.clone());
+ let on_force_close = other.on_force_close.or(self.on_force_close);
Options {
simplified_ui,
@@ -84,6 +94,7 @@ impl Options {
default_shell,
layout_dir,
disable_mouse_mode,
+ on_force_close,
}
}