improv(about): use byte-unit for display of memory and disk capacity
This commit is contained in:
parent
54c860f43d
commit
efdd934e62
4 changed files with 41 additions and 2 deletions
16
Cargo.lock
generated
16
Cargo.lock
generated
|
|
@ -214,6 +214,15 @@ version = "3.12.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535"
|
checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byte-unit"
|
||||||
|
version = "4.0.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3348673602e04848647fffaa8e9a861e7b5d5cae6570727b41bde0f722514484"
|
||||||
|
dependencies = [
|
||||||
|
"utf8-width",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytecheck"
|
name = "bytecheck"
|
||||||
version = "0.6.9"
|
version = "0.6.9"
|
||||||
|
|
@ -538,6 +547,7 @@ name = "cosmic-settings-system"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
|
"byte-unit",
|
||||||
"concat-in-place",
|
"concat-in-place",
|
||||||
"const_format",
|
"const_format",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
|
@ -3826,6 +3836,12 @@ dependencies = [
|
||||||
"xmlwriter",
|
"xmlwriter",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf8-width"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "valuable"
|
name = "valuable"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
|
||||||
16
pages/system/Cargo.lock
generated
16
pages/system/Cargo.lock
generated
|
|
@ -14,6 +14,15 @@ version = "3.12.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535"
|
checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byte-unit"
|
||||||
|
version = "4.0.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3348673602e04848647fffaa8e9a861e7b5d5cae6570727b41bde0f722514484"
|
||||||
|
dependencies = [
|
||||||
|
"utf8-width",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
|
|
@ -57,6 +66,7 @@ name = "cosmic-settings-system"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
|
"byte-unit",
|
||||||
"concat-in-place",
|
"concat-in-place",
|
||||||
"const_format",
|
"const_format",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
|
@ -240,6 +250,12 @@ version = "0.2.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf8-width"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ license = "MPL-2.0"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
byte-unit = { version = "4.0.18", default-features = false }
|
||||||
const_format = "0.2.30"
|
const_format = "0.2.30"
|
||||||
concat-in-place = "1.1.0"
|
concat-in-place = "1.1.0"
|
||||||
sysinfo = "0.27.7"
|
sysinfo = "0.27.7"
|
||||||
|
|
|
||||||
|
|
@ -55,13 +55,13 @@ impl Info {
|
||||||
total_capacity += disk.total_space();
|
total_capacity += disk.total_space();
|
||||||
}
|
}
|
||||||
|
|
||||||
info.disk_capacity = format!("{} GB", (total_capacity / 1_000_000_000));
|
info.disk_capacity = format_size(total_capacity);
|
||||||
|
|
||||||
if let Some(name) = sys.host_name() {
|
if let Some(name) = sys.host_name() {
|
||||||
info.device_name = name;
|
info.device_name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
info.memory = format!("{} GB", (sys.total_memory() / 1_000_000_000 + 1));
|
info.memory = format_size(sys.total_memory());
|
||||||
|
|
||||||
if let Ok(mut session) = std::env::var("XDG_SESSION_TYPE") {
|
if let Ok(mut session) = std::env::var("XDG_SESSION_TYPE") {
|
||||||
if let Some(first) = session.get_mut(0..1) {
|
if let Some(first) = session.get_mut(0..1) {
|
||||||
|
|
@ -200,3 +200,9 @@ pub fn read_to_string<'a, P: AsRef<OsStr>>(
|
||||||
|
|
||||||
std::str::from_utf8(buffer.as_slice()).ok()
|
std::str::from_utf8(buffer.as_slice()).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn format_size(size: u64) -> String {
|
||||||
|
byte_unit::Byte::from_bytes(size)
|
||||||
|
.get_appropriate_unit(true)
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue