summaryrefslogtreecommitdiffstats
path: root/zellij-utils
diff options
context:
space:
mode:
authora-kenji <aks.kenji@protonmail.com>2021-08-01 20:25:33 +0200
committera-kenji <aks.kenji@protonmail.com>2021-08-01 20:25:33 +0200
commitfc7bc3cc8b8b6e6c652e85bb47424338e7038cbe (patch)
treeeb43e2b04ebe0c26e286bab77d842304ddae596d /zellij-utils
parent806ffad5539c99380e7c0e423f4c864d8db431e2 (diff)
parent309f4a62bfd11bd1c311d833343625f9bc476114 (diff)
Merge branch 'main' of https://github.com/zellij-org/zellij into tab-layout
Diffstat (limited to 'zellij-utils')
-rw-r--r--zellij-utils/assets/config/default.yaml2
-rw-r--r--zellij-utils/src/errors.rs1
-rw-r--r--zellij-utils/src/input/actions.rs2
-rw-r--r--zellij-utils/src/input/layout.rs22
-rw-r--r--zellij-utils/src/input/unit/layout_test.rs5
-rw-r--r--zellij-utils/src/setup.rs80
6 files changed, 85 insertions, 27 deletions
diff --git a/zellij-utils/assets/config/default.yaml b/zellij-utils/assets/config/default.yaml
index e90b60a18..13c8efcae 100644
--- a/zellij-utils/assets/config/default.yaml
+++ b/zellij-utils/assets/config/default.yaml
@@ -178,6 +178,8 @@ keybinds:
key: [Ctrl: 'p',]
- action: [SwitchToMode: Session,]
key: [Ctrl: 'o',]
+ - action: [ScrollToBottom, SwitchToMode: Normal,]
+ key: [Ctrl: 'c',]
- action: [Quit,]
key: [Ctrl: 'q',]
- action: [ScrollDown,]
diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs
index b32dd337d..6a053038a 100644
--- a/zellij-utils/src/errors.rs
+++ b/zellij-utils/src/errors.rs
@@ -202,6 +202,7 @@ pub enum ScreenContext {
ScrollUpAt,
ScrollDown,
ScrollDownAt,
+ ScrollToBottom,
PageScrollUp,
PageScrollDown,
ClearScroll,
diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs
index ab711c75c..dbced56df 100644
--- a/zellij-utils/src/input/actions.rs
+++ b/zellij-utils/src/input/actions.rs
@@ -49,6 +49,8 @@ pub enum Action {
ScrollDown,
/// Scroll down at point
ScrollDownAt(Position),
+ /// Scroll down to bottom in focus pane.
+ ScrollToBottom,
/// Scroll up one page in focus pane.
PageScrollUp,
/// Scroll down one page in focus pane.
diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs
index 26d967646..887350fb0 100644
--- a/zellij-utils/src/input/layout.rs
+++ b/zellij-utils/src/input/layout.rs
@@ -123,8 +123,8 @@ impl Layout {
layout: Option<&PathBuf>,
layout_path: Option<&PathBuf>,
layout_dir: Option<PathBuf>,
- ) -> Option<Layout> {
- let layout_result = layout
+ ) -> Option<Result<Layout, ConfigError>> {
+ layout
.map(|p| Layout::from_dir(p, layout_dir.as_ref()))
.or_else(|| layout_path.map(|p| Layout::new(p)))
.or_else(|| {
@@ -132,16 +132,7 @@ impl Layout {
&std::path::PathBuf::from("default"),
layout_dir.as_ref(),
))
- });
-
- match layout_result {
- None => None,
- Some(Ok(layout)) => Some(layout),
- Some(Err(e)) => {
- eprintln!("There was an error in the layout file:\n{}", e);
- std::process::exit(1);
- }
- }
+ })
}
// Currently still needed but on nightly
@@ -297,12 +288,9 @@ impl Layout {
pub fn construct_main_layout(&self) -> MainLayout {
let (pre_tab, post_tab, tabs) = self.split_main_and_tab_layout();
+ // Todo: A proper LayoutError
if tabs.is_empty() {
- panic!("The layout file should have a `tabs` section specified");
- }
-
- if tabs.len() > 1 {
- panic!("The layout file should have one single tab in the `tabs` section specified");
+ panic!("The layout file should have a [`tabs`] section specified");
}
MainLayout {
diff --git a/zellij-utils/src/input/unit/layout_test.rs b/zellij-utils/src/input/unit/layout_test.rs
index 89217e04e..5d9fda35a 100644
--- a/zellij-utils/src/input/unit/layout_test.rs
+++ b/zellij-utils/src/input/unit/layout_test.rs
@@ -528,10 +528,7 @@ fn no_tabs_specified_should_panic() {
}
#[test]
-#[should_panic]
-// TODO Make error out of this
-// Only untill #631 is fixed
-fn multiple_tabs_specified_should_panic() {
+fn multiple_tabs_specified_should_not_panic() {
let path = layout_test_dir("multiple-tabs-should-panic.yaml".into());
let layout = Layout::new(&path);
let _main_layout = layout.unwrap().construct_main_layout();
diff --git a/zellij-utils/src/setup.rs b/zellij-utils/src/setup.rs
index aa0bb642b..e00eb7aea 100644
--- a/zellij-utils/src/setup.rs
+++ b/zellij-utils/src/setup.rs
@@ -1,11 +1,18 @@
-use crate::cli::CliArgs;
-use crate::consts::{
- FEATURES, SYSTEM_DEFAULT_CONFIG_DIR, SYSTEM_DEFAULT_DATA_DIR_PREFIX, VERSION, ZELLIJ_PROJ_DIR,
+use crate::{
+ cli::{CliArgs, Command},
+ consts::{
+ FEATURES, SYSTEM_DEFAULT_CONFIG_DIR, SYSTEM_DEFAULT_DATA_DIR_PREFIX, VERSION,
+ ZELLIJ_PROJ_DIR,
+ },
+ input::{
+ config::{Config, ConfigError},
+ layout::{Layout, MainLayout},
+ options::Options,
+ },
};
-use crate::input::options::Options;
use directories_next::BaseDirs;
use serde::{Deserialize, Serialize};
-use std::{io::Write, path::Path, path::PathBuf};
+use std::{convert::TryFrom, io::Write, path::Path, path::PathBuf, process};
use structopt::StructOpt;
const CONFIG_LOCATION: &str = ".config/zellij";
@@ -139,6 +146,68 @@ pub struct Setup {
impl Setup {
/// Entrypoint from main
+ /// Merges options from the config file and the command line options
+ /// into `[Options]`, the command line options superceding the config
+ /// file options:
+ /// 1. command line options (`zellij options`)
+ /// 2. config options (`config.yaml`)
+ pub fn from_options(
+ opts: &CliArgs,
+ ) -> Result<(Config, Option<MainLayout>, Options), ConfigError> {
+ let clean = match &opts.command {
+ Some(Command::Setup(ref setup)) => setup.clean,
+ _ => false,
+ };
+
+ log::info!("{:?}", clean);
+
+ let config = if !clean {
+ match Config::try_from(opts) {
+ Ok(config) => config,
+ Err(e) => {
+ eprintln!("There was an error in the config file:");
+ return Err(e);
+ }
+ }
+ } else {
+ Config::default()
+ };
+
+ let config_options = Options::from_cli(&config.options, opts.command.clone());
+
+ let layout_dir = config_options
+ .layout_dir
+ .clone()
+ .or_else(|| get_layout_dir(opts.config_dir.clone().or_else(find_default_config_dir)));
+ let layout_result = Layout::from_path_or_default(
+ opts.layout.as_ref(),
+ opts.layout_path.as_ref(),
+ layout_dir,
+ );
+ let layout = match layout_result {
+ None => None,
+ Some(Ok(layout)) => Some(layout),
+ Some(Err(e)) => {
+ eprintln!("There was an error in the layout file:");
+ return Err(e);
+ }
+ }
+ .map(|layout| layout.construct_main_layout());
+
+ if let Some(Command::Setup(ref setup)) = &opts.command {
+ setup.from_cli(opts, &config_options).map_or_else(
+ |e| {
+ eprintln!("{:?}", e);
+ process::exit(1);
+ },
+ |_| {},
+ );
+ };
+
+ Ok((config, layout, config_options))
+ }
+
+ /// General setup helpers
pub fn from_cli(&self, opts: &CliArgs, config_options: &Options) -> std::io::Result<()> {
if self.clean {
return Ok(());
@@ -201,7 +270,6 @@ impl Setup {
}
}
if let Some(config_file) = config_file {
- use crate::input::config::Config;
message.push_str(&format!("[CONFIG FILE]: {:?}\n", config_file));
match Config::new(&config_file) {
Ok(_) => message.push_str("[CONFIG FILE]: Well defined.\n"),