summaryrefslogtreecommitdiffstats
path: root/src/options.rs
diff options
context:
space:
mode:
authorRareČ™ Constantin <95525840+RaresCon@users.noreply.github.com>2023-01-15 19:06:42 +0200
committerGitHub <noreply@github.com>2023-01-15 12:06:42 -0500
commitf8db3403af67a48bd41fc18cf89916ac24dfbbe4 (patch)
treed5fb4169799dbdcba728d5bde42ba64e70ff2988 /src/options.rs
parent571ec08291cb1203aee79490c723124770dbdf7b (diff)
other: Dynamic battery widget (#975)
* Added dynamic battery widget For bottom to know that there are no batteries on the system, I added the battery::Manager to the options.rs file because here is the first moment bottom verifies battery configuration by reading the config file, which may or may not contain the battery field, but for a better UX, it doesn't matter what bottom finds in the config file now, if it doesn't retrieve battery data, it just ignores the battery widget all together. If needed, it can be adjusted so that if the config file contains the battery field, it will still show the widget. * CFG guarding for BATTERY module I guarded the options.rs in two places for battery module that can be missing in the feature list. Co-authored-by: RaresCon <RaresCon> Co-authored-by: NitrogenDev <44950964+NitrogenDev@users.noreply.github.com>
Diffstat (limited to 'src/options.rs')
-rw-r--r--src/options.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/options.rs b/src/options.rs
index d659b00a..5c160310 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -10,6 +10,10 @@ use clap::ArgMatches;
use layout_options::*;
use regex::Regex;
use serde::{Deserialize, Serialize};
+
+#[cfg(feature = "battery")]
+use starship_battery::Manager;
+
use typed_builder::*;
use crate::{
@@ -844,6 +848,15 @@ fn get_hide_table_gap(matches: &ArgMatches, config: &Config) -> bool {
}
fn get_use_battery(matches: &ArgMatches, config: &Config) -> bool {
+ #[cfg(feature = "battery")]
+ if let Ok(battery_manager) = Manager::new() {
+ if let Ok(batteries) = battery_manager.batteries() {
+ if batteries.count() == 0 {
+ return false;
+ }
+ }
+ }
+
if cfg!(feature = "battery") {
if matches.is_present("battery") {
return true;