Skip to content

Commit

Permalink
fix: extra whitespace in battery bar
Browse files Browse the repository at this point in the history
  • Loading branch information
grtcdr committed Feb 17, 2021
1 parent ceb748a commit 6246d63
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -16,7 +16,7 @@ opt-level = 3
debug = false

[dependencies]
colored = "2"
colored = "2.0.0"
num_cpus = "1.13.0"
nix = "0.19.1"
bytesize = "1.0.1"
Expand Down
18 changes: 7 additions & 11 deletions src/display.rs
@@ -1,6 +1,5 @@
extern crate num_cpus;
use crate::{
bars, format, machine, memory, read, DEFAULT_COLOR, DEFAULT_PADDING, DEFAULT_SEPARATOR_COLOR,
bars, format, memory, product, read, DEFAULT_COLOR, DEFAULT_PADDING, DEFAULT_SEPARATOR_COLOR,
};
use colored::{Color, ColoredString, Colorize};
use rand::Rng;
Expand Down Expand Up @@ -83,20 +82,17 @@ impl Elements {
Elements {
hostname: Pair::new(String::from("Host"), read::hostname()),
os: Pair::new(String::from("Os"), read::operating_system()),
desktop_env: Pair::new(
String::from("Desk"),
format::desktop_session(read::desktop_session()),
),
desktop_env: Pair::new(String::from("Desk"), read::desktop_session()),
kernel: Pair::new(String::from("Kern"), read::kernel_version()),
packages: Pair::new(String::from("Pkgs"), read::package_count()),
shell: Pair::new(String::from("Sh"), String::new()),
machine: Pair::new(
String::from("Mach"),
format::machine(
machine::product_version(),
machine::sys_vendor(),
machine::product_family(),
machine::product_name(),
product::product_version(),
product::sys_vendor(),
product::product_family(),
product::product_name(),
),
),
terminal: Pair::new(String::from("Term"), read::terminal()),
Expand Down Expand Up @@ -424,7 +420,7 @@ pub fn hide(mut elems: Elements, options: Options, hide_parameters: Vec<&str>) {
if hide_parameters.contains(&"bat") {
elems.battery.hidden = true;
}

print_info(elems, options);
}

Expand Down
9 changes: 5 additions & 4 deletions src/extra.rs
@@ -1,8 +1,9 @@
use std::fs::File;
use std::io::{BufRead, BufReader, Error};
use std::path::Path;

use crate::memory;
use std::{
fs::File,
io::{BufRead, BufReader, Error},
path::Path,
};

/// Pop '__\n__' from the end of a string if it is found
pub fn pop_newline(mut string: String) -> String {
Expand Down
13 changes: 4 additions & 9 deletions src/format.rs
@@ -1,4 +1,3 @@
extern crate bytesize;
use bytesize::ByteSize;

/// Construct a new _String_ from the value
Expand Down Expand Up @@ -52,7 +51,6 @@ pub fn battery(percentage: String, status: String) -> String {
pub fn memory(used: u64, total: u64) -> String {
let total = ByteSize::kb(total);
let used = ByteSize::kb(used);

String::from(used.to_string() + "/" + &total.to_string())
}

Expand All @@ -70,7 +68,7 @@ pub fn machine(
product_family: String,
product_name: String,
) -> String {
if product_version.is_empty() || product_version.len() <= 10 {
if product_version.is_empty() || product_version.len() <= 15 {
return String::from(sys_vendor + " " + &product_family + " " + &product_name);
}
product_version
Expand All @@ -80,7 +78,6 @@ pub fn desktop_session(mut session_name: String) -> String {
if !session_name.is_empty() {
let last_occurence_index = session_name.rfind("/").unwrap() + 1;
session_name.replace_range(0..last_occurence_index, "");

// Uppercase first letter
let first_letter = session_name
.chars()
Expand All @@ -90,11 +87,9 @@ pub fn desktop_session(mut session_name: String) -> String {
.to_string();
// Remove first letter from original string
session_name.remove(0);
// Append to new string the uppercase
// letter and rest of original string
let new_string = first_letter + &session_name;

return new_string;
// Concatenate the first letter and
// the remainder of the original String
return first_letter + &session_name;
}
String::from("Unknown")
}
6 changes: 2 additions & 4 deletions src/main.rs
@@ -1,15 +1,13 @@
extern crate clap;
mod bars;
mod display;
mod extra;
mod format;
mod machine;
mod memory;
mod product;
mod read;
use clap::{crate_authors, crate_version, App, Arg};
use colored::Color;
use display::Options;
use display::{choose_color, Elements};
use display::{choose_color, Elements, Options};

/// Macchina's version
pub const VERSION: &str = crate_version!();
Expand Down
File renamed without changes.
15 changes: 10 additions & 5 deletions src/read.rs
@@ -1,12 +1,17 @@
extern crate nix;
use crate::{extra, format, PATH_TO_BATTERY_PERCENTAGE, PATH_TO_BATTERY_STATUS};
use nix::unistd;
use std::env;
use std::fs;
use std::process::{Command, Stdio};
use std::{
env, fs,
process::{Command, Stdio},
};

/// Read desktop environment name from $DESKTOP_SESSION environment variable
pub fn desktop_session() -> String {
return String::from(env!("DESKTOP_SESSION"));
let de = String::from(env!("DESKTOP_SESSION"));
if !de.contains("/") {
return de;
}
format::desktop_session(de)
}

/// Read battery percentage from `/sys/class/power_supply/BAT0/capacity`
Expand Down

0 comments on commit 6246d63

Please sign in to comment.