summaryrefslogtreecommitdiffstats
path: root/zellij-utils/src
diff options
context:
space:
mode:
authorKen Matsui <26405363+ken-matsui@users.noreply.github.com>2021-11-01 03:14:12 +0900
committerKen Matsui <26405363+ken-matsui@users.noreply.github.com>2021-11-06 05:15:09 +0900
commit4acb2458d2e0da1d0459114f45123841e2fca741 (patch)
tree50a81760d29440580eabdb5e4f691db038e4bb8d /zellij-utils/src
parent03e62eb91c4f53a5be1548fecacc1fd5173adf47 (diff)
feat(attach): Support `--index` option to choose specific session by provided number in active sessions ordered by creation date, resolve #823
feat(attach): Support `--first` option for `attach` sub-command to let zellij choose the alphabetically first session; resolve #823 fix(attach-first): Fix `--first` option to choose the first created session in the existent sessions feat(attach): Support `--index` option to choose the session indexed by provided number like -t option of tmux feat(attach): Support listing active sessions with index when a provided number is not found in the active sessions feat(attach): Support listing active sessions with index when a provided number is not found in the active sessions feat: Add anyhow to uniformly treat error types and avoid panics
Diffstat (limited to 'zellij-utils/src')
-rw-r--r--zellij-utils/src/cli.rs4
-rw-r--r--zellij-utils/src/errors.rs1
-rw-r--r--zellij-utils/src/input/actions.rs3
-rw-r--r--zellij-utils/src/input/config.rs41
-rw-r--r--zellij-utils/src/ipc.rs2
-rw-r--r--zellij-utils/src/shared.rs7
6 files changed, 36 insertions, 22 deletions
diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs
index 7ac9e958c..78615d929 100644
--- a/zellij-utils/src/cli.rs
+++ b/zellij-utils/src/cli.rs
@@ -85,6 +85,10 @@ pub enum Sessions {
#[structopt(short, long)]
create: bool,
+ /// Number of the session index in the active sessions ordered creation date.
+ #[structopt(long)]
+ index: Option<usize>,
+
/// Change the behaviour of zellij
#[structopt(subcommand, name = "options")]
options: Option<SessionCommand>,
diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs
index be75e4add..401cdc10b 100644
--- a/zellij-utils/src/errors.rs
+++ b/zellij-utils/src/errors.rs
@@ -258,6 +258,7 @@ pub enum ScreenContext {
TerminalResize,
ChangeMode,
LeftClick,
+ RightClick,
MouseRelease,
MouseHold,
Copy,
diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs
index 8446bf0d8..9dd259580 100644
--- a/zellij-utils/src/input/actions.rs
+++ b/zellij-utils/src/input/actions.rs
@@ -28,6 +28,8 @@ pub enum Action {
Quit,
/// Write to the terminal.
Write(Vec<u8>),
+ /// Write Characters to the terminal.
+ WriteChars(String),
/// Switch to the specified input mode.
SwitchToMode(InputMode),
/// Resize focus pane in specified direction.
@@ -85,6 +87,7 @@ pub enum Action {
/// Detach session and exit
Detach,
LeftClick(Position),
+ RightClick(Position),
MouseRelease(Position),
MouseHold(Position),
Copy,
diff --git a/zellij-utils/src/input/config.rs b/zellij-utils/src/input/config.rs
index ecfe64c7c..66104016c 100644
--- a/zellij-utils/src/input/config.rs
+++ b/zellij-utils/src/input/config.rs
@@ -5,7 +5,7 @@ use std::fs::File;
use std::io::{self, Read};
use std::path::{Path, PathBuf};
-use serde::{Deserialize, Serialize};
+use serde::Deserialize;
use std::convert::{TryFrom, TryInto};
use super::keybinds::{Keybinds, KeybindsFromYaml};
@@ -20,7 +20,7 @@ const DEFAULT_CONFIG_FILE_NAME: &str = "config.yaml";
type ConfigResult = Result<Config, ConfigError>;
/// Intermediate deserialization config struct
-#[derive(Debug, Deserialize)]
+#[derive(Clone, Debug, Deserialize)]
pub struct ConfigFromYaml {
#[serde(flatten)]
pub options: Option<Options>,
@@ -31,7 +31,7 @@ pub struct ConfigFromYaml {
}
/// Main configuration.
-#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
+#[derive(Debug, Clone, PartialEq, Deserialize)]
pub struct Config {
pub keybinds: Keybinds,
pub options: Options,
@@ -106,7 +106,8 @@ impl TryFrom<&CliArgs> for Config {
impl Config {
/// Uses defaults, but lets config override them.
pub fn from_yaml(yaml_config: &str) -> ConfigResult {
- let config_from_yaml: Option<ConfigFromYaml> = match serde_yaml::from_str(yaml_config) {
+ let maybe_config_from_yaml: Option<ConfigFromYaml> = match serde_yaml::from_str(yaml_config)
+ {
Err(e) => {
// needs direct check, as `[ErrorImpl]` is private
// https://github.com/dtolnay/serde-yaml/issues/121
@@ -118,20 +119,9 @@ impl Config {
Ok(config) => config,
};
- match config_from_yaml {
+ match maybe_config_from_yaml {
None => Ok(Config::default()),
- Some(config) => {
- let keybinds = Keybinds::get_default_keybinds_with_config(config.keybinds);
- let options = Options::from_yaml(config.options);
- let themes = config.themes;
- let plugins = PluginsConfig::get_plugins_with_default(config.plugins.try_into()?);
- Ok(Config {
- keybinds,
- options,
- plugins,
- themes,
- })
- }
+ Some(config) => config.try_into(),
}
}
@@ -157,6 +147,23 @@ impl Config {
}
}
+impl TryFrom<ConfigFromYaml> for Config {
+ type Error = ConfigError;
+
+ fn try_from(config_from_yaml: ConfigFromYaml) -> ConfigResult {
+ let keybinds = Keybinds::get_default_keybinds_with_config(config_from_yaml.keybinds);
+ let options = Options::from_yaml(config_from_yaml.options);
+ let themes = config_from_yaml.themes;
+ let plugins = PluginsConfig::get_plugins_with_default(config_from_yaml.plugins.try_into()?);
+ Ok(Self {
+ keybinds,
+ options,
+ plugins,
+ themes,
+ })
+ }
+}
+
// TODO: Split errors up into separate modules
#[derive(Debug, Clone)]
pub struct LayoutNameInTabError;
diff --git a/zellij-utils/src/ipc.rs b/zellij-utils/src/ipc.rs
index 995b89fb4..b27a097a1 100644
--- a/zellij-utils/src/ipc.rs
+++ b/zellij-utils/src/ipc.rs
@@ -104,7 +104,7 @@ impl Display for ExitReason {
f,
"Session attached to another client. Use --force flag to force connect."
),
- Self::Error(e) => write!(f, "Error occured in server:\n{}", e),
+ Self::Error(e) => write!(f, "Error occurred in server:\n{}", e),
}
}
}
diff --git a/zellij-utils/src/shared.rs b/zellij-utils/src/shared.rs
index 06d1378db..37dfc3be2 100644
--- a/zellij-utils/src/shared.rs
+++ b/zellij-utils/src/shared.rs
@@ -2,7 +2,7 @@
use std::{iter, str::from_utf8};
-use colors_transform::{Color, Rgb};
+use colorsys::Rgb;
use std::os::unix::fs::PermissionsExt;
use std::path::Path;
use std::{fs, io};
@@ -52,10 +52,9 @@ pub mod colors {
}
pub fn _hex_to_rgb(hex: &str) -> (u8, u8, u8) {
- let rgb = Rgb::from_hex_str(hex)
+ Rgb::from_hex_str(hex)
.expect("The passed argument must be a valid hex color")
- .as_tuple();
- (rgb.0 as u8, rgb.1 as u8, rgb.2 as u8)
+ .into()
}
pub fn default_palette() -> Palette {