diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index c0ed35fc..28afc4f9 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -10,18 +10,16 @@ Closes: # ## Type of change -_Remove the irrelevant one:_ +_Remove the irrelevant ones:_ - [x] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) -- [x] Other (something else) +- [x] Other (something else - please specify if relevant) ## Test methodology _Please state how this was tested:_ - - _Please tick which platforms this change was tested on:_ - [ ] Windows diff --git a/README.md b/README.md index 0efb9cf9..e98a72b7 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ You can get the release versions from the AUR by installing [`bottom`](https://a ```bash yay bottom -#Or +# Or yay bottom-bin ``` @@ -77,10 +77,12 @@ sudo dpkg -i bottom_0.2.2_amd64.deb ### Windows -You can get release versions via [Chocolatey](https://chocolatey.org/packages/bottom/) (note it may take a while to be available due to moderation/review): +You can get release versions via [Chocolatey](https://chocolatey.org/packages/bottom/): ```bash -choco install bottom --version=0.2.1 +choco install bottom +# Or +choco install bottom --version=0.2.1 # Version may be required for newer releases ``` ### macOS @@ -212,7 +214,7 @@ Note that `q` is disabled while in the search widget. ## Bugs and Requests -Spot an bug? Have an idea? Leave an issue that explains what you want in detail and I'll try to take a look. +Spot an bug? Have an idea? Leave an issue that explains what you want in detail and I'll try to take a look. ## Contribution @@ -230,6 +232,8 @@ Thanks to those who have contributed: - This project is very much inspired by both [gotop](https://github.com/cjbassi/gotop) and [gtop](https://github.com/aksakalli/gtop). +- Basic mode inspired by htop's design. + - This application was written with the following libraries, and would otherwise not be possible: - [backtrace](https://github.com/rust-lang/backtrace-rs) diff --git a/src/canvas.rs b/src/canvas.rs index aa7e8478..b98ec99d 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -146,7 +146,6 @@ impl Painter { terminal.autoresize()?; terminal.draw(|mut f| { - debug!("{:?}", f.size()); if app_state.help_dialog_state.is_showing_help { // Only for the help diff --git a/src/main.rs b/src/main.rs index 092722fa..f763e1ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,7 +36,7 @@ use app::{ use constants::*; use data_conversion::*; use options::*; -use utils::error::{self, BottomError}; +use utils::error; pub mod app; @@ -423,212 +423,6 @@ fn create_config(flag_config_location: Option<&str>) -> error::Result { } } -fn get_update_rate_in_milliseconds( - update_rate: &Option<&str>, config: &Config, -) -> error::Result { - let update_rate_in_milliseconds = if let Some(update_rate) = update_rate { - update_rate.parse::()? - } else if let Some(flags) = &config.flags { - if let Some(rate) = flags.rate { - rate as u128 - } else { - constants::DEFAULT_REFRESH_RATE_IN_MILLISECONDS - } - } else { - constants::DEFAULT_REFRESH_RATE_IN_MILLISECONDS - }; - - if update_rate_in_milliseconds < 250 { - return Err(BottomError::InvalidArg( - "Please set your update rate to be greater than 250 milliseconds.".to_string(), - )); - } else if update_rate_in_milliseconds > u128::from(std::u64::MAX) { - return Err(BottomError::InvalidArg( - "Please set your update rate to be less than unsigned INT_MAX.".to_string(), - )); - } - - Ok(update_rate_in_milliseconds) -} - -fn get_temperature_option( - matches: &clap::ArgMatches<'static>, config: &Config, -) -> error::Result { - if matches.is_present("FAHRENHEIT") { - return Ok(data_harvester::temperature::TemperatureType::Fahrenheit); - } else if matches.is_present("KELVIN") { - return Ok(data_harvester::temperature::TemperatureType::Kelvin); - } else if matches.is_present("CELSIUS") { - return Ok(data_harvester::temperature::TemperatureType::Celsius); - } else if let Some(flags) = &config.flags { - if let Some(temp_type) = &flags.temperature_type { - // Give lowest priority to config. - return match temp_type.as_str() { - "fahrenheit" | "f" => Ok(data_harvester::temperature::TemperatureType::Fahrenheit), - "kelvin" | "k" => Ok(data_harvester::temperature::TemperatureType::Kelvin), - "celsius" | "c" => Ok(data_harvester::temperature::TemperatureType::Celsius), - _ => Err(BottomError::ConfigError( - "Invalid temperature type. Please have the value be of the form \ - " - .to_string(), - )), - }; - } - } - Ok(data_harvester::temperature::TemperatureType::Celsius) -} - -fn get_avg_cpu_option(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { - if matches.is_present("AVG_CPU") { - return true; - } else if let Some(flags) = &config.flags { - if let Some(avg_cpu) = flags.avg_cpu { - return avg_cpu; - } - } - - false -} - -fn get_use_dot_option(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { - if matches.is_present("DOT_MARKER") { - return true; - } else if let Some(flags) = &config.flags { - if let Some(dot_marker) = flags.dot_marker { - return dot_marker; - } - } - false -} - -fn get_use_left_legend_option(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { - if matches.is_present("LEFT_LEGEND") { - return true; - } else if let Some(flags) = &config.flags { - if let Some(left_legend) = flags.left_legend { - return left_legend; - } - } - - false -} - -fn get_use_current_cpu_total_option(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { - if matches.is_present("USE_CURR_USAGE") { - return true; - } else if let Some(flags) = &config.flags { - if let Some(current_usage) = flags.current_usage { - return current_usage; - } - } - - false -} - -fn get_show_disabled_data_option(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { - if matches.is_present("SHOW_DISABLED_DATA") { - return true; - } else if let Some(flags) = &config.flags { - if let Some(show_disabled_data) = flags.show_disabled_data { - return show_disabled_data; - } - } - - false -} - -fn enable_app_grouping(matches: &clap::ArgMatches<'static>, config: &Config, app: &mut App) { - if matches.is_present("GROUP_PROCESSES") { - app.toggle_grouping(); - } else if let Some(flags) = &config.flags { - if let Some(grouping) = flags.group_processes { - if grouping { - app.toggle_grouping(); - } - } - } -} - -fn enable_app_case_sensitive(matches: &clap::ArgMatches<'static>, config: &Config, app: &mut App) { - if matches.is_present("CASE_SENSITIVE") { - app.process_search_state.search_toggle_ignore_case(); - } else if let Some(flags) = &config.flags { - if let Some(case_sensitive) = flags.case_sensitive { - if case_sensitive { - app.process_search_state.search_toggle_ignore_case(); - } - } - } -} - -fn enable_app_match_whole_word( - matches: &clap::ArgMatches<'static>, config: &Config, app: &mut App, -) { - if matches.is_present("WHOLE_WORD") { - app.process_search_state.search_toggle_whole_word(); - } else if let Some(flags) = &config.flags { - if let Some(whole_word) = flags.whole_word { - if whole_word { - app.process_search_state.search_toggle_whole_word(); - } - } - } -} - -fn enable_app_use_regex(matches: &clap::ArgMatches<'static>, config: &Config, app: &mut App) { - if matches.is_present("REGEX_DEFAULT") { - app.process_search_state.search_toggle_regex(); - } else if let Some(flags) = &config.flags { - if let Some(regex) = flags.regex { - if regex { - app.process_search_state.search_toggle_regex(); - } - } - } -} - -fn get_default_widget(matches: &clap::ArgMatches<'static>, config: &Config) -> app::WidgetPosition { - if matches.is_present("CPU_WIDGET") { - return app::WidgetPosition::Cpu; - } else if matches.is_present("MEM_WIDGET") { - return app::WidgetPosition::Mem; - } else if matches.is_present("DISK_WIDGET") { - return app::WidgetPosition::Disk; - } else if matches.is_present("TEMP_WIDGET") { - return app::WidgetPosition::Temp; - } else if matches.is_present("NET_WIDGET") { - return app::WidgetPosition::Network; - } else if matches.is_present("PROC_WIDGET") { - return app::WidgetPosition::Process; - } else if let Some(flags) = &config.flags { - if let Some(default_widget) = &flags.default_widget { - match default_widget.as_str() { - "cpu_default" => { - return app::WidgetPosition::Cpu; - } - "memory_default" => { - return app::WidgetPosition::Mem; - } - "processes_default" => { - return app::WidgetPosition::Process; - } - "network_default" => { - return app::WidgetPosition::Network; - } - "temperature_default" => { - return app::WidgetPosition::Temp; - } - "disk_default" => { - return app::WidgetPosition::Disk; - } - _ => {} - } - } - } - - app::WidgetPosition::Process -} - fn try_drawing( terminal: &mut tui::terminal::Terminal>, app: &mut App, painter: &mut canvas::Painter, diff --git a/src/options.rs b/src/options.rs index fc92a915..372165bd 100644 --- a/src/options.rs +++ b/src/options.rs @@ -91,20 +91,14 @@ pub fn get_temperature_option( if let Some(temp_type) = &flags.temperature_type { // Give lowest priority to config. return match temp_type.as_str() { - "fahrenheit" | "f" => { - Ok(data_harvester::temperature::TemperatureType::Fahrenheit) - } - "kelvin" | "k" => { - Ok(data_harvester::temperature::TemperatureType::Kelvin) - } - "celsius" | "c" => { - Ok(data_harvester::temperature::TemperatureType::Celsius) - } - _ => { - Err(BottomError::ConfigError( - "Invalid temperature type. Please have the value be of the form ".to_string() - )) - } + "fahrenheit" | "f" => Ok(data_harvester::temperature::TemperatureType::Fahrenheit), + "kelvin" | "k" => Ok(data_harvester::temperature::TemperatureType::Kelvin), + "celsius" | "c" => Ok(data_harvester::temperature::TemperatureType::Celsius), + _ => Err(BottomError::ConfigError( + "Invalid temperature type. Please have the value be of the form \ + " + .to_string(), + )), }; } }