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
This commit is contained in:
Clement Tsang 2023-06-12 05:01:07 +00:00 committed by GitHub
parent cfdfd2bd3f
commit 531e26ea45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 79 additions and 33 deletions

View file

@ -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/), 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). 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 ## [0.9.2] - 2023-06-11
## Bug Fixes ## Bug Fixes

2
Cargo.lock generated
View file

@ -142,7 +142,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]] [[package]]
name = "bottom" name = "bottom"
version = "0.9.2" version = "0.9.3"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"assert_cmd", "assert_cmd",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "bottom" name = "bottom"
version = "0.9.2" version = "0.9.3"
authors = ["Clement Tsang <cjhtsang@uwaterloo.ca>"] authors = ["Clement Tsang <cjhtsang@uwaterloo.ca>"]
edition = "2021" edition = "2021"
repository = "https://github.com/ClementTsang/bottom" repository = "https://github.com/ClementTsang/bottom"

View file

@ -24,7 +24,7 @@ cfg_if! {
} }
} }
#[derive(Debug, Clone, Default)] #[derive(Clone, Debug, Default)]
pub struct DiskHarvest { pub struct DiskHarvest {
pub name: String, pub name: String,
pub mount_point: String, pub mount_point: String,

View file

@ -3,15 +3,6 @@
#![deny(clippy::unimplemented)] #![deny(clippy::unimplemented)]
#![deny(clippy::missing_safety_doc)] #![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::{ use std::{
boxed::Box, boxed::Box,
io::stdout, io::stdout,
@ -44,7 +35,7 @@ fn main() -> Result<()> {
// let _profiler = dhat::Profiler::new_heap(); // let _profiler = dhat::Profiler::new_heap();
let matches = clap::get_matches(); let matches = clap::get_matches();
#[cfg(all(feature = "fern"))] #[cfg(feature = "logging")]
{ {
if let Err(err) = if let Err(err) =
utils::logging::init_logger(log::LevelFilter::Debug, std::ffi::OsStr::new("debug.log")) utils::logging::init_logger(log::LevelFilter::Debug, std::ffi::OsStr::new("debug.log"))

View file

@ -13,8 +13,10 @@ const TEMPLATE: &str = "\
const USAGE: &str = "btm [OPTIONS]"; 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. Sets which widget type to use as the default widget.
For the default layout, this defaults to the 'process' widget. For the default layout, this defaults to the 'process' widget.
For a custom layout, it defaults to the first widget it sees. For a custom layout, it defaults to the first widget it sees.
@ -46,8 +48,10 @@ Supported widget names:
| batt, battery | | batt, battery |
+--------------------------+ +--------------------------+
" "
} else { }
"\ #[cfg(not(feature = "battery"))]
{
"\
Sets which widget type to use as the default widget. Sets which widget type to use as the default widget.
For the default layout, this defaults to the 'process' widget. For the default layout, this defaults to the 'process' widget.
For a custom layout, it defaults to the first widget it sees. For a custom layout, it defaults to the first widget it sees.
@ -77,6 +81,7 @@ Supported widget names:
| disk | | disk |
+--------------------------+ +--------------------------+
" "
}
}; };
pub fn get_matches() -> clap::ArgMatches { pub fn get_matches() -> clap::ArgMatches {

View file

@ -10,15 +10,6 @@
#![deny(clippy::unimplemented)] #![deny(clippy::unimplemented)]
#![deny(clippy::missing_safety_doc)] #![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::{ use std::{
boxed::Box, boxed::Box,
fs, fs,
@ -69,6 +60,8 @@ pub mod options;
pub mod units; pub mod units;
pub mod widgets; pub mod widgets;
pub use utils::logging::*;
#[cfg(target_family = "windows")] #[cfg(target_family = "windows")]
pub type Pid = usize; 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( pub fn handle_key_event_or_break(
event: KeyEvent, app: &mut App, reset_sender: &Sender<CollectionThreadEvent>, event: KeyEvent, app: &mut App, reset_sender: &Sender<CollectionThreadEvent>,
) -> bool { ) -> bool {
// debug!("KeyEvent: {:?}", event); // c_debug!("KeyEvent: {:?}", event);
if event.modifiers.is_empty() { if event.modifiers.is_empty() {
// Required catch for searching - otherwise you couldn't search with q. // 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('c') | KeyCode::Char('C') => app.toggle_ignore_case(),
KeyCode::Char('w') | KeyCode::Char('W') => app.toggle_search_whole_word(), KeyCode::Char('w') | KeyCode::Char('W') => app.toggle_search_whole_word(),
KeyCode::Char('r') | KeyCode::Char('R') => app.toggle_search_regex(), 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('h') => app.on_left_key(),
KeyCode::Char('l') => app.on_right_key(), KeyCode::Char('l') => app.on_right_key(),
_ => {} _ => {}

View file

@ -1,3 +0,0 @@
pub mod error;
pub mod gen_util;
pub mod logging;

View file

@ -1,4 +1,4 @@
#[cfg(feature = "fern")] #[cfg(feature = "logging")]
pub fn init_logger( pub fn init_logger(
min_level: log::LevelFilter, debug_file_name: &std::ffi::OsStr, min_level: log::LevelFilter, debug_file_name: &std::ffi::OsStr,
) -> Result<(), fern::InitError> { ) -> Result<(), fern::InitError> {
@ -28,3 +28,63 @@ pub fn init_logger(
Ok(()) 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)*)
}
};
}