From 0c570a52f56e61505d0eb1893b4bc19df651f611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Palenica?= Date: Tue, 29 Jun 2021 23:46:00 -0700 Subject: [PATCH 01/33] feat: Add logger to Zellij We add log4rs create for logging across Zellij. Additionally, we capture `stderr` output from plugins and log it the same log file as other Zellij logs. --- Cargo.lock | 301 +++++++++++++++++++++----- Cargo.toml | 1 + default-plugins/strider/src/main.rs | 3 + src/main.rs | 3 + zellij-server/Cargo.toml | 5 + zellij-server/src/decorating_pipe.rs | 94 ++++++++ zellij-server/src/lib.rs | 3 + zellij-server/src/wasm_vm.rs | 9 +- zellij-tile/Cargo.toml | 1 + zellij-utils/Cargo.toml | 3 + zellij-utils/assets/config/log4rs.yml | 42 ++++ zellij-utils/src/logging.rs | 10 +- 12 files changed, 416 insertions(+), 59 deletions(-) create mode 100644 zellij-server/src/decorating_pipe.rs create mode 100644 zellij-utils/assets/config/log4rs.yml diff --git a/Cargo.lock b/Cargo.lock index a2c525d6..1a51077b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + [[package]] name = "ansi_term" version = "0.11.0" @@ -35,6 +44,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "anyhow" +version = "1.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15af2628f6890fe2609a3b91bef4c83450512802e59489f9c1cb1fa5df064a61" + +[[package]] +name = "arc-swap" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dabe5a181f83789739c194cbe5a897dde195078fac08568d09221fd6137a7ba8" + [[package]] name = "arrayvec" version = "0.5.2" @@ -216,7 +237,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "miniz_oxide", - "object 0.25.2", + "object 0.25.3", "rustc-demangle", ] @@ -297,6 +318,19 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "time", + "winapi", +] + [[package]] name = "clap" version = "2.33.3" @@ -582,6 +616,17 @@ dependencies = [ "syn", ] +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "directories-next" version = "2.0.0" @@ -644,9 +689,9 @@ dependencies = [ [[package]] name = "erased-serde" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5b36e6f2295f393f44894c6031f67df4d185b984cd54d08f768ce678007efcd" +checksum = "3de9ad4541d99dc22b59134e7ff8dc3d6c988c89ecd7324bf10a8362b07a2afa" dependencies = [ "serde", ] @@ -866,9 +911,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.9.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" [[package]] name = "heck" @@ -881,13 +926,19 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "ident_case" version = "1.0.1" @@ -896,9 +947,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "indexmap" -version = "1.6.2" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" dependencies = [ "autocfg", "hashbrown", @@ -1013,9 +1064,9 @@ checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" [[package]] name = "libc" -version = "0.2.95" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" +checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" [[package]] name = "libloading" @@ -1084,9 +1135,43 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ "cfg-if 1.0.0", + "serde", "value-bag", ] +[[package]] +name = "log-mdc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a94d21414c1f4a51209ad204c1776a3d0765002c76c6abcb602a6f09f1e881c7" + +[[package]] +name = "log4rs" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1572a880d1115ff867396eee7ae2bc924554225e67a0d3c85c745b3e60ca211" +dependencies = [ + "anyhow", + "arc-swap", + "chrono", + "derivative", + "fnv", + "humantime", + "libc", + "log", + "log-mdc", + "parking_lot 0.11.1", + "regex", + "serde", + "serde-value", + "serde_json", + "serde_yaml", + "thiserror", + "thread-id", + "typemap", + "winapi", +] + [[package]] name = "mach" version = "0.3.2" @@ -1132,9 +1217,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.7.11" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" +checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" dependencies = [ "libc", "log", @@ -1188,6 +1273,25 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.13.0" @@ -1216,24 +1320,24 @@ dependencies = [ [[package]] name = "object" -version = "0.25.2" +version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8bc1d42047cf336f0f939c99e97183cf31551bf0f2865a2ec9c8d91fd4ffb5e" +checksum = "a38f2be3697a57b4060074ff41b44c16870d916ad7877c17696e063257482bc7" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "openssl-sys" -version = "0.9.63" +version = "0.9.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6b0d6fb7d80f877617dfcb014e605e2b5ab2fb0afdf27935219bb6bd984cb98" +checksum = "7a7907e3bfa08bb85105209cdfcb6c63d109f8f6c1ed6ca318fff5c1853fbc1d" dependencies = [ "autocfg", "cc", @@ -1242,6 +1346,15 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "ordered-float" +version = "2.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f100fcfb41e5385e0991f74981732049f9b896821542a219420491046baafdc2" +dependencies = [ + "num-traits", +] + [[package]] name = "parking" version = "2.0.0" @@ -1292,16 +1405,16 @@ dependencies = [ "cfg-if 1.0.0", "instant", "libc", - "redox_syscall 0.2.8", + "redox_syscall 0.2.9", "smallvec", "winapi", ] [[package]] name = "pin-project-lite" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" [[package]] name = "pin-utils" @@ -1317,14 +1430,14 @@ checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "polling" -version = "2.0.3" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fc12d774e799ee9ebae13f4076ca003b40d18a11ac0f3641e6f899618580b7b" +checksum = "92341d779fa34ea8437ef4d82d440d5e1ce3f3ff7f824aa64424cd481f9a1f25" dependencies = [ "cfg-if 1.0.0", "libc", "log", - "wepoll-sys", + "wepoll-ffi", "winapi", ] @@ -1423,24 +1536,24 @@ dependencies = [ [[package]] name = "rand" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" dependencies = [ "libc", "rand_chacha", - "rand_core 0.6.2", + "rand_core 0.6.3", "rand_hc", ] [[package]] name = "rand_chacha" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.2", + "rand_core 0.6.3", ] [[package]] @@ -1460,20 +1573,20 @@ checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" [[package]] name = "rand_core" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ "getrandom", ] [[package]] name = "rand_hc" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" dependencies = [ - "rand_core 0.6.2", + "rand_core 0.6.3", ] [[package]] @@ -1518,9 +1631,9 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "redox_syscall" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc" +checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" dependencies = [ "bitflags", ] @@ -1531,7 +1644,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" dependencies = [ - "redox_syscall 0.2.8", + "redox_syscall 0.2.9", ] [[package]] @@ -1541,7 +1654,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" dependencies = [ "getrandom", - "redox_syscall 0.2.8", + "redox_syscall 0.2.9", ] [[package]] @@ -1555,6 +1668,23 @@ dependencies = [ "smallvec", ] +[[package]] +name = "regex" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + [[package]] name = "region" version = "2.2.0" @@ -1578,9 +1708,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "410f7acf3cb3a44527c5d9546bad4bf4e6c460915d5f9f2fc524498bfe8f70ce" +checksum = "dead70b0b5e03e9c814bcb6b01e03e68f7c57a80aa48c72ec92152ab3e818d49" [[package]] name = "rustc-hash" @@ -1609,6 +1739,16 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-value" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" +dependencies = [ + "ordered-float", + "serde", +] + [[package]] name = "serde_bytes" version = "0.11.5" @@ -1821,9 +1961,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.72" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" +checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" dependencies = [ "proc-macro2", "quote", @@ -1854,8 +1994,8 @@ checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ "cfg-if 1.0.0", "libc", - "rand 0.8.3", - "redox_syscall 0.2.8", + "rand 0.8.4", + "redox_syscall 0.2.9", "remove_dir_all", "winapi", ] @@ -1889,7 +2029,7 @@ checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e" dependencies = [ "libc", "numtoa", - "redox_syscall 0.2.8", + "redox_syscall 0.2.9", "redox_termios", ] @@ -1922,6 +2062,17 @@ dependencies = [ "syn", ] +[[package]] +name = "thread-id" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7fbf4c9d56b320106cd64fd024dadfa0be7cb4706725fc44a7d7ce952d820c1" +dependencies = [ + "libc", + "redox_syscall 0.1.57", + "winapi", +] + [[package]] name = "time" version = "0.1.43" @@ -1965,6 +2116,21 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "traitobject" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" + +[[package]] +name = "typemap" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "653be63c80a3296da5551e1bfd2cca35227e13cdd08c6668903ae2f4f77aa1f6" +dependencies = [ + "unsafe-any", +] + [[package]] name = "typetag" version = "0.1.7" @@ -2007,6 +2173,15 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +[[package]] +name = "unsafe-any" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f30360d7979f5e9c6e6cea48af192ea8fab4afb3cf72597154b8f08935bc9c7f" +dependencies = [ + "traitobject", +] + [[package]] name = "utf8parse" version = "0.1.1" @@ -2037,9 +2212,9 @@ dependencies = [ [[package]] name = "vcpkg" -version = "0.2.13" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "025ce40a007e1907e58d5bc1a594def78e5573bb0b1160bc389634e8f12e4faa" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "vec_map" @@ -2102,6 +2277,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" dependencies = [ "cfg-if 1.0.0", + "serde", + "serde_json", "wasm-bindgen-macro", ] @@ -2363,18 +2540,18 @@ checksum = "87cc2fe6350834b4e528ba0901e7aa405d78b89dc1fa3145359eb4de0e323fcf" [[package]] name = "wast" -version = "35.0.2" +version = "36.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ef140f1b49946586078353a453a1d28ba90adfc54dde75710bc1931de204d68" +checksum = "8b5d7ba374a364571da1cb0a379a3dc302582a2d9937a183bfe35b68ad5bb9c4" dependencies = [ "leb128", ] [[package]] name = "wat" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ec280a739b69173e0ffd12c1658507996836ba4e992ed9bc1e5385a0bd72a02" +checksum = "16383df7f0e3901484c2dda6294ed6895caa3627ce4f6584141dcf30a33a23e6" dependencies = [ "wast", ] @@ -2390,10 +2567,10 @@ dependencies = [ ] [[package]] -name = "wepoll-sys" -version = "3.0.1" +name = "wepoll-ffi" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcb14dea929042224824779fbc82d9fab8d2e6d3cbc0ac404de8edf489e77ff" +checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" dependencies = [ "cc", ] @@ -2444,8 +2621,9 @@ name = "zellij" version = "0.14.0" dependencies = [ "insta", + "log", "names", - "rand 0.8.3", + "rand 0.8.4", "ssh2", "zellij-client", "zellij-server", @@ -2469,8 +2647,13 @@ dependencies = [ "cassowary", "daemonize", "insta", + "log", + "serde", + "serde_derive", "serde_json", + "typetag", "unicode-width", + "wasm-bindgen", "wasmer", "wasmer-wasi", "zellij-utils", @@ -2480,6 +2663,7 @@ dependencies = [ name = "zellij-tile" version = "0.14.0" dependencies = [ + "log", "serde", "serde_json", "strum", @@ -2506,6 +2690,8 @@ dependencies = [ "interprocess", "lazy_static", "libc", + "log", + "log4rs", "nix", "once_cell", "serde", @@ -2516,6 +2702,7 @@ dependencies = [ "strum", "tempfile", "termion", + "typetag", "vte 0.10.1", "zellij-tile", ] diff --git a/Cargo.toml b/Cargo.toml index 16525452..b14e7095 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ names = "0.11.0" zellij-client = { path = "zellij-client/", version = "0.14.0" } zellij-server = { path = "zellij-server/", version = "0.14.0" } zellij-utils = { path = "zellij-utils/", version = "0.14.0" } +log = "0.4.14" [dev-dependencies] insta = { version = "1.6.0", features = ["backtrace"] } diff --git a/default-plugins/strider/src/main.rs b/default-plugins/strider/src/main.rs index 8edc1e19..d73f674f 100644 --- a/default-plugins/strider/src/main.rs +++ b/default-plugins/strider/src/main.rs @@ -9,11 +9,14 @@ register_plugin!(State); impl ZellijPlugin for State { fn load(&mut self) { + dbg!("hello from load"); refresh_directory(self); subscribe(&[EventType::KeyPress]); } fn update(&mut self, event: Event) { + dbg!("hello from update"); + if let Event::KeyPress(key) = event { match key { Key::Up | Key::Char('k') => { diff --git a/src/main.rs b/src/main.rs index 6bcfa872..67b9419b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ mod sessions; mod tests; use crate::install::populate_data_dir; +use log::info; use sessions::{assert_session, assert_session_ne, get_active_session, list_sessions}; use std::convert::TryFrom; use std::process; @@ -21,6 +22,8 @@ use zellij_utils::{ }; pub fn main() { + configure_logger(); + info!("Hello Zellij!"); let opts = CliArgs::from_args(); if let Some(Command::Sessions(Sessions::ListSessions)) = opts.command { diff --git a/zellij-server/Cargo.toml b/zellij-server/Cargo.toml index 1a99bb40..d06745de 100644 --- a/zellij-server/Cargo.toml +++ b/zellij-server/Cargo.toml @@ -16,8 +16,13 @@ serde_json = "1.0" unicode-width = "0.1.8" wasmer = "1.0.0" wasmer-wasi = "1.0.0" +wasm-bindgen = { version = "0.2", features = ["serde-serialize"] } cassowary = "0.3.0" zellij-utils = { path = "../zellij-utils/", version = "0.14.0" } +log = "0.4.14" +serde_derive = "1.0.80" +serde = "1.0.126" +typetag = "0.1.7" [dev-dependencies] insta = "1.6.0" diff --git a/zellij-server/src/decorating_pipe.rs b/zellij-server/src/decorating_pipe.rs new file mode 100644 index 00000000..4b95c57b --- /dev/null +++ b/zellij-server/src/decorating_pipe.rs @@ -0,0 +1,94 @@ +use std::{ + collections::VecDeque, + io::{Read, Seek, Write}, +}; + +use log::info; +use serde::{Deserialize, Serialize}; +use wasmer_wasi::{WasiFile, WasiFsError}; + +#[derive(Debug, Serialize, Deserialize)] +pub struct DecoratingPipe { + buffer: VecDeque, + plugin_name: String, +} + +impl DecoratingPipe { + pub fn new(plugin_name: &str) -> DecoratingPipe { + info!("Creating decorating pipe!"); + dbg!("Creating the decorating pipe :)"); + DecoratingPipe { + buffer: VecDeque::new(), + plugin_name: String::from(plugin_name), + } + } +} + +impl Read for DecoratingPipe { + fn read(&mut self, buf: &mut [u8]) -> std::io::Result { + let amt = std::cmp::min(buf.len(), self.buffer.len()); + for (i, byte) in self.buffer.drain(..amt).enumerate() { + buf[i] = byte; + } + Ok(amt) + } +} + +// TODO: do this better. We're not sure about byte boundaries and endl stuff but, we do expect +// to get the valid thing eventually +impl Write for DecoratingPipe { + fn write(&mut self, buf: &[u8]) -> std::io::Result { + self.buffer.extend(buf); + let current_chunk = std::str::from_utf8(buf).unwrap(); + for c in current_chunk.chars() { + if c == '\n' { + info!( + "{}: {}", + self.plugin_name, + std::str::from_utf8(&self.buffer.make_contiguous().split_last().unwrap().1) + .unwrap() + ); + self.buffer.clear(); + } + } + Ok(buf.len()) + } + fn flush(&mut self) -> std::io::Result<()> { + Ok(()) + } +} + +impl Seek for DecoratingPipe { + fn seek(&mut self, _pos: std::io::SeekFrom) -> std::io::Result { + Err(std::io::Error::new( + std::io::ErrorKind::Other, + "can not seek in a pipe", + )) + } +} + +#[typetag::serde] +impl WasiFile for DecoratingPipe { + fn last_accessed(&self) -> u64 { + 0 + } + fn last_modified(&self) -> u64 { + 0 + } + fn created_time(&self) -> u64 { + 0 + } + fn size(&self) -> u64 { + self.buffer.len() as u64 + } + fn set_len(&mut self, len: u64) -> Result<(), WasiFsError> { + self.buffer.resize(len as usize, 0); + Ok(()) + } + fn unlink(&mut self) -> Result<(), WasiFsError> { + Ok(()) + } + fn bytes_available(&self) -> Result { + Ok(self.buffer.len()) + } +} diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index 27872b64..9ea35e23 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -2,6 +2,7 @@ pub mod os_input_output; pub mod panes; pub mod tab; +mod decorating_pipe; mod pty; mod route; mod screen; @@ -9,6 +10,7 @@ mod thread_bus; mod ui; mod wasm_vm; +use log::info; use zellij_utils::zellij_tile; use std::path::PathBuf; @@ -108,6 +110,7 @@ pub(crate) enum SessionState { } pub fn start_server(os_input: Box, socket_path: PathBuf) { + info!("starts server"); #[cfg(not(any(feature = "test", test)))] daemonize::Daemonize::new() .working_directory(std::env::current_dir().unwrap()) diff --git a/zellij-server/src/wasm_vm.rs b/zellij-server/src/wasm_vm.rs index 62198d68..14823e52 100644 --- a/zellij-server/src/wasm_vm.rs +++ b/zellij-server/src/wasm_vm.rs @@ -1,5 +1,8 @@ +use log::info; +use serde::{de::DeserializeOwned, Serialize}; use std::collections::{HashMap, HashSet}; use std::fs; +use std::io::{Read, Write}; use std::path::PathBuf; use std::process; use std::str::FromStr; @@ -9,7 +12,6 @@ use std::time::{Duration, Instant}; use zellij_utils::{serde, zellij_tile}; -use serde::{de::DeserializeOwned, Serialize}; use wasmer::{ imports, ChainableNamedResolver, Function, ImportObject, Instance, Module, Store, Value, WasmerEnv, @@ -18,6 +20,7 @@ use wasmer_wasi::{Pipe, WasiEnv, WasiState}; use zellij_tile::data::{Event, EventType, PluginIds}; use crate::{ + decorating_pipe::DecoratingPipe, panes::PaneId, pty::PtyInstruction, screen::ScreenInstruction, @@ -56,6 +59,7 @@ pub(crate) struct PluginEnv { // Thread main -------------------------------------------------------------------------------------------------------- pub(crate) fn wasm_thread_main(bus: Bus, store: Store, data_dir: PathBuf) { + info!("Wasm create thread :))"); let mut plugin_id = 0; let mut plugin_map = HashMap::new(); loop { @@ -74,6 +78,8 @@ pub(crate) fn wasm_thread_main(bus: Bus, store: Store, data_d let output = Pipe::new(); let input = Pipe::new(); + let stderr = + DecoratingPipe::new(path.as_path().file_name().unwrap().to_str().unwrap()); let mut wasi_env = WasiState::new("Zellij") .env("CLICOLOR_FORCE", "1") .preopen(|p| { @@ -86,6 +92,7 @@ pub(crate) fn wasm_thread_main(bus: Bus, store: Store, data_d .unwrap() .stdin(Box::new(input)) .stdout(Box::new(output)) + .stderr(Box::new(stderr)) .finalize() .unwrap(); diff --git a/zellij-tile/Cargo.toml b/zellij-tile/Cargo.toml index 93bc3a61..a2aaab1f 100644 --- a/zellij-tile/Cargo.toml +++ b/zellij-tile/Cargo.toml @@ -11,3 +11,4 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" strum = "0.20.0" strum_macros = "0.20.0" +log = "0.4.14" diff --git a/zellij-utils/Cargo.toml b/zellij-utils/Cargo.toml index 16aab07d..42a74d54 100644 --- a/zellij-utils/Cargo.toml +++ b/zellij-utils/Cargo.toml @@ -28,6 +28,9 @@ strum = "0.20.0" termion = "1.5.0" vte = "0.10.1" zellij-tile = { path = "../zellij-tile/", version = "0.14.0" } +log = "0.4.14" +typetag = "0.1.7" +log4rs = "1.0.0" [dependencies.async-std] version = "1.3.0" diff --git a/zellij-utils/assets/config/log4rs.yml b/zellij-utils/assets/config/log4rs.yml new file mode 100644 index 00000000..a10aec55 --- /dev/null +++ b/zellij-utils/assets/config/log4rs.yml @@ -0,0 +1,42 @@ +# Scan this file for changes every 30 seconds +refresh_rate: 30 seconds + +appenders: + # An appender named "stdout" that writes to stdout + stderr: + kind: console + target: stderr + + logFile: + kind: file + path: "zellij.log" + append: false + encoder: + pattern: "{h(|{M}| {d} {l} [{T}] [{f}:{L}]: {m})} {n}" + + logPlugin: + kind: file + path: "zellij.log" + encoder: + pattern: "{m} {n}" + + # An appender named "requests" that writes to a file with a custom pattern encoder + requests: + kind: file + path: "requests.log" + encoder: + pattern: "{d} - {m}{n}" + +# Set the default logging level to "warn" and attach the "stdout" appender to the root +root: + level: info + appenders: + - logFile + +loggers: + # Raise the maximum log level for events sent to the "app::backend::db" logger to "info" + zellij_server::decorating_pipe: + level: trace + appenders: + - logPlugin + additive: false diff --git a/zellij-utils/src/logging.rs b/zellij-utils/src/logging.rs index 6d415e38..eb736142 100644 --- a/zellij-utils/src/logging.rs +++ b/zellij-utils/src/logging.rs @@ -1,15 +1,23 @@ //! Zellij logging utility functions. use std::{ - fs, + fs::{self, OpenOptions}, io::{self, prelude::*}, os::unix::io::RawFd, path::{Path, PathBuf}, + thread, }; +use log::info; + use crate::consts::{ZELLIJ_TMP_LOG_DIR, ZELLIJ_TMP_LOG_FILE}; use crate::shared::set_permissions; +pub fn configure_logger() { + log4rs::init_file("zellij-utils/assets/config/log4rs.yml", Default::default()).unwrap(); + info!("Zellij logger initialized"); +} + pub fn atomic_create_file(file_name: &Path) -> io::Result<()> { let _ = fs::OpenOptions::new() .append(true) From 13dd44557449919ca434ca2c919dc4b8e4d09bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Palenica?= Date: Tue, 6 Jul 2021 23:41:37 -0700 Subject: [PATCH 02/33] Some progress on decorating pipe. Add some logic to handle endl in plugin messages. Basic logging from plugins works now. --- default-plugins/status-bar/src/main.rs | 1 + default-plugins/strider/src/main.rs | 1 + zellij-server/src/decorating_pipe.rs | 72 +++++++++++++++++++++----- zellij-tile/src/lib.rs | 1 + 4 files changed, 61 insertions(+), 14 deletions(-) diff --git a/default-plugins/status-bar/src/main.rs b/default-plugins/status-bar/src/main.rs index 83eb50c9..e9e60fc3 100644 --- a/default-plugins/status-bar/src/main.rs +++ b/default-plugins/status-bar/src/main.rs @@ -133,6 +133,7 @@ fn color_elements(palette: Palette) -> ColoredElements { impl ZellijPlugin for State { fn load(&mut self) { + dbg!("hello from load"); set_selectable(false); set_invisible_borders(true); set_fixed_height(2); diff --git a/default-plugins/strider/src/main.rs b/default-plugins/strider/src/main.rs index d73f674f..7d80f014 100644 --- a/default-plugins/strider/src/main.rs +++ b/default-plugins/strider/src/main.rs @@ -10,6 +10,7 @@ register_plugin!(State); impl ZellijPlugin for State { fn load(&mut self) { dbg!("hello from load"); + dbg!("hello from load2?"); refresh_directory(self); subscribe(&[EventType::KeyPress]); } diff --git a/zellij-server/src/decorating_pipe.rs b/zellij-server/src/decorating_pipe.rs index 4b95c57b..fb02ce6a 100644 --- a/zellij-server/src/decorating_pipe.rs +++ b/zellij-server/src/decorating_pipe.rs @@ -3,9 +3,10 @@ use std::{ io::{Read, Seek, Write}, }; -use log::info; +use log::{error, info}; use serde::{Deserialize, Serialize}; use wasmer_wasi::{WasiFile, WasiFsError}; +use zellij_utils::logging::debug_log_to_file; #[derive(Debug, Serialize, Deserialize)] pub struct DecoratingPipe { @@ -16,7 +17,7 @@ pub struct DecoratingPipe { impl DecoratingPipe { pub fn new(plugin_name: &str) -> DecoratingPipe { info!("Creating decorating pipe!"); - dbg!("Creating the decorating pipe :)"); + debug_log_to_file("Creating decorating pipe!".to_string()).expect("xd"); DecoratingPipe { buffer: VecDeque::new(), plugin_name: String::from(plugin_name), @@ -39,21 +40,64 @@ impl Read for DecoratingPipe { impl Write for DecoratingPipe { fn write(&mut self, buf: &[u8]) -> std::io::Result { self.buffer.extend(buf); - let current_chunk = std::str::from_utf8(buf).unwrap(); - for c in current_chunk.chars() { - if c == '\n' { - info!( - "{}: {}", - self.plugin_name, - std::str::from_utf8(&self.buffer.make_contiguous().split_last().unwrap().1) - .unwrap() - ); - self.buffer.clear(); - } - } + + debug_log_to_file(format!( + "Write called for {}, currentChunk: {}", + self.plugin_name, + std::str::from_utf8(buf).unwrap() + )) + .expect("xd2"); + Ok(buf.len()) } + + // When we flush, check if current buffer is valid utf8 string, split by '\n' and truncate buffer in the process. + // We assume that, eventually, flush will be called on valid string boundary (i.e. std::str::from_utf8(..).is_ok() returns true at some point). + // Above assumption might not be true, in which case we'll have to think about it. Also, at some point we might actually require some synchronization + // between write and flush (i.e. concurrent writes and flushes?). Make it simple for now. fn flush(&mut self) -> std::io::Result<()> { + debug_log_to_file(format!( + "Flush called for {}, buffer: {:?}", + self.plugin_name, self.buffer + )) + .expect("xd3"); + + self.buffer.make_contiguous(); + + if let Ok(converted_string) = std::str::from_utf8(self.buffer.as_slices().0) { + if converted_string.contains('\n') { + let mut consumed_bytes = 0; + let mut split_msg = converted_string.split('\n').peekable(); + debug_log_to_file(format!( + "Back: {}, len: {}, convertedString: {}", + split_msg.clone().collect::(), + split_msg.clone().count(), + converted_string + )) + .expect("xD"); + while let Some(msg) = split_msg.next() { + if split_msg.peek().is_none() { + // Log last chunk iff the last char is endline. Otherwise do not do it. + if converted_string.chars().last().unwrap() == '\n' && !msg.is_empty() { + info!("special case: {}: {}", self.plugin_name, msg); + consumed_bytes += msg.len() + 1; + } + } else { + info!("normal case: {}: {}", self.plugin_name, msg); + consumed_bytes += msg.len() + 1; + } + } + drop(self.buffer.drain(..consumed_bytes)); + debug_log_to_file(format!( + "Consumed: {} bytes, buffer: {:?}", + consumed_bytes, self.buffer + )) + .expect("xd4"); + } + } else { + error!("Buffer conversion didn't work. This is unexpected"); + } + Ok(()) } } diff --git a/zellij-tile/src/lib.rs b/zellij-tile/src/lib.rs index af7d8ca1..176a9497 100644 --- a/zellij-tile/src/lib.rs +++ b/zellij-tile/src/lib.rs @@ -19,6 +19,7 @@ macro_rules! register_plugin { } fn main() { + dbg!("hello from plugin main :)"); STATE.with(|state| { state.borrow_mut().load(); }); From 46cac59d4cc10b3f48c9995d857b7fe54fdb6e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Palenica?= Date: Wed, 7 Jul 2021 22:54:38 -0700 Subject: [PATCH 03/33] Add unit tests for decorating pipe and clean it up a bit --- zellij-server/src/decorating_pipe.rs | 129 ++++++++++++++++++--------- 1 file changed, 89 insertions(+), 40 deletions(-) diff --git a/zellij-server/src/decorating_pipe.rs b/zellij-server/src/decorating_pipe.rs index fb02ce6a..49517629 100644 --- a/zellij-server/src/decorating_pipe.rs +++ b/zellij-server/src/decorating_pipe.rs @@ -6,7 +6,6 @@ use std::{ use log::{error, info}; use serde::{Deserialize, Serialize}; use wasmer_wasi::{WasiFile, WasiFsError}; -use zellij_utils::logging::debug_log_to_file; #[derive(Debug, Serialize, Deserialize)] pub struct DecoratingPipe { @@ -17,7 +16,6 @@ pub struct DecoratingPipe { impl DecoratingPipe { pub fn new(plugin_name: &str) -> DecoratingPipe { info!("Creating decorating pipe!"); - debug_log_to_file("Creating decorating pipe!".to_string()).expect("xd"); DecoratingPipe { buffer: VecDeque::new(), plugin_name: String::from(plugin_name), @@ -35,64 +33,37 @@ impl Read for DecoratingPipe { } } -// TODO: do this better. We're not sure about byte boundaries and endl stuff but, we do expect -// to get the valid thing eventually impl Write for DecoratingPipe { fn write(&mut self, buf: &[u8]) -> std::io::Result { self.buffer.extend(buf); - debug_log_to_file(format!( - "Write called for {}, currentChunk: {}", - self.plugin_name, - std::str::from_utf8(buf).unwrap() - )) - .expect("xd2"); - Ok(buf.len()) } // When we flush, check if current buffer is valid utf8 string, split by '\n' and truncate buffer in the process. - // We assume that, eventually, flush will be called on valid string boundary (i.e. std::str::from_utf8(..).is_ok() returns true at some point). - // Above assumption might not be true, in which case we'll have to think about it. Also, at some point we might actually require some synchronization - // between write and flush (i.e. concurrent writes and flushes?). Make it simple for now. + // We assume that eventually, flush will be called on valid string boundary (i.e. std::str::from_utf8(..).is_ok() returns true at some point). + // Above assumption might not be true, in which case we'll have to think about it. Make it simple for now. fn flush(&mut self) -> std::io::Result<()> { - debug_log_to_file(format!( - "Flush called for {}, buffer: {:?}", - self.plugin_name, self.buffer - )) - .expect("xd3"); - self.buffer.make_contiguous(); - if let Ok(converted_string) = std::str::from_utf8(self.buffer.as_slices().0) { - if converted_string.contains('\n') { + if let Ok(converted_buffer) = std::str::from_utf8(self.buffer.as_slices().0) { + if converted_buffer.contains('\n') { let mut consumed_bytes = 0; - let mut split_msg = converted_string.split('\n').peekable(); - debug_log_to_file(format!( - "Back: {}, len: {}, convertedString: {}", - split_msg.clone().collect::(), - split_msg.clone().count(), - converted_string - )) - .expect("xD"); - while let Some(msg) = split_msg.next() { - if split_msg.peek().is_none() { + let mut split_converted_buffer = converted_buffer.split('\n').peekable(); + + while let Some(msg) = split_converted_buffer.next() { + if split_converted_buffer.peek().is_none() { // Log last chunk iff the last char is endline. Otherwise do not do it. - if converted_string.chars().last().unwrap() == '\n' && !msg.is_empty() { - info!("special case: {}: {}", self.plugin_name, msg); + if converted_buffer.chars().last().unwrap() == '\n' && !msg.is_empty() { + info!("{}: {}", self.plugin_name, msg); consumed_bytes += msg.len() + 1; } } else { - info!("normal case: {}: {}", self.plugin_name, msg); + info!("{}: {}", self.plugin_name, msg); consumed_bytes += msg.len() + 1; } } drop(self.buffer.drain(..consumed_bytes)); - debug_log_to_file(format!( - "Consumed: {} bytes, buffer: {:?}", - consumed_bytes, self.buffer - )) - .expect("xd4"); } } else { error!("Buffer conversion didn't work. This is unexpected"); @@ -136,3 +107,81 @@ impl WasiFile for DecoratingPipe { Ok(self.buffer.len()) } } + +// Unit tests +#[cfg(test)] +mod decorating_pipe_test { + + use super::*; + + #[test] + fn write_without_endl_does_not_consume_buffer_after_flush() { + let mut pipe = DecoratingPipe::new("TestPipe"); + + let test_buffer = "Testing write".as_bytes(); + + pipe.write(test_buffer).expect("Err write"); + pipe.flush().expect("Err flush"); + + assert_eq!(pipe.buffer.len(), test_buffer.len()); + } + + #[test] + fn write_with_single_endl_at_the_end_consumes_whole_buffer_after_flush() { + let mut pipe = DecoratingPipe::new("TestPipe"); + + let test_buffer = "Testing write \n".as_bytes(); + + pipe.write(test_buffer).expect("Err write"); + pipe.flush().expect("Err flush"); + + assert_eq!(pipe.buffer.len(), 0); + } + + #[test] + fn write_with_endl_in_the_middle_consumes_buffer_up_to_endl_after_flush() { + let mut pipe = DecoratingPipe::new("TestPipe"); + + let test_buffer = "Testing write \n".as_bytes(); + let test_buffer2 = "And the rest".as_bytes(); + + pipe.write( + [ + test_buffer, + test_buffer, + test_buffer, + test_buffer, + test_buffer2, + ] + .concat() + .as_slice(), + ) + .expect("Err write"); + pipe.flush().expect("Err flush"); + + assert_eq!(pipe.buffer.len(), test_buffer2.len()); + } + + #[test] + fn write_with_many_endl_consumes_whole_buffer_after_flush() { + let mut pipe = DecoratingPipe::new("TestPipe"); + + let test_buffer = "Testing write \n".as_bytes(); + + pipe.write( + [ + test_buffer, + test_buffer, + test_buffer, + test_buffer, + test_buffer, + ] + .concat() + .as_slice(), + ) + .expect("Err write"); + pipe.flush().expect("Err flush"); + + assert_eq!(pipe.buffer.len(), 0); + } +} From 21b88281ce6d70d2473fdbf02b6642d67bba8a0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Palenica?= Date: Wed, 7 Jul 2021 23:14:50 -0700 Subject: [PATCH 04/33] Add test case for malformed input and detect too long messages --- zellij-server/src/decorating_pipe.rs | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/zellij-server/src/decorating_pipe.rs b/zellij-server/src/decorating_pipe.rs index 49517629..0d5d2f51 100644 --- a/zellij-server/src/decorating_pipe.rs +++ b/zellij-server/src/decorating_pipe.rs @@ -7,6 +7,8 @@ use log::{error, info}; use serde::{Deserialize, Serialize}; use wasmer_wasi::{WasiFile, WasiFsError}; +// 16kB log buffer +const ZELLIJ_MAX_PIPE_BUFFER_SIZE: usize = 16_384; #[derive(Debug, Serialize, Deserialize)] pub struct DecoratingPipe { buffer: VecDeque, @@ -37,6 +39,19 @@ impl Write for DecoratingPipe { fn write(&mut self, buf: &[u8]) -> std::io::Result { self.buffer.extend(buf); + if self.buffer.len() > ZELLIJ_MAX_PIPE_BUFFER_SIZE { + let error_msg = + "Exceeded log buffer size. Make sure that your plugin calls flush on stderr on \ + valid UTF-8 symbol boundary. Aditionally, make sure that your log message contains \ + endline \\n symbol."; + error!("{}: {}", self.plugin_name, error_msg); + self.buffer.clear(); + return Err(std::io::Error::new( + std::io::ErrorKind::InvalidData, + error_msg, + )); + } + Ok(buf.len()) } @@ -184,4 +199,22 @@ mod decorating_pipe_test { assert_eq!(pipe.buffer.len(), 0); } + + #[test] + fn write_with_incorrect_byte_boundary_does_not_crash() { + let mut pipe = DecoratingPipe::new("TestPipe"); + + let test_buffer = "😱".as_bytes(); + + // make sure it's not valid utf-8 string if we drop last symbol + assert!(std::str::from_utf8(&test_buffer[..test_buffer.len() - 1]).is_err()); + + pipe.write(&test_buffer[..test_buffer.len() - 1]) + .expect("Err write"); + pipe.flush().expect("Err flush"); + + assert_eq!(pipe.buffer.len(), test_buffer.len() - 1); + + println!("len: {}, buf: {:?}", test_buffer.len(), test_buffer); + } } From ba21b86435a390342893dc0e43a69532fc39bb77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Palenica?= Date: Wed, 7 Jul 2021 23:27:07 -0700 Subject: [PATCH 05/33] Cleanup log config file a bit, make format verbose so everyone can understand it without looking into log4rs docs --- zellij-utils/assets/config/log4rs.yml | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/zellij-utils/assets/config/log4rs.yml b/zellij-utils/assets/config/log4rs.yml index a10aec55..01934f40 100644 --- a/zellij-utils/assets/config/log4rs.yml +++ b/zellij-utils/assets/config/log4rs.yml @@ -7,34 +7,37 @@ appenders: kind: console target: stderr + # default zellij appender, should be used across most of the codebase. logFile: kind: file path: "zellij.log" append: false encoder: - pattern: "{h(|{M}| {d} {l} [{T}] [{f}:{L}]: {m})} {n}" + # {n} means platform dependent newline + pattern: "|{module}| {date} {highlight({level})} [{thread}] [{file}:{line}]: {message} {n}" + # plugin appender. To be used in decorating_pipe to forward stderr output from plugins. logPlugin: kind: file path: "zellij.log" encoder: - pattern: "{m} {n}" + # {n} means platform dependent newline + pattern: "{message} {n}" - # An appender named "requests" that writes to a file with a custom pattern encoder - requests: - kind: file - path: "requests.log" - encoder: - pattern: "{d} - {m}{n}" - -# Set the default logging level to "warn" and attach the "stdout" appender to the root +# Set the default logging level to "info" and log it to zellij.log file root: level: info appenders: - logFile loggers: - # Raise the maximum log level for events sent to the "app::backend::db" logger to "info" + # decrease verbosity for this module because it has a lot of useless info logs + wasmer_compiler_cranelift: + level: warn + appenders: + - logFile + + # For decorating_pipe, we use custom format as we use logging macros to forward stderr output from plugins zellij_server::decorating_pipe: level: trace appenders: From 4fcf558156dec6cfebd9fc6ba8605594369fded6 Mon Sep 17 00:00:00 2001 From: Lovecraftian Horror Date: Thu, 8 Jul 2021 14:16:25 -0400 Subject: [PATCH 06/33] Display session name within session --- default-plugins/tab-bar/src/line.rs | 11 +++++-- default-plugins/tab-bar/src/main.rs | 1 + zellij-server/src/lib.rs | 5 ++- zellij-server/src/route.rs | 7 ++-- zellij-server/src/screen.rs | 11 +++---- zellij-tile/src/data.rs | 44 +++++++++++++++++++++++++ zellij-utils/src/input/mod.rs | 51 +---------------------------- 7 files changed, 64 insertions(+), 66 deletions(-) diff --git a/default-plugins/tab-bar/src/line.rs b/default-plugins/tab-bar/src/line.rs index cad5b720..3ebeaac3 100644 --- a/default-plugins/tab-bar/src/line.rs +++ b/default-plugins/tab-bar/src/line.rs @@ -144,8 +144,12 @@ fn add_next_tabs_msg( title_bar.push(right_more_message); } -fn tab_line_prefix(palette: Palette) -> LinePart { - let prefix_text = " Zellij ".to_string(); +fn tab_line_prefix(session_name: Option<&str>, palette: Palette) -> LinePart { + let mut prefix_text = " Zellij ".to_string(); + if let Some(name) = session_name { + prefix_text.push_str(&format!("({}) ", name)); + } + let prefix_text_len = prefix_text.chars().count(); let prefix_styled_text = style!(palette.white, palette.cyan) .bold() @@ -165,6 +169,7 @@ pub fn tab_separator(capabilities: PluginCapabilities) -> &'static str { } pub fn tab_line( + session_name: Option<&str>, mut all_tabs: Vec, active_tab_index: usize, cols: usize, @@ -181,7 +186,7 @@ pub fn tab_line( }; tabs_to_render.push(active_tab); - let prefix = tab_line_prefix(palette); + let prefix = tab_line_prefix(session_name, palette); populate_tabs_in_tab_line( &mut tabs_before_active, &mut tabs_after_active, diff --git a/default-plugins/tab-bar/src/main.rs b/default-plugins/tab-bar/src/main.rs index 1f83dcde..a185ccc3 100644 --- a/default-plugins/tab-bar/src/main.rs +++ b/default-plugins/tab-bar/src/main.rs @@ -64,6 +64,7 @@ impl ZellijPlugin for State { all_tabs.push(tab); } let tab_line = tab_line( + self.mode_info.session_name.as_deref(), all_tabs, active_tab_index, cols, diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index 660acdc9..a15eb4c9 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -15,7 +15,7 @@ use std::path::PathBuf; use std::sync::{Arc, Mutex, RwLock}; use std::thread; use wasmer::Store; -use zellij_tile::data::{Event, Palette, PluginCapabilities}; +use zellij_tile::data::{Event, ModeInfo, Palette, PluginCapabilities}; use crate::{ os_input_output::ServerOsApi, @@ -31,7 +31,6 @@ use zellij_utils::{ errors::{ContextType, ErrorInstruction, ServerContext}, input::{ command::{RunCommand, TerminalAction}, - get_mode_info, layout::Layout, options::Options, }, @@ -235,7 +234,7 @@ pub fn start_server(os_input: Box, socket_path: PathBuf) { .unwrap(); let default_mode = options.default_mode.unwrap_or_default(); let mode_info = - get_mode_info(default_mode, attrs.palette, session_data.capabilities); + ModeInfo::new(default_mode, attrs.palette, session_data.capabilities); session_data .senders .send_to_screen(ScreenInstruction::ChangeMode(mode_info.clone())) diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index 22d843f0..0796ac74 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -1,6 +1,6 @@ use std::sync::{Arc, RwLock}; -use zellij_utils::zellij_tile::data::Event; +use zellij_utils::zellij_tile::data::{Event, ModeInfo}; use crate::{ os_input_output::ServerOsApi, pty::PtyInstruction, screen::ScreenInstruction, @@ -11,7 +11,6 @@ use zellij_utils::{ input::{ actions::{Action, Direction}, command::TerminalAction, - get_mode_info, }, ipc::{ClientToServerMsg, ExitReason, ServerToClientMsg}, }; @@ -43,12 +42,12 @@ fn route_action( .senders .send_to_plugin(PluginInstruction::Update( None, - Event::ModeUpdate(get_mode_info(mode, palette, session.capabilities)), + Event::ModeUpdate(ModeInfo::new(mode, palette, session.capabilities)), )) .unwrap(); session .senders - .send_to_screen(ScreenInstruction::ChangeMode(get_mode_info( + .send_to_screen(ScreenInstruction::ChangeMode(ModeInfo::new( mode, palette, session.capabilities, diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index 9005d795..9f5435de 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -434,14 +434,13 @@ pub(crate) fn screen_thread_main( bus, &client_attributes, max_panes, - ModeInfo { - palette: client_attributes.palette, - capabilities: PluginCapabilities { + ModeInfo::new( + default_mode, + client_attributes.palette, + PluginCapabilities { arrow_fonts: capabilities, }, - mode: default_mode, - ..ModeInfo::default() - }, + ), default_mode, session_state, ); diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs index 4e4b6823..48ef4df9 100644 --- a/zellij-tile/src/data.rs +++ b/zellij-tile/src/data.rs @@ -148,6 +148,50 @@ pub struct ModeInfo { pub keybinds: Vec<(String, String)>, // => pub palette: Palette, pub capabilities: PluginCapabilities, + pub session_name: Option, +} + +impl ModeInfo { + /// Creates a [`ModeInfo`] struct indicating the current [`InputMode`] and its keybinds + /// (as pairs of [`String`]s). + pub fn new(mode: InputMode, palette: Palette, capabilities: PluginCapabilities) -> Self { + 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(); + + Self { + mode, + keybinds, + palette, + capabilities, + session_name, + } + } } #[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] diff --git a/zellij-utils/src/input/mod.rs b/zellij-utils/src/input/mod.rs index 11c5a843..e037fe66 100644 --- a/zellij-utils/src/input/mod.rs +++ b/zellij-utils/src/input/mod.rs @@ -10,56 +10,7 @@ pub mod options; 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 -/// (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())); - } - } - ModeInfo { - mode, - keybinds, - palette, - capabilities, - } -} +use zellij_tile::data::Key; pub fn parse_keys(input_bytes: &[u8]) -> Vec { input_bytes.keys().flatten().map(cast_termion_key).collect() From 13b5d1e58fce574240bebec8721460f7b8636f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Palenica?= Date: Thu, 8 Jul 2021 21:43:19 -0700 Subject: [PATCH 07/33] Add padding to logger --- zellij-server/src/decorating_pipe.rs | 6 +++--- zellij-utils/assets/config/log4rs.yml | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/zellij-server/src/decorating_pipe.rs b/zellij-server/src/decorating_pipe.rs index 0d5d2f51..7f68f50c 100644 --- a/zellij-server/src/decorating_pipe.rs +++ b/zellij-server/src/decorating_pipe.rs @@ -17,7 +17,7 @@ pub struct DecoratingPipe { impl DecoratingPipe { pub fn new(plugin_name: &str) -> DecoratingPipe { - info!("Creating decorating pipe!"); + info!("Creating decorating pipe for plugin: {}!", plugin_name); DecoratingPipe { buffer: VecDeque::new(), plugin_name: String::from(plugin_name), @@ -70,11 +70,11 @@ impl Write for DecoratingPipe { if split_converted_buffer.peek().is_none() { // Log last chunk iff the last char is endline. Otherwise do not do it. if converted_buffer.chars().last().unwrap() == '\n' && !msg.is_empty() { - info!("{}: {}", self.plugin_name, msg); + info!("|{:<25}| {}", self.plugin_name, msg); consumed_bytes += msg.len() + 1; } } else { - info!("{}: {}", self.plugin_name, msg); + info!("|{:<25}| {}", self.plugin_name, msg); consumed_bytes += msg.len() + 1; } } diff --git a/zellij-utils/assets/config/log4rs.yml b/zellij-utils/assets/config/log4rs.yml index 01934f40..5a60b973 100644 --- a/zellij-utils/assets/config/log4rs.yml +++ b/zellij-utils/assets/config/log4rs.yml @@ -2,7 +2,7 @@ refresh_rate: 30 seconds appenders: - # An appender named "stdout" that writes to stdout + # An appender named "stderr" that writes to stderr stderr: kind: console target: stderr @@ -14,7 +14,8 @@ appenders: append: false encoder: # {n} means platform dependent newline - pattern: "|{module}| {date} {highlight({level})} [{thread}] [{file}:{line}]: {message} {n}" + # module is padded to *at least* 25 bytes and thread is padded to be between 10 and 15 bytes. + pattern: "|{module:<25}| {date} {highlight({level})} [{thread:<10.15}] [{file}:{line}]: {message} {n}" # plugin appender. To be used in decorating_pipe to forward stderr output from plugins. logPlugin: From a076d9ef1437f21b67ca525d4f8bddbca7c14f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Palenica?= Date: Thu, 8 Jul 2021 21:49:56 -0700 Subject: [PATCH 08/33] Cleanup --- .gitignore | 3 ++- Cargo.lock | 5 ----- zellij-server/Cargo.toml | 1 - zellij-server/src/wasm_vm.rs | 5 ++--- zellij-tile/Cargo.toml | 3 +-- zellij-utils/Cargo.toml | 1 - zellij-utils/src/logging.rs | 3 +-- 7 files changed, 6 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 433d02d7..21a50829 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ .vim .DS_Store /assets/man/zellij.1 -**/target \ No newline at end of file +**/target +zellij.log \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 1a51077b..a55e40da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2277,8 +2277,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" dependencies = [ "cfg-if 1.0.0", - "serde", - "serde_json", "wasm-bindgen-macro", ] @@ -2653,7 +2651,6 @@ dependencies = [ "serde_json", "typetag", "unicode-width", - "wasm-bindgen", "wasmer", "wasmer-wasi", "zellij-utils", @@ -2663,7 +2660,6 @@ dependencies = [ name = "zellij-tile" version = "0.14.0" dependencies = [ - "log", "serde", "serde_json", "strum", @@ -2702,7 +2698,6 @@ dependencies = [ "strum", "tempfile", "termion", - "typetag", "vte 0.10.1", "zellij-tile", ] diff --git a/zellij-server/Cargo.toml b/zellij-server/Cargo.toml index d06745de..442360d9 100644 --- a/zellij-server/Cargo.toml +++ b/zellij-server/Cargo.toml @@ -16,7 +16,6 @@ serde_json = "1.0" unicode-width = "0.1.8" wasmer = "1.0.0" wasmer-wasi = "1.0.0" -wasm-bindgen = { version = "0.2", features = ["serde-serialize"] } cassowary = "0.3.0" zellij-utils = { path = "../zellij-utils/", version = "0.14.0" } log = "0.4.14" diff --git a/zellij-server/src/wasm_vm.rs b/zellij-server/src/wasm_vm.rs index 14823e52..0f676169 100644 --- a/zellij-server/src/wasm_vm.rs +++ b/zellij-server/src/wasm_vm.rs @@ -1,8 +1,6 @@ use log::info; -use serde::{de::DeserializeOwned, Serialize}; use std::collections::{HashMap, HashSet}; use std::fs; -use std::io::{Read, Write}; use std::path::PathBuf; use std::process; use std::str::FromStr; @@ -10,8 +8,9 @@ use std::sync::{mpsc::Sender, Arc, Mutex}; use std::thread; use std::time::{Duration, Instant}; -use zellij_utils::{serde, zellij_tile}; +use zellij_utils::zellij_tile; +use serde::{de::DeserializeOwned, Serialize}; use wasmer::{ imports, ChainableNamedResolver, Function, ImportObject, Instance, Module, Store, Value, WasmerEnv, diff --git a/zellij-tile/Cargo.toml b/zellij-tile/Cargo.toml index a2aaab1f..f4c73367 100644 --- a/zellij-tile/Cargo.toml +++ b/zellij-tile/Cargo.toml @@ -10,5 +10,4 @@ license = "MIT" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" strum = "0.20.0" -strum_macros = "0.20.0" -log = "0.4.14" +strum_macros = "0.20.0" \ No newline at end of file diff --git a/zellij-utils/Cargo.toml b/zellij-utils/Cargo.toml index 42a74d54..bf7c60af 100644 --- a/zellij-utils/Cargo.toml +++ b/zellij-utils/Cargo.toml @@ -29,7 +29,6 @@ termion = "1.5.0" vte = "0.10.1" zellij-tile = { path = "../zellij-tile/", version = "0.14.0" } log = "0.4.14" -typetag = "0.1.7" log4rs = "1.0.0" [dependencies.async-std] diff --git a/zellij-utils/src/logging.rs b/zellij-utils/src/logging.rs index eb736142..52e91497 100644 --- a/zellij-utils/src/logging.rs +++ b/zellij-utils/src/logging.rs @@ -1,11 +1,10 @@ //! Zellij logging utility functions. use std::{ - fs::{self, OpenOptions}, + fs, io::{self, prelude::*}, os::unix::io::RawFd, path::{Path, PathBuf}, - thread, }; use log::info; From 8d864e1fbf7408a840e2ac0ff3933f9d82fa1772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Palenica?= Date: Thu, 8 Jul 2021 21:53:22 -0700 Subject: [PATCH 09/33] remove one more crate from zellij-server --- Cargo.lock | 1 - zellij-server/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a55e40da..aa63b3f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2647,7 +2647,6 @@ dependencies = [ "insta", "log", "serde", - "serde_derive", "serde_json", "typetag", "unicode-width", diff --git a/zellij-server/Cargo.toml b/zellij-server/Cargo.toml index 442360d9..9cec6b8a 100644 --- a/zellij-server/Cargo.toml +++ b/zellij-server/Cargo.toml @@ -19,7 +19,6 @@ wasmer-wasi = "1.0.0" cassowary = "0.3.0" zellij-utils = { path = "../zellij-utils/", version = "0.14.0" } log = "0.4.14" -serde_derive = "1.0.80" serde = "1.0.126" typetag = "0.1.7" From 3b78d7d0a4781ca541b4e307afe37f4a0c4d4640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Palenica?= Date: Thu, 8 Jul 2021 22:01:03 -0700 Subject: [PATCH 10/33] More cleanup, remove serde from zellij-server --- Cargo.lock | 1 - zellij-server/Cargo.toml | 1 - zellij-server/src/decorating_pipe.rs | 5 ++++- zellij-server/src/wasm_vm.rs | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa63b3f1..6d23cea3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2646,7 +2646,6 @@ dependencies = [ "daemonize", "insta", "log", - "serde", "serde_json", "typetag", "unicode-width", diff --git a/zellij-server/Cargo.toml b/zellij-server/Cargo.toml index 9cec6b8a..1a671c3d 100644 --- a/zellij-server/Cargo.toml +++ b/zellij-server/Cargo.toml @@ -19,7 +19,6 @@ wasmer-wasi = "1.0.0" cassowary = "0.3.0" zellij-utils = { path = "../zellij-utils/", version = "0.14.0" } log = "0.4.14" -serde = "1.0.126" typetag = "0.1.7" [dev-dependencies] diff --git a/zellij-server/src/decorating_pipe.rs b/zellij-server/src/decorating_pipe.rs index 7f68f50c..65039139 100644 --- a/zellij-server/src/decorating_pipe.rs +++ b/zellij-server/src/decorating_pipe.rs @@ -4,12 +4,15 @@ use std::{ }; use log::{error, info}; -use serde::{Deserialize, Serialize}; use wasmer_wasi::{WasiFile, WasiFsError}; +use zellij_utils::serde; + +use serde::{Deserialize, Serialize}; // 16kB log buffer const ZELLIJ_MAX_PIPE_BUFFER_SIZE: usize = 16_384; #[derive(Debug, Serialize, Deserialize)] +#[serde(crate = "self::serde")] pub struct DecoratingPipe { buffer: VecDeque, plugin_name: String, diff --git a/zellij-server/src/wasm_vm.rs b/zellij-server/src/wasm_vm.rs index 0f676169..fe8f5be7 100644 --- a/zellij-server/src/wasm_vm.rs +++ b/zellij-server/src/wasm_vm.rs @@ -8,7 +8,7 @@ use std::sync::{mpsc::Sender, Arc, Mutex}; use std::thread; use std::time::{Duration, Instant}; -use zellij_utils::zellij_tile; +use zellij_utils::{serde, zellij_tile}; use serde::{de::DeserializeOwned, Serialize}; use wasmer::{ From 383446d025bc8fd8bcc87289daac3c61a117bd86 Mon Sep 17 00:00:00 2001 From: qepasa Date: Fri, 9 Jul 2021 07:56:20 +0200 Subject: [PATCH 11/33] Update Cargo.toml --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b6ac222d..a0fd188e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,6 @@ resolver = "2" [dependencies] names = "0.11.0" - zellij-client = { path = "zellij-client/", version = "0.15.0" } zellij-server = { path = "zellij-server/", version = "0.15.0" } zellij-utils = { path = "zellij-utils/", version = "0.15.0" } From a38c176646fcbe8f10d71c32e955674ffd7b669d Mon Sep 17 00:00:00 2001 From: qepasa Date: Fri, 9 Jul 2021 07:56:54 +0200 Subject: [PATCH 12/33] Update Cargo.toml --- zellij-utils/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/zellij-utils/Cargo.toml b/zellij-utils/Cargo.toml index 9520753b..b3f14886 100644 --- a/zellij-utils/Cargo.toml +++ b/zellij-utils/Cargo.toml @@ -31,7 +31,6 @@ zellij-tile = { path = "../zellij-tile/", version = "0.15.0" } log = "0.4.14" log4rs = "1.0.0" - [dependencies.async-std] version = "1.3.0" features = ["unstable"] From eb6e49c260be568800e76fd3276fc96ad909d4eb Mon Sep 17 00:00:00 2001 From: Lovecraftian Horror Date: Fri, 9 Jul 2021 15:21:47 -0400 Subject: [PATCH 13/33] Move `ModeInfo::new()` back to `get_mode_info()` --- zellij-server/src/lib.rs | 5 ++-- zellij-server/src/route.rs | 7 +++--- zellij-server/src/screen.rs | 4 +-- zellij-tile/src/data.rs | 43 -------------------------------- zellij-utils/src/input/mod.rs | 47 ++++++++++++++++++++++++++++++++++- 5 files changed, 55 insertions(+), 51 deletions(-) diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index a15eb4c9..660acdc9 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -15,7 +15,7 @@ use std::path::PathBuf; use std::sync::{Arc, Mutex, RwLock}; use std::thread; use wasmer::Store; -use zellij_tile::data::{Event, ModeInfo, Palette, PluginCapabilities}; +use zellij_tile::data::{Event, Palette, PluginCapabilities}; use crate::{ os_input_output::ServerOsApi, @@ -31,6 +31,7 @@ use zellij_utils::{ errors::{ContextType, ErrorInstruction, ServerContext}, input::{ command::{RunCommand, TerminalAction}, + get_mode_info, layout::Layout, options::Options, }, @@ -234,7 +235,7 @@ pub fn start_server(os_input: Box, socket_path: PathBuf) { .unwrap(); let default_mode = options.default_mode.unwrap_or_default(); let mode_info = - ModeInfo::new(default_mode, attrs.palette, session_data.capabilities); + get_mode_info(default_mode, attrs.palette, session_data.capabilities); session_data .senders .send_to_screen(ScreenInstruction::ChangeMode(mode_info.clone())) diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index 0796ac74..22d843f0 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -1,6 +1,6 @@ use std::sync::{Arc, RwLock}; -use zellij_utils::zellij_tile::data::{Event, ModeInfo}; +use zellij_utils::zellij_tile::data::Event; use crate::{ os_input_output::ServerOsApi, pty::PtyInstruction, screen::ScreenInstruction, @@ -11,6 +11,7 @@ use zellij_utils::{ input::{ actions::{Action, Direction}, command::TerminalAction, + get_mode_info, }, ipc::{ClientToServerMsg, ExitReason, ServerToClientMsg}, }; @@ -42,12 +43,12 @@ fn route_action( .senders .send_to_plugin(PluginInstruction::Update( None, - Event::ModeUpdate(ModeInfo::new(mode, palette, session.capabilities)), + Event::ModeUpdate(get_mode_info(mode, palette, session.capabilities)), )) .unwrap(); session .senders - .send_to_screen(ScreenInstruction::ChangeMode(ModeInfo::new( + .send_to_screen(ScreenInstruction::ChangeMode(get_mode_info( mode, palette, session.capabilities, diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index 9f5435de..9400599c 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -18,7 +18,7 @@ use crate::{ use zellij_tile::data::{Event, InputMode, ModeInfo, Palette, PluginCapabilities, TabInfo}; use zellij_utils::{ errors::{ContextType, ScreenContext}, - input::options::Options, + input::{get_mode_info, options::Options}, ipc::ClientAttributes, pane_size::PositionAndSize, }; @@ -434,7 +434,7 @@ pub(crate) fn screen_thread_main( bus, &client_attributes, max_panes, - ModeInfo::new( + get_mode_info( default_mode, client_attributes.palette, PluginCapabilities { diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs index 48ef4df9..cdf57e69 100644 --- a/zellij-tile/src/data.rs +++ b/zellij-tile/src/data.rs @@ -151,49 +151,6 @@ pub struct ModeInfo { pub session_name: Option, } -impl ModeInfo { - /// Creates a [`ModeInfo`] struct indicating the current [`InputMode`] and its keybinds - /// (as pairs of [`String`]s). - pub fn new(mode: InputMode, palette: Palette, capabilities: PluginCapabilities) -> Self { - 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(); - - Self { - mode, - keybinds, - palette, - capabilities, - session_name, - } - } -} - #[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct TabInfo { /* subset of fields to publish to plugins */ diff --git a/zellij-utils/src/input/mod.rs b/zellij-utils/src/input/mod.rs index e037fe66..746d5861 100644 --- a/zellij-utils/src/input/mod.rs +++ b/zellij-utils/src/input/mod.rs @@ -10,7 +10,52 @@ pub mod options; pub mod theme; use termion::input::TermRead; -use zellij_tile::data::Key; +use zellij_tile::data::{InputMode, Key, ModeInfo, Palette, PluginCapabilities}; + +/// Creates a [`ModeInfo`] struct indicating the current [`InputMode`] and its keybinds +/// (as pairs of [`String`]s). +pub fn get_mode_info( + mode: InputMode, + palette: Palette, + capabilities: PluginCapabilities, +) -> ModeInfo { + 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, + } +} pub fn parse_keys(input_bytes: &[u8]) -> Vec { input_bytes.keys().flatten().map(cast_termion_key).collect() From b25842a563215bada9844367011fe147407c73d8 Mon Sep 17 00:00:00 2001 From: Lovecraftian Horror Date: Fri, 9 Jul 2021 15:45:39 -0400 Subject: [PATCH 14/33] Display just session name with tab names --- default-plugins/tab-bar/src/line.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/default-plugins/tab-bar/src/line.rs b/default-plugins/tab-bar/src/line.rs index 3ebeaac3..fbd9cba0 100644 --- a/default-plugins/tab-bar/src/line.rs +++ b/default-plugins/tab-bar/src/line.rs @@ -145,10 +145,8 @@ fn add_next_tabs_msg( } fn tab_line_prefix(session_name: Option<&str>, palette: Palette) -> LinePart { - let mut prefix_text = " Zellij ".to_string(); - if let Some(name) = session_name { - prefix_text.push_str(&format!("({}) ", name)); - } + let session_name = session_name.unwrap_or("Zellij"); + let prefix_text = format!(" {} ", session_name); let prefix_text_len = prefix_text.chars().count(); let prefix_styled_text = style!(palette.white, palette.cyan) From b15cfba6e1c6227395a4f8cd2a625bd75659092e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Palenica?= Date: Tue, 13 Jul 2021 23:22:11 -0700 Subject: [PATCH 15/33] Apply code review suggestions. Rename decorating_pipe to logging_pipe. Add plugin_id to plugin log. Move logger init from file to in-code initialization and change logging file to zellij directory. Change format of timestamp. --- .gitignore | 3 +- Cargo.lock | 82 ++++++++++--------- default-plugins/status-bar/src/main.rs | 1 - default-plugins/strider/src/main.rs | 4 - src/main.rs | 2 +- zellij-client/Cargo.toml | 1 + zellij-client/src/lib.rs | 2 + zellij-server/Cargo.toml | 1 + zellij-server/src/lib.rs | 2 +- .../{decorating_pipe.rs => logging_pipe.rs} | 61 +++++++++----- zellij-server/src/wasm_vm.rs | 10 ++- zellij-tile/src/lib.rs | 1 - zellij-utils/assets/config/log4rs.yml | 46 ----------- zellij-utils/src/logging.rs | 50 ++++++++++- 14 files changed, 143 insertions(+), 123 deletions(-) rename zellij-server/src/{decorating_pipe.rs => logging_pipe.rs} (81%) delete mode 100644 zellij-utils/assets/config/log4rs.yml diff --git a/.gitignore b/.gitignore index 21a50829..433d02d7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,4 @@ .vim .DS_Store /assets/man/zellij.1 -**/target -zellij.log \ No newline at end of file +**/target \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index ead56047..f06e05c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,9 +46,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.41" +version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15af2628f6890fe2609a3b91bef4c83450512802e59489f9c1cb1fa5df064a61" +checksum = "595d3cfa7a60d4555cb5067b99f07142a08ea778de5cf993f7b75c7d8fabc486" [[package]] name = "arc-swap" @@ -105,12 +105,11 @@ dependencies = [ [[package]] name = "async-io" -version = "1.4.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bbfd5cf2794b1e908ea8457e6c45f8f8f1f6ec5f74617bf4662623f47503c3b" +checksum = "a811e6a479f2439f0c04038796b5cfb3d2ad56c230e0f2d3f7b04d68cfee607b" dependencies = [ "concurrent-queue", - "fastrand", "futures-lite", "libc", "log", @@ -211,12 +210,12 @@ checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" [[package]] name = "atty" -version = "0.2.11" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ + "hermit-abi", "libc", - "termion", "winapi", ] @@ -308,9 +307,9 @@ checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" [[package]] name = "cc" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" +checksum = "e70cc2f62c6ce1868963827bd677764c62d07c3d9a3e1fb1177ee1a9ab199eb2" [[package]] name = "cfg-if" @@ -589,9 +588,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.12.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f2c43f534ea4b0b049015d00269734195e6d3f0f6635cb692251aca6f9f8b3c" +checksum = "757c0ded2af11d8e739c4daea1ac623dd1624b06c844cf3f5a39f1bdbd99bb12" dependencies = [ "darling_core", "darling_macro", @@ -599,9 +598,9 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.12.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e91455b86830a1c21799d94524df0845183fa55bafd9aa137b01c7d1065fa36" +checksum = "2c34d8efb62d0c2d7f60ece80f75e5c63c1588ba68032740494b0b9a996466e3" dependencies = [ "fnv", "ident_case", @@ -613,9 +612,9 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.12.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29b5acf0dea37a7f66f7b25d2c5e93fd46f8f6968b1a5d7a3e02e97768afc95a" +checksum = "ade7bff147130fe5e6d39f089c6bd49ec0250f35d70b2eebf72afdfc919f15cc" dependencies = [ "darling_core", "quote", @@ -674,18 +673,18 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "enumset" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbd795df6708a599abf1ee10eacc72efd052b7a5f70fdf0715e4d5151a6db9c3" +checksum = "7e76129da36102af021b8e5000dab2c1c30dbef85c1e482beeff8da5dde0e0b0" dependencies = [ "enumset_derive", ] [[package]] name = "enumset_derive" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e19c52f9ec503c8a68dc04daf71a04b07e690c32ab1a8b68e33897f255269d47" +checksum = "6451128aa6655d880755345d085494cf7561a6bee7c8dc821e5d77e6d267ecd4" dependencies = [ "darling", "proc-macro2", @@ -980,9 +979,9 @@ dependencies = [ [[package]] name = "instant" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" +checksum = "bee0328b1209d157ef001c94dd85b4f8f64139adb0eac2659f4b08382b2f474d" dependencies = [ "cfg-if 1.0.0", ] @@ -1070,9 +1069,9 @@ checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" [[package]] name = "libc" -version = "0.2.97" +version = "0.2.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" +checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" [[package]] name = "libloading" @@ -1354,9 +1353,9 @@ dependencies = [ [[package]] name = "ordered-float" -version = "2.5.1" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f100fcfb41e5385e0991f74981732049f9b896821542a219420491046baafdc2" +checksum = "039f02eb0f69271f26abe3202189275d7aa2258b903cb0281b5de710a2570ff3" dependencies = [ "num-traits", ] @@ -1925,9 +1924,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "structopt" -version = "0.3.21" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c" +checksum = "69b041cdcb67226aca307e6e7be44c8806423d83e018bd662360a93dabce4d71" dependencies = [ "clap", "lazy_static", @@ -1936,9 +1935,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90" +checksum = "7813934aecf5f51a54775e00068c237de98489463968231a51746bbbc03f9c10" dependencies = [ "heck", "proc-macro-error", @@ -2050,18 +2049,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.25" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa6f76457f59514c7eeb4e59d891395fab0b2fd1d40723ae737d64153392e9c6" +checksum = "93119e4feac1cbe6c798c34d3a53ea0026b0b1de6a120deef895137c0529bfe2" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.25" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a36768c0fbf1bb15eca10defa29526bda730a2376c2ab4393ccfa16fb1a318d" +checksum = "060d69a0afe7796bf42e9e2ff91f5ee691fb15c53d38b4b62a9a53eb23164745" dependencies = [ "proc-macro2", "quote", @@ -2081,11 +2080,12 @@ dependencies = [ [[package]] name = "time" -version = "0.1.43" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ "libc", + "wasi", "winapi", ] @@ -2163,9 +2163,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" [[package]] name = "unicode-width" @@ -2272,9 +2272,9 @@ checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] name = "wasm-bindgen" @@ -2639,6 +2639,7 @@ name = "zellij-client" version = "0.15.0" dependencies = [ "insta", + "log", "mio", "termbg", "zellij-utils", @@ -2652,6 +2653,7 @@ dependencies = [ "async-trait", "base64", "cassowary", + "chrono", "daemonize", "insta", "log", diff --git a/default-plugins/status-bar/src/main.rs b/default-plugins/status-bar/src/main.rs index e9e60fc3..83eb50c9 100644 --- a/default-plugins/status-bar/src/main.rs +++ b/default-plugins/status-bar/src/main.rs @@ -133,7 +133,6 @@ fn color_elements(palette: Palette) -> ColoredElements { impl ZellijPlugin for State { fn load(&mut self) { - dbg!("hello from load"); set_selectable(false); set_invisible_borders(true); set_fixed_height(2); diff --git a/default-plugins/strider/src/main.rs b/default-plugins/strider/src/main.rs index 7d80f014..8edc1e19 100644 --- a/default-plugins/strider/src/main.rs +++ b/default-plugins/strider/src/main.rs @@ -9,15 +9,11 @@ register_plugin!(State); impl ZellijPlugin for State { fn load(&mut self) { - dbg!("hello from load"); - dbg!("hello from load2?"); refresh_directory(self); subscribe(&[EventType::KeyPress]); } fn update(&mut self, event: Event) { - dbg!("hello from update"); - if let Event::KeyPress(key) = event { match key { Key::Up | Key::Char('k') => { diff --git a/src/main.rs b/src/main.rs index 7d6865fd..1fa3343b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,7 @@ use zellij_utils::{ pub fn main() { configure_logger(); - info!("Hello Zellij!"); + info!("Starting Zellij!"); let opts = CliArgs::from_args(); if let Some(Command::Sessions(Sessions::ListSessions)) = opts.command { diff --git a/zellij-client/Cargo.toml b/zellij-client/Cargo.toml index 5a2e314a..64241f58 100644 --- a/zellij-client/Cargo.toml +++ b/zellij-client/Cargo.toml @@ -12,6 +12,7 @@ license = "MIT" mio = "0.7.11" termbg = "0.2.3" zellij-utils = { path = "../zellij-utils/", version = "0.15.0" } +log = "0.4.14" [dev-dependencies] insta = "1.6.0" diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs index 90732024..d456103a 100644 --- a/zellij-client/src/lib.rs +++ b/zellij-client/src/lib.rs @@ -3,6 +3,7 @@ pub mod os_input_output; mod command_is_executing; mod input_handler; +use log::info; use std::env::current_exe; use std::io::{self, Write}; use std::path::Path; @@ -291,6 +292,7 @@ pub fn start_client( ); os_input.disable_mouse(); + info!("{}", exit_msg); os_input.unset_raw_mode(0); let mut stdout = os_input.get_stdout_writer(); let _ = stdout.write(goodbye_message.as_bytes()).unwrap(); diff --git a/zellij-server/Cargo.toml b/zellij-server/Cargo.toml index 598d8aa3..81616d06 100644 --- a/zellij-server/Cargo.toml +++ b/zellij-server/Cargo.toml @@ -21,6 +21,7 @@ cassowary = "0.3.0" zellij-utils = { path = "../zellij-utils/", version = "0.15.0" } log = "0.4.14" typetag = "0.1.7" +chrono = "0.4.19" [dev-dependencies] insta = "1.6.0" diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index 8dc5509b..853f35a0 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -2,7 +2,7 @@ pub mod os_input_output; pub mod panes; pub mod tab; -mod decorating_pipe; +mod logging_pipe; mod pty; mod route; mod screen; diff --git a/zellij-server/src/decorating_pipe.rs b/zellij-server/src/logging_pipe.rs similarity index 81% rename from zellij-server/src/decorating_pipe.rs rename to zellij-server/src/logging_pipe.rs index 65039139..e1d7acc5 100644 --- a/zellij-server/src/decorating_pipe.rs +++ b/zellij-server/src/logging_pipe.rs @@ -3,32 +3,51 @@ use std::{ io::{Read, Seek, Write}, }; -use log::{error, info}; +use log::{debug, error, info}; use wasmer_wasi::{WasiFile, WasiFsError}; use zellij_utils::serde; +use chrono::prelude::*; use serde::{Deserialize, Serialize}; // 16kB log buffer const ZELLIJ_MAX_PIPE_BUFFER_SIZE: usize = 16_384; #[derive(Debug, Serialize, Deserialize)] #[serde(crate = "self::serde")] -pub struct DecoratingPipe { +pub struct LoggingPipe { buffer: VecDeque, plugin_name: String, + plugin_id: u32, } -impl DecoratingPipe { - pub fn new(plugin_name: &str) -> DecoratingPipe { - info!("Creating decorating pipe for plugin: {}!", plugin_name); - DecoratingPipe { +impl LoggingPipe { + pub fn new(plugin_name: &str, plugin_id: u32) -> LoggingPipe { + info!( + "|{:<25.25}| {} [{:<10.15}] Creating decorating pipe for plugin: {}!", + plugin_name, + Local::now().format("%Y-%m-%d %H:%M:%S.%3f"), + format!("id: {}", plugin_id), + plugin_name + ); + LoggingPipe { buffer: VecDeque::new(), plugin_name: String::from(plugin_name), + plugin_id, } } + + fn log_message(&self, message: &str) { + debug!( + "|{:<25.25}| {} [{:<10.15}] {}", + self.plugin_name, + Local::now().format("%Y-%m-%d %H:%M:%S.%3f"), + format!("id: {}", self.plugin_id), + message + ); + } } -impl Read for DecoratingPipe { +impl Read for LoggingPipe { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { let amt = std::cmp::min(buf.len(), self.buffer.len()); for (i, byte) in self.buffer.drain(..amt).enumerate() { @@ -38,11 +57,9 @@ impl Read for DecoratingPipe { } } -impl Write for DecoratingPipe { +impl Write for LoggingPipe { fn write(&mut self, buf: &[u8]) -> std::io::Result { - self.buffer.extend(buf); - - if self.buffer.len() > ZELLIJ_MAX_PIPE_BUFFER_SIZE { + if self.buffer.len() + buf.len() > ZELLIJ_MAX_PIPE_BUFFER_SIZE { let error_msg = "Exceeded log buffer size. Make sure that your plugin calls flush on stderr on \ valid UTF-8 symbol boundary. Aditionally, make sure that your log message contains \ @@ -55,6 +72,8 @@ impl Write for DecoratingPipe { )); } + self.buffer.extend(buf); + Ok(buf.len()) } @@ -73,11 +92,11 @@ impl Write for DecoratingPipe { if split_converted_buffer.peek().is_none() { // Log last chunk iff the last char is endline. Otherwise do not do it. if converted_buffer.chars().last().unwrap() == '\n' && !msg.is_empty() { - info!("|{:<25}| {}", self.plugin_name, msg); + self.log_message(msg); consumed_bytes += msg.len() + 1; } } else { - info!("|{:<25}| {}", self.plugin_name, msg); + self.log_message(msg); consumed_bytes += msg.len() + 1; } } @@ -91,7 +110,7 @@ impl Write for DecoratingPipe { } } -impl Seek for DecoratingPipe { +impl Seek for LoggingPipe { fn seek(&mut self, _pos: std::io::SeekFrom) -> std::io::Result { Err(std::io::Error::new( std::io::ErrorKind::Other, @@ -101,7 +120,7 @@ impl Seek for DecoratingPipe { } #[typetag::serde] -impl WasiFile for DecoratingPipe { +impl WasiFile for LoggingPipe { fn last_accessed(&self) -> u64 { 0 } @@ -128,13 +147,13 @@ impl WasiFile for DecoratingPipe { // Unit tests #[cfg(test)] -mod decorating_pipe_test { +mod logging_pipe_test { use super::*; #[test] fn write_without_endl_does_not_consume_buffer_after_flush() { - let mut pipe = DecoratingPipe::new("TestPipe"); + let mut pipe = LoggingPipe::new("TestPipe", 0); let test_buffer = "Testing write".as_bytes(); @@ -146,7 +165,7 @@ mod decorating_pipe_test { #[test] fn write_with_single_endl_at_the_end_consumes_whole_buffer_after_flush() { - let mut pipe = DecoratingPipe::new("TestPipe"); + let mut pipe = LoggingPipe::new("TestPipe", 0); let test_buffer = "Testing write \n".as_bytes(); @@ -158,7 +177,7 @@ mod decorating_pipe_test { #[test] fn write_with_endl_in_the_middle_consumes_buffer_up_to_endl_after_flush() { - let mut pipe = DecoratingPipe::new("TestPipe"); + let mut pipe = LoggingPipe::new("TestPipe", 0); let test_buffer = "Testing write \n".as_bytes(); let test_buffer2 = "And the rest".as_bytes(); @@ -182,7 +201,7 @@ mod decorating_pipe_test { #[test] fn write_with_many_endl_consumes_whole_buffer_after_flush() { - let mut pipe = DecoratingPipe::new("TestPipe"); + let mut pipe = LoggingPipe::new("TestPipe", 0); let test_buffer = "Testing write \n".as_bytes(); @@ -205,7 +224,7 @@ mod decorating_pipe_test { #[test] fn write_with_incorrect_byte_boundary_does_not_crash() { - let mut pipe = DecoratingPipe::new("TestPipe"); + let mut pipe = LoggingPipe::new("TestPipe", 0); let test_buffer = "😱".as_bytes(); diff --git a/zellij-server/src/wasm_vm.rs b/zellij-server/src/wasm_vm.rs index eed7e935..f3e4a115 100644 --- a/zellij-server/src/wasm_vm.rs +++ b/zellij-server/src/wasm_vm.rs @@ -17,7 +17,7 @@ use wasmer_wasi::{Pipe, WasiEnv, WasiState}; use zellij_tile::data::{Event, EventType, PluginIds}; use crate::{ - decorating_pipe::DecoratingPipe, + logging_pipe::LoggingPipe, panes::PaneId, pty::PtyInstruction, screen::ScreenInstruction, @@ -57,7 +57,7 @@ pub(crate) struct PluginEnv { // Thread main -------------------------------------------------------------------------------------------------------- pub(crate) fn wasm_thread_main(bus: Bus, store: Store, data_dir: PathBuf) { - info!("Wasm create thread :))"); + info!("Wasm main thread starts"); let mut plugin_id = 0; let mut plugin_map = HashMap::new(); loop { @@ -76,8 +76,10 @@ pub(crate) fn wasm_thread_main(bus: Bus, store: Store, data_d let output = Pipe::new(); let input = Pipe::new(); - let stderr = - DecoratingPipe::new(path.as_path().file_name().unwrap().to_str().unwrap()); + let stderr = LoggingPipe::new( + path.as_path().file_name().unwrap().to_str().unwrap(), + plugin_id, + ); let mut wasi_env = WasiState::new("Zellij") .env("CLICOLOR_FORCE", "1") .preopen(|p| { diff --git a/zellij-tile/src/lib.rs b/zellij-tile/src/lib.rs index 176a9497..af7d8ca1 100644 --- a/zellij-tile/src/lib.rs +++ b/zellij-tile/src/lib.rs @@ -19,7 +19,6 @@ macro_rules! register_plugin { } fn main() { - dbg!("hello from plugin main :)"); STATE.with(|state| { state.borrow_mut().load(); }); diff --git a/zellij-utils/assets/config/log4rs.yml b/zellij-utils/assets/config/log4rs.yml deleted file mode 100644 index 5a60b973..00000000 --- a/zellij-utils/assets/config/log4rs.yml +++ /dev/null @@ -1,46 +0,0 @@ -# Scan this file for changes every 30 seconds -refresh_rate: 30 seconds - -appenders: - # An appender named "stderr" that writes to stderr - stderr: - kind: console - target: stderr - - # default zellij appender, should be used across most of the codebase. - logFile: - kind: file - path: "zellij.log" - append: false - encoder: - # {n} means platform dependent newline - # module is padded to *at least* 25 bytes and thread is padded to be between 10 and 15 bytes. - pattern: "|{module:<25}| {date} {highlight({level})} [{thread:<10.15}] [{file}:{line}]: {message} {n}" - - # plugin appender. To be used in decorating_pipe to forward stderr output from plugins. - logPlugin: - kind: file - path: "zellij.log" - encoder: - # {n} means platform dependent newline - pattern: "{message} {n}" - -# Set the default logging level to "info" and log it to zellij.log file -root: - level: info - appenders: - - logFile - -loggers: - # decrease verbosity for this module because it has a lot of useless info logs - wasmer_compiler_cranelift: - level: warn - appenders: - - logFile - - # For decorating_pipe, we use custom format as we use logging macros to forward stderr output from plugins - zellij_server::decorating_pipe: - level: trace - appenders: - - logPlugin - additive: false diff --git a/zellij-utils/src/logging.rs b/zellij-utils/src/logging.rs index 52e91497..d7f35344 100644 --- a/zellij-utils/src/logging.rs +++ b/zellij-utils/src/logging.rs @@ -7,13 +7,59 @@ use std::{ path::{Path, PathBuf}, }; -use log::info; +use log::{info, 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() { - log4rs::init_file("zellij-utils/assets/config/log4rs.yml", Default::default()).unwrap(); + // {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(); + info!("Zellij logger initialized"); } From 9044dbcec361ab921d618965f547437da4097bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Palenica?= Date: Tue, 13 Jul 2021 23:31:16 -0700 Subject: [PATCH 16/33] small touchups --- zellij-server/src/lib.rs | 1 - zellij-tile/Cargo.toml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index 853f35a0..b8cbbc5d 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -117,7 +117,6 @@ pub(crate) enum SessionState { pub fn start_server(os_input: Box, socket_path: PathBuf) { info!("starts server"); - #[cfg(not(any(feature = "test", test)))] daemonize::Daemonize::new() .working_directory(std::env::current_dir().unwrap()) .umask(0o077) diff --git a/zellij-tile/Cargo.toml b/zellij-tile/Cargo.toml index 3ae62576..b0c18ff2 100644 --- a/zellij-tile/Cargo.toml +++ b/zellij-tile/Cargo.toml @@ -10,4 +10,4 @@ license = "MIT" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" strum = "0.20.0" -strum_macros = "0.20.0" \ No newline at end of file +strum_macros = "0.20.0" From 3326f521efd33cdfbe9df3d6f44ddd9042897943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Palenica?= Date: Tue, 13 Jul 2021 23:46:36 -0700 Subject: [PATCH 17/33] Fix clippy --- zellij-server/src/logging_pipe.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/zellij-server/src/logging_pipe.rs b/zellij-server/src/logging_pipe.rs index e1d7acc5..eecfa2d3 100644 --- a/zellij-server/src/logging_pipe.rs +++ b/zellij-server/src/logging_pipe.rs @@ -91,7 +91,7 @@ impl Write for LoggingPipe { while let Some(msg) = split_converted_buffer.next() { if split_converted_buffer.peek().is_none() { // Log last chunk iff the last char is endline. Otherwise do not do it. - if converted_buffer.chars().last().unwrap() == '\n' && !msg.is_empty() { + if converted_buffer.ends_with('\n') && !msg.is_empty() { self.log_message(msg); consumed_bytes += msg.len() + 1; } @@ -239,4 +239,20 @@ mod logging_pipe_test { println!("len: {}, buf: {:?}", test_buffer.len(), test_buffer); } + + #[test] + fn write_with_many_endls_consumes_everything_after_flush() { + let mut pipe = LoggingPipe::new("TestPipe", 0); + let test_buffer = "Testing write \n".as_bytes(); + + pipe.write( + [test_buffer, test_buffer, b"\n", b"\n", b"\n"] + .concat() + .as_slice(), + ) + .expect("Err write"); + pipe.flush().expect("Err flush"); + + assert_eq!(pipe.buffer.len(), 0); + } } From 27634423d90df538070e052ba4cbd8b9811fae51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Palenica?= Date: Sat, 17 Jul 2021 23:50:24 -0700 Subject: [PATCH 18/33] Minor fixes --- src/main.rs | 2 -- zellij-client/src/lib.rs | 1 + zellij-server/src/lib.rs | 2 +- zellij-server/src/logging_pipe.rs | 18 ++++++------------ zellij-utils/src/logging.rs | 4 +--- 5 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1fa3343b..612e130e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,6 @@ mod sessions; mod tests; use crate::install::populate_data_dir; -use log::info; use sessions::{assert_session, assert_session_ne, get_active_session, list_sessions}; use std::convert::TryFrom; use std::process; @@ -21,7 +20,6 @@ use zellij_utils::{ pub fn main() { configure_logger(); - info!("Starting Zellij!"); let opts = CliArgs::from_args(); if let Some(Command::Sessions(Sessions::ListSessions)) = opts.command { diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs index d456103a..d9dda42c 100644 --- a/zellij-client/src/lib.rs +++ b/zellij-client/src/lib.rs @@ -89,6 +89,7 @@ pub fn start_client( info: ClientInfo, layout: Option, ) { + info!("Starting Zellij client!"); let clear_client_terminal_attributes = "\u{1b}[?1l\u{1b}=\u{1b}[r\u{1b}12l\u{1b}[?1000l\u{1b}[?1002l\u{1b}[?1003l\u{1b}[?1005l\u{1b}[?1006l\u{1b}[?12l"; let take_snapshot = "\u{1b}[?1049h"; let bracketed_paste = "\u{1b}[?2004h"; diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index b8cbbc5d..690304bb 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -116,7 +116,7 @@ pub(crate) enum SessionState { } pub fn start_server(os_input: Box, socket_path: PathBuf) { - info!("starts server"); + info!("Starting Zellij server!"); daemonize::Daemonize::new() .working_directory(std::env::current_dir().unwrap()) .umask(0o077) diff --git a/zellij-server/src/logging_pipe.rs b/zellij-server/src/logging_pipe.rs index eecfa2d3..a2658cf9 100644 --- a/zellij-server/src/logging_pipe.rs +++ b/zellij-server/src/logging_pipe.rs @@ -3,7 +3,7 @@ use std::{ io::{Read, Seek, Write}, }; -use log::{debug, error, info}; +use log::{debug, error}; use wasmer_wasi::{WasiFile, WasiFsError}; use zellij_utils::serde; @@ -22,13 +22,6 @@ pub struct LoggingPipe { impl LoggingPipe { pub fn new(plugin_name: &str, plugin_id: u32) -> LoggingPipe { - info!( - "|{:<25.25}| {} [{:<10.15}] Creating decorating pipe for plugin: {}!", - plugin_name, - Local::now().format("%Y-%m-%d %H:%M:%S.%3f"), - format!("id: {}", plugin_id), - plugin_name - ); LoggingPipe { buffer: VecDeque::new(), plugin_name: String::from(plugin_name), @@ -49,11 +42,12 @@ impl LoggingPipe { impl Read for LoggingPipe { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { + // NOTE: should we do this? I think if anyone were to chain LoggingPipe and read from it, + // they would see very weird behavior because we drain self.buffer in `flush`. Also, logs would be screwed up. + // Consider removing this code. let amt = std::cmp::min(buf.len(), self.buffer.len()); - for (i, byte) in self.buffer.drain(..amt).enumerate() { - buf[i] = byte; - } - Ok(amt) + let data: Vec<_> = self.buffer.drain(..amt).collect(); + buf.as_mut().write(&data) } } diff --git a/zellij-utils/src/logging.rs b/zellij-utils/src/logging.rs index d7f35344..7e57eebd 100644 --- a/zellij-utils/src/logging.rs +++ b/zellij-utils/src/logging.rs @@ -7,7 +7,7 @@ use std::{ path::{Path, PathBuf}, }; -use log::{info, LevelFilter}; +use log::LevelFilter; use log4rs::append::file::FileAppender; use log4rs::config::{Appender, Config, Logger, Root}; @@ -59,8 +59,6 @@ pub fn configure_logger() { .unwrap(); let _ = log4rs::init_config(config).unwrap(); - - info!("Zellij logger initialized"); } pub fn atomic_create_file(file_name: &Path) -> io::Result<()> { From d097c521acda376899949083f38c857fa30b47d6 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Mon, 19 Jul 2021 20:27:58 +0100 Subject: [PATCH 19/33] chore(release): v0.15.0 --- Makefile.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.toml b/Makefile.toml index c58ce3d0..e0043ab7 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -151,7 +151,7 @@ run_task = "publish-zellij" [tasks.release-commit] dependencies = ["commit-all", "tag-release"] command = "git" -args = ["push", "--atomic", "upstream", "main", "v${CARGO_MAKE_CRATE_VERSION}"] +args = ["push", "--atomic", "origin", "main", "v${CARGO_MAKE_CRATE_VERSION}"] [tasks.commit-all] ignore_errors = true From 6a90542ae38ca46c84c0b3c721a2a6b231347359 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Mon, 19 Jul 2021 20:35:50 +0100 Subject: [PATCH 20/33] chore(release): bump development version --- Cargo.toml | 8 ++++---- zellij-client/Cargo.toml | 4 ++-- zellij-server/Cargo.toml | 4 ++-- zellij-tile-utils/Cargo.toml | 2 +- zellij-tile/Cargo.toml | 2 +- zellij-utils/Cargo.toml | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f5f221e9..9a487176 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zellij" -version = "0.15.0" +version = "0.16.0" authors = ["Aram Drevekenin "] edition = "2018" description = "A terminal workspace with batteries included" @@ -14,9 +14,9 @@ resolver = "2" [dependencies] names = "0.11.0" -zellij-client = { path = "zellij-client/", version = "0.15.0" } -zellij-server = { path = "zellij-server/", version = "0.15.0" } -zellij-utils = { path = "zellij-utils/", version = "0.15.0" } +zellij-client = { path = "zellij-client/", version = "0.16.0" } +zellij-server = { path = "zellij-server/", version = "0.16.0" } +zellij-utils = { path = "zellij-utils/", version = "0.16.0" } [dev-dependencies] insta = { version = "1.6.0", features = ["backtrace"] } diff --git a/zellij-client/Cargo.toml b/zellij-client/Cargo.toml index 5a2e314a..f0d67435 100644 --- a/zellij-client/Cargo.toml +++ b/zellij-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zellij-client" -version = "0.15.0" +version = "0.16.0" authors = ["Kunal Mohan "] edition = "2018" description = "The client-side library for Zellij" @@ -11,7 +11,7 @@ license = "MIT" [dependencies] mio = "0.7.11" termbg = "0.2.3" -zellij-utils = { path = "../zellij-utils/", version = "0.15.0" } +zellij-utils = { path = "../zellij-utils/", version = "0.16.0" } [dev-dependencies] insta = "1.6.0" diff --git a/zellij-server/Cargo.toml b/zellij-server/Cargo.toml index beefb82d..f6c8fcbe 100644 --- a/zellij-server/Cargo.toml +++ b/zellij-server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zellij-server" -version = "0.15.0" +version = "0.16.0" authors = ["Kunal Mohan "] edition = "2018" description = "The server-side library for Zellij" @@ -18,7 +18,7 @@ unicode-width = "0.1.8" wasmer = "1.0.0" wasmer-wasi = "1.0.0" cassowary = "0.3.0" -zellij-utils = { path = "../zellij-utils/", version = "0.15.0" } +zellij-utils = { path = "../zellij-utils/", version = "0.16.0" } [dev-dependencies] insta = "1.6.0" diff --git a/zellij-tile-utils/Cargo.toml b/zellij-tile-utils/Cargo.toml index 9c8865a9..d1e7d233 100644 --- a/zellij-tile-utils/Cargo.toml +++ b/zellij-tile-utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zellij-tile-utils" -version = "0.15.0" +version = "0.16.0" authors = ["denis "] edition = "2018" description = "A utility library for Zellij plugins" diff --git a/zellij-tile/Cargo.toml b/zellij-tile/Cargo.toml index b0c18ff2..90be3e08 100644 --- a/zellij-tile/Cargo.toml +++ b/zellij-tile/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zellij-tile" -version = "0.15.0" +version = "0.16.0" authors = ["Brooks J Rady "] edition = "2018" description = "A small client-side library for writing Zellij plugins" diff --git a/zellij-utils/Cargo.toml b/zellij-utils/Cargo.toml index 6b530ee9..3365db09 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 "] edition = "2018" description = "A utility library for Zellij client and server" @@ -27,7 +27,7 @@ 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" } [dependencies.async-std] version = "1.3.0" From 7de19dc6dfd6c847370f354649178e68f0181fd4 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Mon, 19 Jul 2021 20:49:23 +0100 Subject: [PATCH 21/33] fix(style): bury the dead (code) --- Cargo.lock | 12 ++++++------ zellij-server/src/screen.rs | 10 +--------- zellij-server/src/tab.rs | 6 +----- zellij-server/src/unit/screen_tests.rs | 12 ++---------- zellij-server/src/unit/tab_tests.rs | 4 +--- 5 files changed, 11 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 52967fbb..d88bcec8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2447,7 +2447,7 @@ dependencies = [ [[package]] name = "zellij" -version = "0.15.0" +version = "0.16.0" dependencies = [ "insta", "names", @@ -2460,7 +2460,7 @@ dependencies = [ [[package]] name = "zellij-client" -version = "0.15.0" +version = "0.16.0" dependencies = [ "insta", "mio", @@ -2470,7 +2470,7 @@ dependencies = [ [[package]] name = "zellij-server" -version = "0.15.0" +version = "0.16.0" dependencies = [ "ansi_term 0.12.1", "async-trait", @@ -2487,7 +2487,7 @@ dependencies = [ [[package]] name = "zellij-tile" -version = "0.15.0" +version = "0.16.0" dependencies = [ "serde", "serde_json", @@ -2497,14 +2497,14 @@ dependencies = [ [[package]] name = "zellij-tile-utils" -version = "0.15.0" +version = "0.16.0" dependencies = [ "ansi_term 0.12.1", ] [[package]] name = "zellij-utils" -version = "0.15.0" +version = "0.16.0" dependencies = [ "async-std", "backtrace", diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index 9005d795..c96c1345 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -15,7 +15,7 @@ use crate::{ wasm_vm::PluginInstruction, ServerInstruction, SessionState, }; -use zellij_tile::data::{Event, InputMode, ModeInfo, Palette, PluginCapabilities, TabInfo}; +use zellij_tile::data::{Event, ModeInfo, Palette, PluginCapabilities, TabInfo}; use zellij_utils::{ errors::{ContextType, ScreenContext}, input::options::Options, @@ -149,7 +149,6 @@ pub(crate) struct Screen { /// The index of this [`Screen`]'s active [`Tab`]. active_tab_index: Option, mode_info: ModeInfo, - input_mode: InputMode, colors: Palette, session_state: Arc>, } @@ -161,7 +160,6 @@ impl Screen { client_attributes: &ClientAttributes, max_panes: Option, mode_info: ModeInfo, - input_mode: InputMode, session_state: Arc>, ) -> Self { Screen { @@ -172,7 +170,6 @@ impl Screen { active_tab_index: None, tabs: BTreeMap::new(), mode_info, - input_mode, session_state, } } @@ -192,7 +189,6 @@ impl Screen { self.max_panes, Some(PaneId::Terminal(pane_id)), self.mode_info.clone(), - self.input_mode, self.colors, self.session_state.clone(), ); @@ -354,7 +350,6 @@ impl Screen { self.max_panes, None, self.mode_info.clone(), - self.input_mode, self.colors, self.session_state.clone(), ); @@ -428,7 +423,6 @@ pub(crate) fn screen_thread_main( session_state: Arc>, ) { let capabilities = config_options.simplified_ui; - let default_mode = config_options.default_mode.unwrap_or_default(); let mut screen = Screen::new( bus, @@ -439,10 +433,8 @@ pub(crate) fn screen_thread_main( capabilities: PluginCapabilities { arrow_fonts: capabilities, }, - mode: default_mode, ..ModeInfo::default() }, - default_mode, session_state, ); loop { diff --git a/zellij-server/src/tab.rs b/zellij-server/src/tab.rs index 686a1c20..f3b30fe3 100644 --- a/zellij-server/src/tab.rs +++ b/zellij-server/src/tab.rs @@ -24,7 +24,7 @@ use std::{ cmp::Reverse, collections::{BTreeMap, HashSet}, }; -use zellij_tile::data::{Event, InputMode, ModeInfo, Palette}; +use zellij_tile::data::{Event, ModeInfo, Palette}; use zellij_utils::{ input::{ layout::{Layout, Run}, @@ -87,7 +87,6 @@ pub(crate) struct Tab { should_clear_display_before_rendering: bool, session_state: Arc>, pub mode_info: ModeInfo, - pub input_mode: InputMode, pub colors: Palette, } @@ -99,7 +98,6 @@ pub(crate) struct TabData { pub name: String, pub active: bool, pub mode_info: ModeInfo, - pub input_mode: InputMode, pub colors: Palette, } @@ -260,7 +258,6 @@ impl Tab { max_panes: Option, pane_id: Option, mode_info: ModeInfo, - input_mode: InputMode, colors: Palette, session_state: Arc>, ) -> Self { @@ -299,7 +296,6 @@ impl Tab { senders, should_clear_display_before_rendering: false, mode_info, - input_mode, colors, session_state, } diff --git a/zellij-server/src/unit/screen_tests.rs b/zellij-server/src/unit/screen_tests.rs index 173e2ccc..df159dde 100644 --- a/zellij-server/src/unit/screen_tests.rs +++ b/zellij-server/src/unit/screen_tests.rs @@ -1,5 +1,5 @@ use super::{Screen, ScreenInstruction}; -use crate::zellij_tile::data::{InputMode, ModeInfo, Palette}; +use crate::zellij_tile::data::{ModeInfo, Palette}; use crate::{ os_input_output::{AsyncReader, Pid, ServerOsApi}, thread_bus::Bus, @@ -81,16 +81,8 @@ fn create_new_screen(position_and_size: PositionAndSize) -> Screen { client_attributes.position_and_size = position_and_size; let max_panes = None; let mode_info = ModeInfo::default(); - let input_mode = InputMode::Normal; let session_state = Arc::new(RwLock::new(SessionState::Attached)); - Screen::new( - bus, - &client_attributes, - max_panes, - mode_info, - input_mode, - session_state, - ) + Screen::new(bus, &client_attributes, max_panes, mode_info, session_state) } #[test] diff --git a/zellij-server/src/unit/tab_tests.rs b/zellij-server/src/unit/tab_tests.rs index c19c41ce..cc08a5b1 100644 --- a/zellij-server/src/unit/tab_tests.rs +++ b/zellij-server/src/unit/tab_tests.rs @@ -1,5 +1,5 @@ use super::Tab; -use crate::zellij_tile::data::{InputMode, ModeInfo, Palette}; +use crate::zellij_tile::data::{ModeInfo, Palette}; use crate::{ os_input_output::{AsyncReader, Pid, ServerOsApi}, panes::PaneId, @@ -82,7 +82,6 @@ fn create_new_tab(position_and_size: PositionAndSize) -> Tab { let max_panes = None; let first_pane_id = Some(PaneId::Terminal(1)); let mode_info = ModeInfo::default(); - let input_mode = InputMode::Normal; let colors = Palette::default(); let session_state = Arc::new(RwLock::new(SessionState::Attached)); Tab::new( @@ -95,7 +94,6 @@ fn create_new_tab(position_and_size: PositionAndSize) -> Tab { max_panes, first_pane_id, mode_info, - input_mode, colors, session_state, ) From 55bc1feee1a1239c36f5d8591a9a275df44f4b88 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Mon, 19 Jul 2021 20:50:01 +0100 Subject: [PATCH 22/33] chore(release): rotate changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b665fa44..5ce2d371 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] + + +## [0.15.0] - 2021-07-19 * Kill children properly (https://github.com/zellij-org/zellij/pull/601) * Change name of `Run` binding for actions (https://github.com/zellij-org/zellij/pull/602) * Add running commands to `layouts` (https://github.com/zellij-org/zellij/pull/600) From 697ba09c71407f1cf430dfb59292fb7b6ee3b182 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Tue, 20 Jul 2021 15:08:38 +0200 Subject: [PATCH 23/33] Add noop for mouse actions on plugins * Comments the `unimplemented!` macro out, in favor of a noop The macro is still there for easy greppability. It is still unimplemented, but zellij doesn't need to panic once a plugin does get a scroll event. --- zellij-server/src/panes/plugin_pane.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zellij-server/src/panes/plugin_pane.rs b/zellij-server/src/panes/plugin_pane.rs index c01c7b87..256ceaea 100644 --- a/zellij-server/src/panes/plugin_pane.rs +++ b/zellij-server/src/panes/plugin_pane.rs @@ -196,13 +196,13 @@ impl Pane for PluginPane { self.position_and_size.y -= count; } fn scroll_up(&mut self, _count: usize) { - unimplemented!() + //unimplemented!() } fn scroll_down(&mut self, _count: usize) { - unimplemented!() + //unimplemented!() } fn clear_scroll(&mut self) { - unimplemented!() + //unimplemented!() } // FIXME: This need to be reevaluated and deleted if possible. // `max` doesn't make sense when things are fixed... From 105ae616829da277481b82fb9610062bea22f985 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Tue, 20 Jul 2021 16:27:32 +0200 Subject: [PATCH 24/33] docs(changelog): noop for mouse actions on plugins --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ce2d371..9fa68e51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] +* Plugins don't crash zellij anymore on receiving mouse events (https://github.com/zellij-org/zellij/pull/620) ## [0.15.0] - 2021-07-19 From c5a25f267fdc42ff66a5de6f75720150985b0dce Mon Sep 17 00:00:00 2001 From: Lovecraftian Horror Date: Tue, 20 Jul 2021 13:14:13 -0400 Subject: [PATCH 25/33] Revert "Display just session name with tab names" This reverts commit b25842a563215bada9844367011fe147407c73d8. --- default-plugins/tab-bar/src/line.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/default-plugins/tab-bar/src/line.rs b/default-plugins/tab-bar/src/line.rs index fbd9cba0..3ebeaac3 100644 --- a/default-plugins/tab-bar/src/line.rs +++ b/default-plugins/tab-bar/src/line.rs @@ -145,8 +145,10 @@ fn add_next_tabs_msg( } fn tab_line_prefix(session_name: Option<&str>, palette: Palette) -> LinePart { - let session_name = session_name.unwrap_or("Zellij"); - let prefix_text = format!(" {} ", session_name); + let mut prefix_text = " Zellij ".to_string(); + if let Some(name) = session_name { + prefix_text.push_str(&format!("({}) ", name)); + } let prefix_text_len = prefix_text.chars().count(); let prefix_styled_text = style!(palette.white, palette.cyan) From 0cabc5f11291da1814abbf4ce68676b4d338f43a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Palenica?= Date: Tue, 20 Jul 2021 22:17:26 -0700 Subject: [PATCH 26/33] Read from LoggingPipe returns error --- zellij-server/src/logging_pipe.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/zellij-server/src/logging_pipe.rs b/zellij-server/src/logging_pipe.rs index a2658cf9..f1fae6b8 100644 --- a/zellij-server/src/logging_pipe.rs +++ b/zellij-server/src/logging_pipe.rs @@ -41,13 +41,11 @@ impl LoggingPipe { } impl Read for LoggingPipe { - fn read(&mut self, buf: &mut [u8]) -> std::io::Result { - // NOTE: should we do this? I think if anyone were to chain LoggingPipe and read from it, - // they would see very weird behavior because we drain self.buffer in `flush`. Also, logs would be screwed up. - // Consider removing this code. - let amt = std::cmp::min(buf.len(), self.buffer.len()); - let data: Vec<_> = self.buffer.drain(..amt).collect(); - buf.as_mut().write(&data) + fn read(&mut self, _: &mut [u8]) -> std::io::Result { + Err(std::io::Error::new( + std::io::ErrorKind::Other, + "Can not reed from a LoggingPipe", + )) } } From 56b7cbf58cd9aae162a5037ee536c64818b0dd11 Mon Sep 17 00:00:00 2001 From: qepasa Date: Wed, 21 Jul 2021 07:19:39 +0200 Subject: [PATCH 27/33] Cleanup Cargo.toml --- zellij-client/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/zellij-client/Cargo.toml b/zellij-client/Cargo.toml index 731c0d45..b9edb0ad 100644 --- a/zellij-client/Cargo.toml +++ b/zellij-client/Cargo.toml @@ -14,7 +14,6 @@ termbg = "0.2.3" zellij-utils = { path = "../zellij-utils/", version = "0.16.0" } log = "0.4.14" - [dev-dependencies] insta = "1.6.0" From 290704a0568a831eb2b7e77c3f0f1f5ee69edf4b Mon Sep 17 00:00:00 2001 From: qepasa Date: Wed, 21 Jul 2021 07:20:07 +0200 Subject: [PATCH 28/33] Cleanup Cargo.toml --- zellij-server/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/zellij-server/Cargo.toml b/zellij-server/Cargo.toml index e3015aaa..c9c6491e 100644 --- a/zellij-server/Cargo.toml +++ b/zellij-server/Cargo.toml @@ -23,7 +23,6 @@ log = "0.4.14" typetag = "0.1.7" chrono = "0.4.19" - [dev-dependencies] insta = "1.6.0" From 2bb3c08ae2b0026ee1109857b62db995b0a4474f Mon Sep 17 00:00:00 2001 From: Brooks Rady Date: Wed, 21 Jul 2021 12:38:25 +0100 Subject: [PATCH 29/33] chore(changelog): add logging feature --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fa68e51..5b499546 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] * Plugins don't crash zellij anymore on receiving mouse events (https://github.com/zellij-org/zellij/pull/620) - +* A universal logging system has been implemented (https://github.com/zellij-org/zellij/pull/592) + * Added [`log`](https://docs.rs/log/0.4.14/log/#macros) crate support for logging within Zellij + * Messages sent over the `stderr` of plugins are now logged as well, bringing back `dbg!` support! ## [0.15.0] - 2021-07-19 * Kill children properly (https://github.com/zellij-org/zellij/pull/601) From c42b0f867e0300c86243ab709d8d3620e362964b Mon Sep 17 00:00:00 2001 From: a-kenji Date: Thu, 22 Jul 2021 16:30:06 +0200 Subject: [PATCH 30/33] fixup! merge * Missed something while merging --- zellij-server/src/screen.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index e265e8c5..86ecd688 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -429,7 +429,7 @@ pub(crate) fn screen_thread_main( &client_attributes, max_panes, get_mode_info( - default_mode, + config_options.default_mode.unwrap_or_default(), client_attributes.palette, PluginCapabilities { arrow_fonts: capabilities, From 903cb68a40979ff3020f431db4a8222eb607e238 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Thu, 22 Jul 2021 16:19:46 +0200 Subject: [PATCH 31/33] Add cmd to dump layout to stdout Adds the ability to dump the default layouts to stdout, similar to the `zellij setup --dump-config`, but now it needs the name of a currently existing layout: - default - strider - disable-status `zellij setup --dump-layout [LAYOUT]` --- src/main.rs | 10 ++++++++-- zellij-utils/src/setup.rs | 22 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 612e130e..22f373a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,8 +36,14 @@ pub fn main() { let config_options = Options::from_cli(&config.options, opts.command.clone()); if let Some(Command::Setup(ref setup)) = opts.command { - Setup::from_cli(setup, &opts, &config_options).expect("Failed to print to stdout"); - } + Setup::from_cli(setup, &opts, &config_options).map_or_else( + |e| { + eprintln!("{:?}", e); + process::exit(1); + }, + |_| {}, + ); + }; atomic_create_dir(&*ZELLIJ_TMP_DIR).unwrap(); atomic_create_dir(&*ZELLIJ_TMP_LOG_DIR).unwrap(); diff --git a/zellij-utils/src/setup.rs b/zellij-utils/src/setup.rs index 61c330cd..aa0bb642 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, /// Generates completion for the specified shell #[structopt(long)] pub generate_completion: Option, @@ -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(()) } From d74a1bd7c5808eb934c2efa5652a989a7fe5c80e Mon Sep 17 00:00:00 2001 From: a-kenji Date: Thu, 22 Jul 2021 16:48:54 +0200 Subject: [PATCH 32/33] docs(changelog): display session-name in tab-bar --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b499546..d92743be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) * A universal logging system has been implemented (https://github.com/zellij-org/zellij/pull/592) * Added [`log`](https://docs.rs/log/0.4.14/log/#macros) crate support for logging within Zellij * Messages sent over the `stderr` of plugins are now logged as well, bringing back `dbg!` support! +* Add displaying of the `session-name` to the `tab-bar` (https://github.com/zellij-org/zellij/pull/608) ## [0.15.0] - 2021-07-19 * Kill children properly (https://github.com/zellij-org/zellij/pull/601) From f5734f2bf14212cda4455065222c0593004020bf Mon Sep 17 00:00:00 2001 From: a-kenji Date: Thu, 22 Jul 2021 18:47:28 +0200 Subject: [PATCH 33/33] docs(changelog): add dump `layout` to stdout --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d92743be..ad53c6c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) * Added [`log`](https://docs.rs/log/0.4.14/log/#macros) crate support for logging within Zellij * Messages sent over the `stderr` of plugins are now logged as well, bringing back `dbg!` support! * Add displaying of the `session-name` to the `tab-bar` (https://github.com/zellij-org/zellij/pull/608) +* Add command to dump `layouts` to stdout (https://github.com/zellij-org/zellij/pull/623) + * `zellij setup --dump-layout [LAYOUT]` [default, strider, disable-status] ## [0.15.0] - 2021-07-19 * Kill children properly (https://github.com/zellij-org/zellij/pull/601)