diff --git a/CHANGELOG.md b/CHANGELOG.md index e9859d4..3be9564 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Features +- Redirect logs by default to systemd - Specify colors in css-like hex (#47) - Fallback to input at dialog overflow (#43) - Support environments without layer-shell protocol (#42) diff --git a/Cargo.lock b/Cargo.lock index 89a3dd7..2a25992 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "adler" version = "1.0.2" @@ -95,6 +97,15 @@ dependencies = [ "wyz", ] +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + [[package]] name = "bytemuck" version = "1.7.2" @@ -224,6 +235,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cpufeatures" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" +dependencies = [ + "libc", +] + [[package]] name = "crc32fast" version = "1.2.1" @@ -233,6 +253,26 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "crypto-mac" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "ctor" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e98e2ad1a782e33928b96fc3948e7c355e5af34ba4de7670fe8bac2a3b2006d" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "data-url" version = "0.1.0" @@ -252,6 +292,15 @@ dependencies = [ "byteorder", ] +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + [[package]] name = "dirs-next" version = "2.0.0" @@ -466,6 +515,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getrandom" version = "0.2.3" @@ -495,6 +554,16 @@ dependencies = [ "libc", ] +[[package]] +name = "hmac" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" +dependencies = [ + "crypto-mac", + "digest", +] + [[package]] name = "itertools" version = "0.10.1" @@ -554,6 +623,22 @@ dependencies = [ "winapi", ] +[[package]] +name = "libsystemd" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce716113032d777d2c66ca51d94b511b015454d037cef42f71d9c6c41e0333c" +dependencies = [ + "hmac", + "libc", + "log", + "nix 0.21.0", + "serde", + "sha2", + "thiserror", + "uuid", +] + [[package]] name = "log" version = "0.4.14" @@ -561,6 +646,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ "cfg-if 1.0.0", + "value-bag", ] [[package]] @@ -615,6 +701,15 @@ dependencies = [ "libc", ] +[[package]] +name = "memoffset" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" +dependencies = [ + "autocfg", +] + [[package]] name = "miniz_oxide" version = "0.3.7" @@ -671,6 +766,19 @@ dependencies = [ "libc", ] +[[package]] +name = "nix" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c3728fec49d363a50a8828a190b379a446cc5cf085c06259bbbeb34447e4ec7" +dependencies = [ + "bitflags", + "cc", + "cfg-if 1.0.0", + "libc", + "memoffset", +] + [[package]] name = "nom" version = "6.2.1" @@ -728,6 +836,12 @@ dependencies = [ "loom", ] +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + [[package]] name = "pathfinder_geometry" version = "0.5.1" @@ -1067,6 +1181,19 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "sha2" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b362ae5752fd2137731f9fa25fd4d9058af34666ca1966fb969119cc35719f12" +dependencies = [ + "block-buffer", + "cfg-if 1.0.0", + "cpufeatures", + "digest", + "opaque-debug", +] + [[package]] name = "shlex" version = "1.0.0" @@ -1148,6 +1275,12 @@ dependencies = [ "syn", ] +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + [[package]] name = "svgfilters" version = "0.3.0" @@ -1185,6 +1318,18 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "systemd-journal-logger" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58102728086a64a9d67274f36e5447da32dde6973b326dd67e404fa65a0b45f3" +dependencies = [ + "libc", + "libsystemd", + "log", + "nix 0.21.0", +] + [[package]] name = "tap" version = "1.0.1" @@ -1262,6 +1407,12 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0685c84d5d54d1c26f7d3eb96cd41550adb97baed141a761cf335d3d33bcd0ae" +[[package]] +name = "typenum" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" + [[package]] name = "ucd-trie" version = "0.1.3" @@ -1306,6 +1457,25 @@ dependencies = [ "xmlwriter", ] +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +dependencies = [ + "serde", +] + +[[package]] +name = "value-bag" +version = "1.0.0-alpha.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd320e1520f94261153e96f7534476ad869c14022aee1e59af7c778075d840ae" +dependencies = [ + "ctor", + "version_check", +] + [[package]] name = "vec_map" version = "0.8.2" @@ -1518,6 +1688,7 @@ dependencies = [ "shlex", "smithay-client-toolkit", "structopt", + "systemd-journal-logger", "test-case", "tiny-skia", "toml", diff --git a/Cargo.toml b/Cargo.toml index 316838f..5e688c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,7 @@ regex = "1.4.2" libc = "0.2.81" pathfinder_geometry = "0.5" tiny-skia = "0.5.1" +systemd-journal-logger = "0.3.0" [profile.release] lto = true diff --git a/rust-toolchain b/rust-toolchain index 9db5ea1..b7921ae 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.48.0 +1.54.0 diff --git a/src/config.rs b/src/config.rs index 708d617..c69e4d1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -153,7 +153,7 @@ impl Config { pub fn terminal_command(&self) -> Vec { if let Some(cmd) = self.term.as_ref() { - shlex::split(&cmd) + shlex::split(cmd) .unwrap() .into_iter() .map(|s| CString::new(s).unwrap()) diff --git a/src/draw.rs b/src/draw.rs index b1dd359..72cd020 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -112,5 +112,5 @@ fn draw_text( }, ); - dt.draw_glyphs(font, point_size, &ids, &positions, &source, &opts); + dt.draw_glyphs(font, point_size, &ids, &positions, &source, opts); } diff --git a/src/draw/list_view.rs b/src/draw/list_view.rs index e44eaec..29aad00 100644 --- a/src/draw/list_view.rs +++ b/src/draw/list_view.rs @@ -105,7 +105,7 @@ where dt.draw_image_at( x_offset, y_offset - icon_size_f32, - &icon, + icon, &DrawOptions::default(), ); } else { @@ -114,7 +114,7 @@ where icon_size_f32, x_offset, y_offset - icon_size_f32, - &icon, + icon, &DrawOptions::default(), ); } @@ -186,7 +186,7 @@ where let tail_str = substr(item.name, &(idx..item.name.chars().count())); let color = Source::Solid(color); - draw_text(&mut dt, tail_str, &font, font_size, pos, color, &draw_opts); + draw_text(&mut dt, tail_str, font, font_size, pos, color, &draw_opts); } else { draw_text( &mut dt, diff --git a/src/input.rs b/src/input.rs index 1f7cbd8..0637745 100644 --- a/src/input.rs +++ b/src/input.rs @@ -124,7 +124,7 @@ impl InputHandler { } let _seat_listener = - env.listen_for_seats(move |seat, seat_data, _| seat_handler(seat, &seat_data)); + env.listen_for_seats(move |seat, seat_data, _| seat_handler(seat, seat_data)); (Self { _seat_listener }, rx) } diff --git a/src/main.rs b/src/main.rs index b373f11..6319500 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,8 +43,6 @@ macro_rules! prog_name { }; } -const DEFAULT_LOG_PATH: &str = concat!(concat!("/tmp/", prog_name!()), ".log"); - fn setup_logger(level: LevelFilter, log_file: impl AsRef) { fern::Dispatch::new() .format(|out, message, record| { @@ -97,14 +95,18 @@ fn main() { let mut config = config::Config::load(args.config_file.take()); - setup_logger( - match (args.verbose, args.quiet) { - (true, _) => LevelFilter::Debug, - (_, true) => LevelFilter::Warn, - _ => LevelFilter::Info, - }, - args.log_file.unwrap_or_else(|| DEFAULT_LOG_PATH.into()), - ); + let log_level = match (args.verbose, args.quiet) { + (true, _) => LevelFilter::Debug, + (_, true) => LevelFilter::Warn, + _ => LevelFilter::Info, + }; + if let Some(log_file) = args.log_file { + setup_logger(log_level, log_file); + } else { + const VERSION: &str = env!("CARGO_PKG_VERSION"); + systemd_journal_logger::init_with_extra_fields(vec![("VERSION", VERSION)]).unwrap(); + log::set_max_level(LevelFilter::Info); + } let (env, display, queue) = sctk::new_default_environment!(Env, desktop, fields = [layer_shell: SimpleGlobal::new()]) @@ -173,7 +175,7 @@ fn draw(state: &mut state::State, config: &config::Config, surface: &mut surface let (tx, rx) = oneshot::channel(); let background = draw::Widget::background(config.param()); - let input_widget = draw::Widget::input_text(&state.raw_input(), config.param()); + let input_widget = draw::Widget::input_text(state.raw_input(), config.param()); let list_view_widget = draw::Widget::list_view( state.processed_entries(), state.skip_offset(), diff --git a/src/mode.rs b/src/mode.rs index f3728b2..36b0dd3 100644 --- a/src/mode.rs +++ b/src/mode.rs @@ -24,9 +24,9 @@ macro_rules! delegate { (pub fn $name:ident ( & $([$m:ident])? self, $($ident:ident : $tp:ty),* ) -> $ret:ty $(, wrap_with ($wrap:path))?) => { pub fn $name ( & $($m)? self, $($ident : $tp),* ) -> $ret { match self { - Mode::AppsMode(mode) => $($wrap)?(mode.$name($($ident),*)), - Mode::BinAppsMode(mode) => $($wrap)?(mode.$name($($ident),*)), - Mode::DialogMode(mode) => $($wrap)?(mode.$name($($ident),*)), + Mode::Apps(mode) => $($wrap)?(mode.$name($($ident),*)), + Mode::BinApps(mode) => $($wrap)?(mode.$name($($ident),*)), + Mode::Dialog(mode) => $($wrap)?(mode.$name($($ident),*)), } } } @@ -46,9 +46,9 @@ impl<'a> std::ops::Deref for EvalInfo<'a> { } pub enum Mode { - AppsMode(apps::AppsMode), - BinAppsMode(bins::BinsMode), - DialogMode(dialog::DialogMode), + Apps(apps::AppsMode), + BinApps(bins::BinsMode), + Dialog(dialog::DialogMode), } pub struct Entry<'a> { @@ -58,15 +58,15 @@ pub struct Entry<'a> { impl Mode { pub fn apps(entries: Vec, term: Vec) -> Self { - Self::AppsMode(apps::AppsMode::new(entries, term)) + Self::Apps(apps::AppsMode::new(entries, term)) } pub fn bins(term: Vec) -> Self { - Self::BinAppsMode(bins::BinsMode::new(term)) + Self::BinApps(bins::BinsMode::new(term)) } pub fn dialog() -> Self { - Self::DialogMode(dialog::DialogMode::new()) + Self::Dialog(dialog::DialogMode::new()) } delegate!(pub fn eval(&mut self, info: EvalInfo<'_>) -> std::convert::Infallible); @@ -75,9 +75,9 @@ impl Mode { pub fn text_entries(&self) -> impl Iterator + ExactSizeIterator + '_ { match self { - Mode::AppsMode(mode) => Either::Left(Either::Right(mode.text_entries())), - Mode::BinAppsMode(mode) => Either::Left(Either::Left(mode.text_entries())), - Mode::DialogMode(mode) => Either::Right(mode.text_entries()), + Mode::Apps(mode) => Either::Left(Either::Right(mode.text_entries())), + Mode::BinApps(mode) => Either::Left(Either::Left(mode.text_entries())), + Mode::Dialog(mode) => Either::Right(mode.text_entries()), } .into_iter() } diff --git a/src/mode/apps.rs b/src/mode/apps.rs index 1002035..fe0482a 100644 --- a/src/mode/apps.rs +++ b/src/mode/apps.rs @@ -40,7 +40,7 @@ impl AppsMode { self.usage.try_update_cache(CACHE_PATH); let term = if entry.is_terminal { - Some(std::mem::replace(&mut self.term, Vec::new())) + Some(std::mem::take(&mut self.term)) } else { None }; diff --git a/src/mode/bins.rs b/src/mode/bins.rs index 3953273..b1caa60 100644 --- a/src/mode/bins.rs +++ b/src/mode/bins.rs @@ -47,7 +47,7 @@ impl BinsMode { Reverse(x_usage_count) .cmp(&Reverse(y_usage_count)) - .then_with(|| x.cmp(&y)) + .then_with(|| x.cmp(y)) }); bins.dedup(); @@ -69,7 +69,7 @@ impl BinsMode { let fname_str = fname.to_str().unwrap(); entry_name_cache.insert( - Rc::clone(&bin), + Rc::clone(bin), format!("{} ({})", fname_str, bin.to_str().unwrap()), ); } @@ -93,7 +93,7 @@ impl BinsMode { self.usage.try_update_cache(CACHE_PATH); crate::exec::exec( - Some(std::mem::replace(&mut self.term, Vec::new())), + Some(std::mem::take(&mut self.term)), vec![CString::new(binary).expect("invalid binary")], info.input_value, )