summaryrefslogtreecommitdiffstats
path: root/zellij-utils
diff options
context:
space:
mode:
authora-kenji <aks.kenji@protonmail.com>2021-07-23 17:24:45 +0200
committera-kenji <aks.kenji@protonmail.com>2021-07-23 17:24:45 +0200
commit485339c58471664915776272f397e09c9a911d01 (patch)
tree904e2aa26d72ac3ea425e82e158d234f02567b24 /zellij-utils
parent5ede25dc37ceb192032524ac9200bb1ca95e5863 (diff)
parentf5734f2bf14212cda4455065222c0593004020bf (diff)
Merge branch 'main' of https://github.com/zellij-org/zellij into tab-layout
Diffstat (limited to 'zellij-utils')
-rw-r--r--zellij-utils/Cargo.toml6
-rw-r--r--zellij-utils/src/input/mod.rs66
-rw-r--r--zellij-utils/src/logging.rs51
-rw-r--r--zellij-utils/src/setup.rs22
4 files changed, 107 insertions, 38 deletions
diff --git a/zellij-utils/Cargo.toml b/zellij-utils/Cargo.toml
index 6b530ee96..5761f4140 100644
--- a/zellij-utils/Cargo.toml
+++ b/zellij-utils/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "zellij-utils"
-version = "0.15.0"
+version = "0.16.0"
authors = ["Kunal Mohan <kunalmohan99@gmail.com>"]
edition = "2018"
description = "A utility library for Zellij client and server"
@@ -27,7 +27,9 @@ structopt = "0.3"
strum = "0.20.0"
termion = "1.5.0"
vte = "0.10.1"
-zellij-tile = { path = "../zellij-tile/", version = "0.15.0" }
+zellij-tile = { path = "../zellij-tile/", version = "0.16.0" }
+log = "0.4.14"
+log4rs = "1.0.0"
[dependencies.async-std]
version = "1.3.0"
diff --git a/zellij-utils/src/input/mod.rs b/zellij-utils/src/input/mod.rs
index 11c5a8432..746d58619 100644
--- a/zellij-utils/src/input/mod.rs
+++ b/zellij-utils/src/input/mod.rs
@@ -12,52 +12,48 @@ pub mod theme;
use termion::input::TermRead;
use zellij_tile::data::{InputMode, Key, ModeInfo, Palette, PluginCapabilities};
-/// Creates a [`Help`] struct indicating the current [`InputMode`] and its keybinds
+/// Creates a [`ModeInfo`] struct indicating the current [`InputMode`] and its keybinds
/// (as pairs of [`String`]s).
-// TODO this should probably be automatically generated in some way
pub fn get_mode_info(
mode: InputMode,
palette: Palette,
capabilities: PluginCapabilities,
) -> ModeInfo {
- let mut keybinds: Vec<(String, String)> = vec![];
- match mode {
- InputMode::Normal | InputMode::Locked => {}
- InputMode::Resize => {
- keybinds.push(("←↓↑→".to_string(), "Resize".to_string()));
- }
- InputMode::Pane => {
- keybinds.push(("←↓↑→".to_string(), "Move focus".to_string()));
- keybinds.push(("p".to_string(), "Next".to_string()));
- keybinds.push(("n".to_string(), "New".to_string()));
- keybinds.push(("d".to_string(), "Down split".to_string()));
- keybinds.push(("r".to_string(), "Right split".to_string()));
- keybinds.push(("x".to_string(), "Close".to_string()));
- keybinds.push(("f".to_string(), "Fullscreen".to_string()));
- }
- InputMode::Tab => {
- keybinds.push(("←↓↑→".to_string(), "Move focus".to_string()));
- keybinds.push(("n".to_string(), "New".to_string()));
- keybinds.push(("x".to_string(), "Close".to_string()));
- keybinds.push(("r".to_string(), "Rename".to_string()));
- keybinds.push(("s".to_string(), "Sync".to_string()));
- }
- InputMode::Scroll => {
- keybinds.push(("↓↑".to_string(), "Scroll".to_string()));
- keybinds.push(("PgUp/PgDn".to_string(), "Scroll Page".to_string()));
- }
- InputMode::RenameTab => {
- keybinds.push(("Enter".to_string(), "when done".to_string()));
- }
- InputMode::Session => {
- keybinds.push(("d".to_string(), "Detach".to_string()));
- }
- }
+ let keybinds = match mode {
+ InputMode::Normal | InputMode::Locked => Vec::new(),
+ InputMode::Resize => vec![("←↓↑→".to_string(), "Resize".to_string())],
+ InputMode::Pane => vec![
+ ("←↓↑→".to_string(), "Move focus".to_string()),
+ ("p".to_string(), "Next".to_string()),
+ ("n".to_string(), "New".to_string()),
+ ("d".to_string(), "Down split".to_string()),
+ ("r".to_string(), "Right split".to_string()),
+ ("x".to_string(), "Close".to_string()),
+ ("f".to_string(), "Fullscreen".to_string()),
+ ],
+ InputMode::Tab => vec![
+ ("←↓↑→".to_string(), "Move focus".to_string()),
+ ("n".to_string(), "New".to_string()),
+ ("x".to_string(), "Close".to_string()),
+ ("r".to_string(), "Rename".to_string()),
+ ("s".to_string(), "Sync".to_string()),
+ ],
+ InputMode::Scroll => vec![
+ ("↓↑".to_string(), "Scroll".to_string()),
+ ("PgUp/PgDn".to_string(), "Scroll Page".to_string()),
+ ],
+ InputMode::RenameTab => vec![("Enter".to_string(), "when done".to_string())],
+ InputMode::Session => vec![("d".to_string(), "Detach".to_string())],
+ };
+
+ let session_name = std::env::var("ZELLIJ_SESSION_NAME").ok();
+
ModeInfo {
mode,
keybinds,
palette,
capabilities,
+ session_name,
}
}
diff --git a/zellij-utils/src/logging.rs b/zellij-utils/src/logging.rs
index 6d415e38f..7e57eebda 100644
--- a/zellij-utils/src/logging.rs
+++ b/zellij-utils/src/logging.rs
@@ -7,9 +7,60 @@ use std::{
path::{Path, PathBuf},
};
+use log::LevelFilter;
+
+use log4rs::append::file::FileAppender;
+use log4rs::config::{Appender, Config, Logger, Root};
+use log4rs::encode::pattern::PatternEncoder;
+
use crate::consts::{ZELLIJ_TMP_LOG_DIR, ZELLIJ_TMP_LOG_FILE};
use crate::shared::set_permissions;
+pub fn configure_logger() {
+ // {n} means platform dependent newline
+ // module is padded to exactly 25 bytes and thread is padded to be between 10 and 15 bytes.
+ let file_pattern = "{highlight({level:<6})} |{module:<25.25}| {date(%Y-%m-%d %H:%M:%S.%3f)} [{thread:<10.15}] [{file}:{line}]: {message} {n}";
+
+ // default zellij appender, should be used across most of the codebase.
+ let log_file = FileAppender::builder()
+ .encoder(Box::new(PatternEncoder::new(file_pattern)))
+ .append(true)
+ .build(ZELLIJ_TMP_LOG_DIR.join("zellij.log"))
+ .unwrap();
+
+ // plugin appender. To be used in loggin_pipe to forward stderr output from plugins. We do some formatting
+ // in logging_pipe to print plugin name as 'module' and plugin_id instead of thread.
+ let log_plugin = FileAppender::builder()
+ .encoder(Box::new(PatternEncoder::new(
+ "{highlight({level:<6})} {message} {n}",
+ )))
+ .append(true)
+ .build(ZELLIJ_TMP_LOG_DIR.join("zellij.log"))
+ .unwrap();
+
+ // Set the default logging level to "info" and log it to zellij.log file
+ // Decrease verbosity for `wasmer_compiler_cranelift` module because it has a lot of useless info logs
+ // For `zellij_server::logging_pipe`, we use custom format as we use logging macros to forward stderr output from plugins
+ let config = Config::builder()
+ .appender(Appender::builder().build("logFile", Box::new(log_file)))
+ .appender(Appender::builder().build("logPlugin", Box::new(log_plugin)))
+ .logger(
+ Logger::builder()
+ .appender("logFile")
+ .build("wasmer_compiler_cranelift", LevelFilter::Warn),
+ )
+ .logger(
+ Logger::builder()
+ .appender("logPlugin")
+ .additive(false)
+ .build("zellij_server::logging_pipe", LevelFilter::Trace),
+ )
+ .build(Root::builder().appender("logFile").build(LevelFilter::Info))
+ .unwrap();
+
+ let _ = log4rs::init_config(config).unwrap();
+}
+
pub fn atomic_create_file(file_name: &Path) -> io::Result<()> {
let _ = fs::OpenOptions::new()
.append(true)
diff --git a/zellij-utils/src/setup.rs b/zellij-utils/src/setup.rs
index 61c330cdb..aa0bb642b 100644
--- a/zellij-utils/src/setup.rs
+++ b/zellij-utils/src/setup.rs
@@ -96,13 +96,25 @@ pub const STRIDER_LAYOUT: &[u8] = include_bytes!(concat!(
pub const NO_STATUS_LAYOUT: &[u8] = include_bytes!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/",
- "assets/layouts/default.yaml"
+ "assets/layouts/disable-status-bar.yaml"
));
pub fn dump_default_config() -> std::io::Result<()> {
dump_asset(DEFAULT_CONFIG)
}
+pub fn dump_specified_layout(layout: &str) -> std::io::Result<()> {
+ match layout {
+ "strider" => dump_asset(STRIDER_LAYOUT),
+ "default" => dump_asset(DEFAULT_LAYOUT),
+ "disable-status" => dump_asset(NO_STATUS_LAYOUT),
+ not_found => Err(std::io::Error::new(
+ std::io::ErrorKind::Other,
+ format!("Layout: {} not found", not_found),
+ )),
+ }
+}
+
#[derive(Debug, Default, Clone, StructOpt, Serialize, Deserialize)]
pub struct Setup {
/// Dump the default configuration file to stdout
@@ -117,6 +129,9 @@ pub struct Setup {
#[structopt(long)]
pub check: bool,
+ /// Dump the specified layout file to stdout
+ #[structopt(long)]
+ pub dump_layout: Option<String>,
/// Generates completion for the specified shell
#[structopt(long)]
pub generate_completion: Option<String>,
@@ -144,6 +159,11 @@ impl Setup {
std::process::exit(0);
}
+ if let Some(layout) = &self.dump_layout {
+ dump_specified_layout(layout)?;
+ std::process::exit(0);
+ }
+
Ok(())
}