mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-10 14:44:18 +00:00
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:
parent
cfdfd2bd3f
commit
531e26ea45
9 changed files with 79 additions and 33 deletions
|
@ -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
|
||||
|
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -24,7 +24,7 @@ cfg_if! {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct DiskHarvest {
|
||||
pub name: String,
|
||||
pub mount_point: String,
|
||||
|
|
|
@ -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"))
|
||||
|
|
13
src/clap.rs
13
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 {
|
||||
|
|
15
src/lib.rs
15
src/lib.rs
|
@ -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(),
|
||||
_ => {}
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
pub mod error;
|
||||
pub mod gen_util;
|
||||
pub mod logging;
|
|
@ -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)*)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue