mirror of
				https://github.com/ClementTsang/bottom.git
				synced 2025-10-31 03:04:01 +01:00 
			
		
		
		
	More merge conflicts.
This commit is contained in:
		
							parent
							
								
									fee8b5c8a1
								
							
						
					
					
						commit
						26c1175a8a
					
				
							
								
								
									
										386
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										386
									
								
								src/main.rs
									
									
									
									
									
								
							| @ -6,7 +6,7 @@ extern crate clap; | |||||||
| extern crate futures; | extern crate futures; | ||||||
| #[macro_use] | #[macro_use] | ||||||
| extern crate lazy_static; | extern crate lazy_static; | ||||||
| #[macro_use]CEvent | #[macro_use] | ||||||
| extern crate log; | extern crate log; | ||||||
| 
 | 
 | ||||||
| use std::{ | use std::{ | ||||||
| @ -36,7 +36,7 @@ use app::{ | |||||||
| use constants::*; | use constants::*; | ||||||
| use data_conversion::*; | use data_conversion::*; | ||||||
| use options::*; | use options::*; | ||||||
| use utils::error::{self}; | use utils::error::{self, BottomError}; | ||||||
| 
 | 
 | ||||||
| pub mod app; | pub mod app; | ||||||
| 
 | 
 | ||||||
| @ -392,250 +392,242 @@ fn create_logger() -> error::Result<()> { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn create_config(flag_config_location: Option<&str>) -> error::Result<Config> { | fn create_config(flag_config_location: Option<&str>) -> error::Result<Config> { | ||||||
| 	use std::{ffi::OsString, fs}; |     use std::{ffi::OsString, fs}; | ||||||
| 	let config_path = if let Some(conf_loc) = flag_config_location { |     let config_path = if let Some(conf_loc) = flag_config_location { | ||||||
| 		OsString::from(conf_loc) |         OsString::from(conf_loc) | ||||||
| 	} else if cfg!(target_os = "windows") { |     } else if cfg!(target_os = "windows") { | ||||||
| 		if let Some(home_path) = dirs::config_dir() { |         if let Some(home_path) = dirs::config_dir() { | ||||||
| 			let mut path = home_path; |             let mut path = home_path; | ||||||
| 			path.push(DEFAULT_WINDOWS_CONFIG_FILE_PATH); |             path.push(DEFAULT_WINDOWS_CONFIG_FILE_PATH); | ||||||
| 			path.into_os_string() |             path.into_os_string() | ||||||
| 		} else { |         } else { | ||||||
| 			OsString::new() |             OsString::new() | ||||||
| 		} |         } | ||||||
| 	} else if let Some(home_path) = dirs::home_dir() { |     } else if let Some(home_path) = dirs::home_dir() { | ||||||
| 		let mut path = home_path; |         let mut path = home_path; | ||||||
| 		path.push(DEFAULT_UNIX_CONFIG_FILE_PATH); |         path.push(DEFAULT_UNIX_CONFIG_FILE_PATH); | ||||||
| 		path.into_os_string() |         path.into_os_string() | ||||||
| 	} else { |     } else { | ||||||
| 		OsString::new() |         OsString::new() | ||||||
| 	}; |     }; | ||||||
| 
 | 
 | ||||||
| 	let path = std::path::Path::new(&config_path); |     let path = std::path::Path::new(&config_path); | ||||||
| 
 | 
 | ||||||
| 	if let Ok(config_string) = fs::read_to_string(path) { |     if let Ok(config_string) = fs::read_to_string(path) { | ||||||
| 		Ok(toml::from_str(config_string.as_str())?) |         Ok(toml::from_str(config_string.as_str())?) | ||||||
| 	} else { |     } else { | ||||||
| 		if let Some(parent_path) = path.parent() { |         if let Some(parent_path) = path.parent() { | ||||||
| 			fs::create_dir_all(parent_path)?; |             fs::create_dir_all(parent_path)?; | ||||||
| 		} |         } | ||||||
| 		fs::File::create(path)?.write_all(DEFAULT_CONFIG_CONTENT.as_bytes())?; |         fs::File::create(path)?.write_all(DEFAULT_CONFIG_CONTENT.as_bytes())?; | ||||||
| 		Ok(toml::from_str(DEFAULT_CONFIG_CONTENT)?) |         Ok(toml::from_str(DEFAULT_CONFIG_CONTENT)?) | ||||||
| 	} |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn get_update_rate_in_milliseconds( | fn get_update_rate_in_milliseconds( | ||||||
| 	update_rate: &Option<&str>, config: &Config, |     update_rate: &Option<&str>, config: &Config, | ||||||
| ) -> error::Result<u128> { | ) -> error::Result<u128> { | ||||||
| 	let update_rate_in_milliseconds = if let Some(update_rate) = update_rate { |     let update_rate_in_milliseconds = if let Some(update_rate) = update_rate { | ||||||
| 		update_rate.parse::<u128>()? |         update_rate.parse::<u128>()? | ||||||
| 	} else if let Some(flags) = &config.flags { |     } else if let Some(flags) = &config.flags { | ||||||
| 		if let Some(rate) = flags.rate { |         if let Some(rate) = flags.rate { | ||||||
| 			rate as u128 |             rate as u128 | ||||||
| 		} else { |         } else { | ||||||
| 			constants::DEFAULT_REFRESH_RATE_IN_MILLISECONDS |             constants::DEFAULT_REFRESH_RATE_IN_MILLISECONDS | ||||||
| 		} |         } | ||||||
| 	} else { |     } else { | ||||||
| 		constants::DEFAULT_REFRESH_RATE_IN_MILLISECONDS |         constants::DEFAULT_REFRESH_RATE_IN_MILLISECONDS | ||||||
| 	}; |     }; | ||||||
| 
 | 
 | ||||||
| 	if update_rate_in_milliseconds < 250 { |     if update_rate_in_milliseconds < 250 { | ||||||
| 		return Err(BottomError::InvalidArg( |         return Err(BottomError::InvalidArg( | ||||||
| 			"Please set your update rate to be greater than 250 milliseconds.".to_string(), |             "Please set your update rate to be greater than 250 milliseconds.".to_string(), | ||||||
| 		)); |         )); | ||||||
| 	} else if update_rate_in_milliseconds > u128::from(std::u64::MAX) { |     } else if update_rate_in_milliseconds > u128::from(std::u64::MAX) { | ||||||
| 		return Err(BottomError::InvalidArg( |         return Err(BottomError::InvalidArg( | ||||||
| 			"Please set your update rate to be less than unsigned INT_MAX.".to_string(), |             "Please set your update rate to be less than unsigned INT_MAX.".to_string(), | ||||||
| 		)); |         )); | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	Ok(update_rate_in_milliseconds) |     Ok(update_rate_in_milliseconds) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn get_temperature_option( | fn get_temperature_option( | ||||||
| 	matches: &clap::ArgMatches<'static>, config: &Config, |     matches: &clap::ArgMatches<'static>, config: &Config, | ||||||
| ) -> error::Result<data_harvester::temperature::TemperatureType> { | ) -> error::Result<data_harvester::temperature::TemperatureType> { | ||||||
| 	if matches.is_present("FAHRENHEIT") { |     if matches.is_present("FAHRENHEIT") { | ||||||
| 		return Ok(data_harvester::temperature::TemperatureType::Fahrenheit); |         return Ok(data_harvester::temperature::TemperatureType::Fahrenheit); | ||||||
| 	} else if matches.is_present("KELVIN") { |     } else if matches.is_present("KELVIN") { | ||||||
| 		return Ok(data_harvester::temperature::TemperatureType::Kelvin); |         return Ok(data_harvester::temperature::TemperatureType::Kelvin); | ||||||
| 	} else if matches.is_present("CELSIUS") { |     } else if matches.is_present("CELSIUS") { | ||||||
| 		return Ok(data_harvester::temperature::TemperatureType::Celsius); |         return Ok(data_harvester::temperature::TemperatureType::Celsius); | ||||||
| 	} else if let Some(flags) = &config.flags { |     } else if let Some(flags) = &config.flags { | ||||||
| 		if let Some(temp_type) = &flags.temperature_type { |         if let Some(temp_type) = &flags.temperature_type { | ||||||
| 			// Give lowest priority to config.
 |             // Give lowest priority to config.
 | ||||||
| 			return match temp_type.as_str() { |             return match temp_type.as_str() { | ||||||
| 				"fahrenheit" | "f" => { |                 "fahrenheit" | "f" => Ok(data_harvester::temperature::TemperatureType::Fahrenheit), | ||||||
| 					Ok(data_harvester::temperature::TemperatureType::Fahrenheit) |                 "kelvin" | "k" => Ok(data_harvester::temperature::TemperatureType::Kelvin), | ||||||
| 				} |                 "celsius" | "c" => Ok(data_harvester::temperature::TemperatureType::Celsius), | ||||||
| 				"kelvin" | "k" => { |                 _ => Err(BottomError::ConfigError( | ||||||
| 					Ok(data_harvester::temperature::TemperatureType::Kelvin) |                     "Invalid temperature type.  Please have the value be of the form \ | ||||||
| 				} |  | ||||||
| 				"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>" | 						 <kelvin|k|celsius|c|fahrenheit|f>" | ||||||
| 							.to_string(), |                         .to_string(), | ||||||
| 					)) |                 )), | ||||||
| 				} |             }; | ||||||
| 			} |         } | ||||||
| 		} |     } | ||||||
| 	} |     Ok(data_harvester::temperature::TemperatureType::Celsius) | ||||||
| 	Ok(data_harvester::temperature::TemperatureType::Celsius) |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn get_avg_cpu_option(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { | fn get_avg_cpu_option(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { | ||||||
| 	if matches.is_present("AVG_CPU") { |     if matches.is_present("AVG_CPU") { | ||||||
| 		return true; |         return true; | ||||||
| 	} else if let Some(flags) = &config.flags { |     } else if let Some(flags) = &config.flags { | ||||||
| 		if let Some(avg_cpu) = flags.avg_cpu { |         if let Some(avg_cpu) = flags.avg_cpu { | ||||||
| 			return avg_cpu; |             return avg_cpu; | ||||||
| 		} |         } | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	false |     false | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn get_use_dot_option(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { | fn get_use_dot_option(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { | ||||||
| 	if matches.is_present("DOT_MARKER") { |     if matches.is_present("DOT_MARKER") { | ||||||
| 		return true; |         return true; | ||||||
| 	} else if let Some(flags) = &config.flags { |     } else if let Some(flags) = &config.flags { | ||||||
| 		if let Some(dot_marker) = flags.dot_marker { |         if let Some(dot_marker) = flags.dot_marker { | ||||||
| 			return dot_marker; |             return dot_marker; | ||||||
| 		} |         } | ||||||
| 	} |     } | ||||||
| 	false |     false | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn get_use_left_legend_option(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { | fn get_use_left_legend_option(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { | ||||||
| 	if matches.is_present("LEFT_LEGEND") { |     if matches.is_present("LEFT_LEGEND") { | ||||||
| 		return true; |         return true; | ||||||
| 	} else if let Some(flags) = &config.flags { |     } else if let Some(flags) = &config.flags { | ||||||
| 		if let Some(left_legend) = flags.left_legend { |         if let Some(left_legend) = flags.left_legend { | ||||||
| 			return left_legend; |             return left_legend; | ||||||
| 		} |         } | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	false |     false | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn get_use_current_cpu_total_option(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { | fn get_use_current_cpu_total_option(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { | ||||||
| 	if matches.is_present("USE_CURR_USAGE") { |     if matches.is_present("USE_CURR_USAGE") { | ||||||
| 		return true; |         return true; | ||||||
| 	} else if let Some(flags) = &config.flags { |     } else if let Some(flags) = &config.flags { | ||||||
| 		if let Some(current_usage) = flags.current_usage { |         if let Some(current_usage) = flags.current_usage { | ||||||
| 			return current_usage; |             return current_usage; | ||||||
| 		} |         } | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	false |     false | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn get_show_disabled_data_option(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { | fn get_show_disabled_data_option(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { | ||||||
| 	if matches.is_present("SHOW_DISABLED_DATA") { |     if matches.is_present("SHOW_DISABLED_DATA") { | ||||||
| 		return true; |         return true; | ||||||
| 	} else if let Some(flags) = &config.flags { |     } else if let Some(flags) = &config.flags { | ||||||
| 		if let Some(show_disabled_data) = flags.show_disabled_data { |         if let Some(show_disabled_data) = flags.show_disabled_data { | ||||||
| 			return show_disabled_data; |             return show_disabled_data; | ||||||
| 		} |         } | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	false |     false | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn enable_app_grouping(matches: &clap::ArgMatches<'static>, config: &Config, app: &mut App) { | fn enable_app_grouping(matches: &clap::ArgMatches<'static>, config: &Config, app: &mut App) { | ||||||
| 	if matches.is_present("GROUP_PROCESSES") { |     if matches.is_present("GROUP_PROCESSES") { | ||||||
| 		app.toggle_grouping(); |         app.toggle_grouping(); | ||||||
| 	} else if let Some(flags) = &config.flags { |     } else if let Some(flags) = &config.flags { | ||||||
| 		if let Some(grouping) = flags.group_processes { |         if let Some(grouping) = flags.group_processes { | ||||||
| 			if grouping { |             if grouping { | ||||||
| 				app.toggle_grouping(); |                 app.toggle_grouping(); | ||||||
| 			} |             } | ||||||
| 		} |         } | ||||||
| 	} |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn enable_app_case_sensitive(matches: &clap::ArgMatches<'static>, config: &Config, app: &mut App) { | fn enable_app_case_sensitive(matches: &clap::ArgMatches<'static>, config: &Config, app: &mut App) { | ||||||
| 	if matches.is_present("CASE_SENSITIVE") { |     if matches.is_present("CASE_SENSITIVE") { | ||||||
| 		app.process_search_state.search_toggle_ignore_case(); |         app.process_search_state.search_toggle_ignore_case(); | ||||||
| 	} else if let Some(flags) = &config.flags { |     } else if let Some(flags) = &config.flags { | ||||||
| 		if let Some(case_sensitive) = flags.case_sensitive { |         if let Some(case_sensitive) = flags.case_sensitive { | ||||||
| 			if case_sensitive { |             if case_sensitive { | ||||||
| 				app.process_search_state.search_toggle_ignore_case(); |                 app.process_search_state.search_toggle_ignore_case(); | ||||||
| 			} |             } | ||||||
| 		} |         } | ||||||
| 	} |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn enable_app_match_whole_word( | fn enable_app_match_whole_word( | ||||||
| 	matches: &clap::ArgMatches<'static>, config: &Config, app: &mut App, |     matches: &clap::ArgMatches<'static>, config: &Config, app: &mut App, | ||||||
| ) { | ) { | ||||||
| 	if matches.is_present("WHOLE_WORD") { |     if matches.is_present("WHOLE_WORD") { | ||||||
| 		app.process_search_state.search_toggle_whole_word(); |         app.process_search_state.search_toggle_whole_word(); | ||||||
| 	} else if let Some(flags) = &config.flags { |     } else if let Some(flags) = &config.flags { | ||||||
| 		if let Some(whole_word) = flags.whole_word { |         if let Some(whole_word) = flags.whole_word { | ||||||
| 			if whole_word { |             if whole_word { | ||||||
| 				app.process_search_state.search_toggle_whole_word(); |                 app.process_search_state.search_toggle_whole_word(); | ||||||
| 			} |             } | ||||||
| 		} |         } | ||||||
| 	} |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn enable_app_use_regex(matches: &clap::ArgMatches<'static>, config: &Config, app: &mut App) { | fn enable_app_use_regex(matches: &clap::ArgMatches<'static>, config: &Config, app: &mut App) { | ||||||
| 	if matches.is_present("REGEX_DEFAULT") { |     if matches.is_present("REGEX_DEFAULT") { | ||||||
| 		app.process_search_state.search_toggle_regex(); |         app.process_search_state.search_toggle_regex(); | ||||||
| 	} else if let Some(flags) = &config.flags { |     } else if let Some(flags) = &config.flags { | ||||||
| 		if let Some(regex) = flags.regex { |         if let Some(regex) = flags.regex { | ||||||
| 			if regex { |             if regex { | ||||||
| 				app.process_search_state.search_toggle_regex(); |                 app.process_search_state.search_toggle_regex(); | ||||||
| 			} |             } | ||||||
| 		} |         } | ||||||
| 	} |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn get_default_widget(matches: &clap::ArgMatches<'static>, config: &Config) -> app::WidgetPosition { | fn get_default_widget(matches: &clap::ArgMatches<'static>, config: &Config) -> app::WidgetPosition { | ||||||
| 	if matches.is_present("CPU_WIDGET") { |     if matches.is_present("CPU_WIDGET") { | ||||||
| 		return app::WidgetPosition::Cpu; |         return app::WidgetPosition::Cpu; | ||||||
| 	} else if matches.is_present("MEM_WIDGET") { |     } else if matches.is_present("MEM_WIDGET") { | ||||||
| 		return app::WidgetPosition::Mem; |         return app::WidgetPosition::Mem; | ||||||
| 	} else if matches.is_present("DISK_WIDGET") { |     } else if matches.is_present("DISK_WIDGET") { | ||||||
| 		return app::WidgetPosition::Disk; |         return app::WidgetPosition::Disk; | ||||||
| 	} else if matches.is_present("TEMP_WIDGET") { |     } else if matches.is_present("TEMP_WIDGET") { | ||||||
| 		return app::WidgetPosition::Temp; |         return app::WidgetPosition::Temp; | ||||||
| 	} else if matches.is_present("NET_WIDGET") { |     } else if matches.is_present("NET_WIDGET") { | ||||||
| 		return app::WidgetPosition::Network; |         return app::WidgetPosition::Network; | ||||||
| 	} else if matches.is_present("PROC_WIDGET") { |     } else if matches.is_present("PROC_WIDGET") { | ||||||
| 		return app::WidgetPosition::Process; |         return app::WidgetPosition::Process; | ||||||
| 	} else if let Some(flags) = &config.flags { |     } else if let Some(flags) = &config.flags { | ||||||
| 		if let Some(default_widget) = &flags.default_widget { |         if let Some(default_widget) = &flags.default_widget { | ||||||
| 			match default_widget.as_str() { |             match default_widget.as_str() { | ||||||
| 				"cpu_default" => { |                 "cpu_default" => { | ||||||
| 					return app::WidgetPosition::Cpu; |                     return app::WidgetPosition::Cpu; | ||||||
| 				} |                 } | ||||||
| 				"memory_default" => { |                 "memory_default" => { | ||||||
| 					return app::WidgetPosition::Mem; |                     return app::WidgetPosition::Mem; | ||||||
| 				} |                 } | ||||||
| 				"processes_default" => { |                 "processes_default" => { | ||||||
| 					return app::WidgetPosition::Process; |                     return app::WidgetPosition::Process; | ||||||
| 				} |                 } | ||||||
| 				"network_default" => { |                 "network_default" => { | ||||||
| 					return app::WidgetPosition::Network; |                     return app::WidgetPosition::Network; | ||||||
| 				} |                 } | ||||||
| 				"temperature_default" => { |                 "temperature_default" => { | ||||||
| 					return app::WidgetPosition::Temp; |                     return app::WidgetPosition::Temp; | ||||||
| 				} |                 } | ||||||
| 				"disk_default" => { |                 "disk_default" => { | ||||||
| 					return app::WidgetPosition::Disk; |                     return app::WidgetPosition::Disk; | ||||||
| 				} |                 } | ||||||
| 				_ => {} |                 _ => {} | ||||||
| 			} |             } | ||||||
| 		} |         } | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	app::WidgetPosition::Process |     app::WidgetPosition::Process | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn try_drawing( | fn try_drawing( | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user