diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2023-06-12 05:01:07 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-12 01:01:07 -0400 |
commit | 531e26ea45e537a29dffe9438bc5085750574571 (patch) | |
tree | ac47a05d6b6422e79937dd6189f6a348e929a431 | |
parent | cfdfd2bd3f6877ebe4fcfc9d359caeebbabf8911 (diff) |
other: post-0.9.2 cleanup (#1203)
* other: some cleanup
* other: add conditional logging macros
* more cleanup
* use compile-time feature for some text in clap
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/app/data_harvester/disks.rs | 2 | ||||
-rw-r--r-- | src/bin/main.rs | 11 | ||||
-rw-r--r-- | src/clap.rs | 13 | ||||
-rw-r--r-- | src/lib.rs | 15 | ||||
-rw-r--r-- | src/utils.rs | 3 | ||||
-rw-r--r-- | src/utils/logging.rs | 62 |
9 files changed, 79 insertions, 33 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index a448efde..819abcf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ 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/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.9.3]/[0.10.0] - Unreleased + ## [0.9.2] - 2023-06-11 ## Bug Fixes @@ -142,7 +142,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bottom" -version = "0.9.2" +version = "0.9.3" dependencies = [ "anyhow", "assert_cmd", @@ -1,6 +1,6 @@ [package] name = "bottom" -version = "0.9.2" +version = "0.9.3" authors = ["Clement Tsang <cjhtsang@uwaterloo.ca>"] edition = "2021" repository = "https://github.com/ClementTsang/bottom" diff --git a/src/app/data_harvester/disks.rs b/src/app/data_harvester/disks.rs index ddb07073..3359fcc7 100644 --- a/src/app/data_harvester/disks.rs +++ b/src/app/data_harvester/disks.rs @@ -24,7 +24,7 @@ cfg_if! { } } -#[derive(Debug, Clone, Default)] +#[derive(Clone, Debug, Default)] pub struct DiskHarvest { pub name: String, pub mount_point: String, diff --git a/src/bin/main.rs b/src/bin/main.rs index 18a181f7..06757971 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -3,15 +3,6 @@ #![deny(clippy::unimplemented)] #![deny(clippy::missing_safety_doc)] -// Primarily used for debug purposes. -cfg_if::cfg_if! { - if #[cfg(feature = "log")] { - #[allow(unused_imports)] - #[macro_use] - extern crate log; - } -} - use std::{ boxed::Box, io::stdout, @@ -44,7 +35,7 @@ fn main() -> Result<()> { // let _profiler = dhat::Profiler::new_heap(); let matches = clap::get_matches(); - #[cfg(all(feature = "fern"))] + #[cfg(feature = "logging")] { if let Err(err) = utils::logging::init_logger(log::LevelFilter::Debug, std::ffi::OsStr::new("debug.log")) diff --git a/src/clap.rs b/src/clap.rs index 1b57a7ba..91fb63cb 100644 --- a/src/clap.rs +++ b/src/clap.rs @@ -13,8 +13,10 @@ const TEMPLATE: &str = "\ const USAGE: &str = "btm [OPTIONS]"; -const DEFAULT_WIDGET_TYPE_STR: &str = if cfg!(feature = "battery") { - "\ +const DEFAULT_WIDGET_TYPE_STR: &str = { + #[cfg(feature = "battery")] + { + "\ Sets which widget type to use as the default widget. For the default layout, this defaults to the 'process' widget. For a custom layout, it defaults to the first widget it sees. @@ -46,8 +48,10 @@ Supported widget names: | batt, battery | +--------------------------+ " -} else { - "\ + } + #[cfg(not(feature = "battery"))] + { + "\ Sets which widget type to use as the default widget. For the default layout, this defaults to the 'process' widget. For a custom layout, it defaults to the first widget it sees. @@ -77,6 +81,7 @@ Supported widget names: | disk | +--------------------------+ " + } }; pub fn get_matches() -> clap::ArgMatches { @@ -10,15 +10,6 @@ #![deny(clippy::unimplemented)] #![deny(clippy::missing_safety_doc)] -// Primarily used for debug purposes. -cfg_if::cfg_if! { - if #[cfg(feature = "log")] { - #[allow(unused_imports)] - #[macro_use] - extern crate log; - } -} - use std::{ boxed::Box, fs, @@ -69,6 +60,8 @@ pub mod options; pub mod units; pub mod widgets; +pub use utils::logging::*; + #[cfg(target_family = "windows")] pub type Pid = usize; @@ -117,7 +110,7 @@ pub fn handle_mouse_event(event: MouseEvent, app: &mut App) { pub fn handle_key_event_or_break( event: KeyEvent, app: &mut App, reset_sender: &Sender<CollectionThreadEvent>, ) -> bool { - // debug!("KeyEvent: {:?}", event); + // c_debug!("KeyEvent: {:?}", event); if event.modifiers.is_empty() { // Required catch for searching - otherwise you couldn't search with q. @@ -154,8 +147,6 @@ pub fn handle_key_event_or_break( KeyCode::Char('c') | KeyCode::Char('C') => app.toggle_ignore_case(), KeyCode::Char('w') | KeyCode::Char('W') => app.toggle_search_whole_word(), KeyCode::Char('r') | KeyCode::Char('R') => app.toggle_search_regex(), - // KeyCode::Char('b') | KeyCode::Char('B') => todo!(), - // KeyCode::Char('f') | KeyCode::Char('F') => todo!(), KeyCode::Char('h') => app.on_left_key(), KeyCode::Char('l') => app.on_right_key(), _ => {} diff --git a/src/utils.rs b/src/utils.rs deleted file mode 100644 index 22fbdf53..00000000 --- a/src/utils.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod error; -pub mod gen_util; -pub mod logging; diff --git a/src/utils/logging.rs b/src/utils/logging.rs index ed1578d2..312c909f 100644 --- a/src/utils/logging.rs +++ b/src/utils/logging.rs @@ -1,4 +1,4 @@ -#[cfg(feature = "fern")] +#[cfg(feature = "logging")] pub fn init_logger( min_level: log::LevelFilter, debug_file_name: &std::ffi::OsStr, ) -> Result<(), fern::InitError> { @@ -28,3 +28,63 @@ pub fn init_logger( Ok(()) } + +#[macro_export] +macro_rules! c_debug { + ($($x:tt)*) => { + #[cfg(feature = "logging")] + { + log::debug!($($x)*) + } + }; +} + +#[macro_export] +macro_rules! c_error { + ($($x:tt)*) => { + #[cfg(feature = "logging")] + { + log::error!($($x)*) + } + }; +} + +#[macro_export] +macro_rules! c_info { + ($($x:tt)*) => { + #[cfg(feature = "logging")] + { + log::info!($($x)*) + } + }; +} + +#[macro_export] +macro_rules! c_log { + ($($x:tt)*) => { + #[cfg(feature = "logging")] + { + log::log!($($x)*) + } + }; +} + +#[macro_export] +macro_rules! c_trace { + ($($x:tt)*) => { + #[cfg(feature = "logging")] + { + log::trace!($($x)*) + } + }; +} + +#[macro_export] +macro_rules! c_warn { + ($($x:tt)*) => { + #[cfg(feature = "logging")] + { + log::warn!($($x)*) + } + }; +} |