summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2020-03-08 00:35:01 -0500
committerGitHub <noreply@github.com>2020-03-08 00:35:01 -0500
commit226c4e5a681f66db7bf5a263804332d201ced98c (patch)
treec50cc51a0211f3873388f3d50618f4e22654764b /src
parent6342686e2243cd8ecb4f47b604caf5520919c34a (diff)
Clean up and manage some basic stuff (#73)
* Remove debug statement. * Remove redundant functions from main * Update pull request template. * Format temperature line. * Update README for chocolatey. * Add note about basic mode and htop's inspiration.
Diffstat (limited to 'src')
-rw-r--r--src/canvas.rs1
-rw-r--r--src/main.rs208
-rw-r--r--src/options.rs22
3 files changed, 9 insertions, 222 deletions
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<Config> {
}
}
-fn get_update_rate_in_milliseconds(
- update_rate: &Option<&str>, config: &Config,
-) -> error::Result<u128> {
- let update_rate_in_milliseconds = if let Some(update_rate) = update_rate {
- update_rate.parse::<u128>()?
- } 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<data_harvester::temperature::TemperatureType> {
- 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 \
- <kelvin|k|celsius|c|fahrenheit|f>"
- .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<tui::backend::CrosstermBackend<std::io::Stdout>>,
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 <kelvin|k|celsius|c|fahrenheit|f>".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 \
+ <kelvin|k|celsius|c|fahrenheit|f>"
+ .to_string(),
+ )),
};
}
}