mirror of
https://github.com/qwjyh/xdbm
synced 2025-06-26 17:59:20 +09:00
update dependencies (especially byte_unit)
- update formatting byte units
This commit is contained in:
parent
a389935819
commit
44674262a6
5 changed files with 435 additions and 73 deletions
|
@ -6,7 +6,7 @@ use std::{
|
|||
};
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use byte_unit::Byte;
|
||||
use byte_unit::{Byte, UnitType};
|
||||
use dunce::canonicalize;
|
||||
use git2::Repository;
|
||||
use inquire::{Confirm, CustomType, Text};
|
||||
|
@ -197,10 +197,11 @@ fn write_storages_list(
|
|||
trace!("name widths: {}", name_width);
|
||||
for storage in storages.list.values() {
|
||||
let size_str = match storage.capacity() {
|
||||
Some(b) => Byte::from_bytes(b.into())
|
||||
.get_appropriate_unit(true)
|
||||
.format(0)
|
||||
.to_string(),
|
||||
Some(b) => {
|
||||
let size = Byte::from_u64(b).get_appropriate_unit(UnitType::Binary);
|
||||
// TODO: split case for 500GB and 1.5TB?
|
||||
format!("{:>+5.1}", size)
|
||||
}
|
||||
None => "".to_string(),
|
||||
};
|
||||
let isremovable = if let Storage::Physical(s) = storage {
|
||||
|
@ -228,7 +229,7 @@ fn write_storages_list(
|
|||
};
|
||||
writeln!(
|
||||
writer,
|
||||
"{stype}{isremovable}: {name:<name_width$} {size:>8} {parent:<name_width$} {path}",
|
||||
"{stype}{isremovable}: {name:<name_width$} {size:>10} {parent:<name_width$} {path}",
|
||||
stype = storage.shorttypename(),
|
||||
isremovable = isremovable,
|
||||
name = storage.name(),
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use anyhow::{Context, Result};
|
||||
use byte_unit::Byte;
|
||||
use byte_unit::UnitType;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt;
|
||||
|
@ -60,10 +61,7 @@ impl StorageExt for OnlineStorage {
|
|||
self.local_infos.get(&device.name())
|
||||
}
|
||||
|
||||
fn mount_path(
|
||||
&self,
|
||||
device: &devices::Device,
|
||||
) -> Result<std::path::PathBuf> {
|
||||
fn mount_path(&self, device: &devices::Device) -> Result<std::path::PathBuf> {
|
||||
Ok(self
|
||||
.local_infos
|
||||
.get(&device.name())
|
||||
|
@ -98,7 +96,7 @@ impl fmt::Display for OnlineStorage {
|
|||
f,
|
||||
"O {name:<10} {size:<10} {provider:<10}",
|
||||
name = self.name(),
|
||||
size = Byte::from_bytes(self.capacity.into()).get_appropriate_unit(true),
|
||||
size = Byte::from_u64(self.capacity).get_appropriate_unit(UnitType::Binary),
|
||||
provider = self.provider,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::devices;
|
|||
use crate::devices::Device;
|
||||
use crate::storages::{Storage, StorageExt, Storages};
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use byte_unit::Byte;
|
||||
use byte_unit::{Byte, UnitType};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::{self, Path};
|
||||
use std::{collections::BTreeMap, fmt};
|
||||
|
@ -148,7 +148,7 @@ impl fmt::Display for PhysicalDrivePartition {
|
|||
f,
|
||||
"P {name:<10} {size:<10} {removable:<1} {kind:<6} {fs:<5}",
|
||||
name = self.name(),
|
||||
size = Byte::from_bytes(self.capacity.into()).get_appropriate_unit(true),
|
||||
size = Byte::from_u64(self.capacity).get_appropriate_unit(UnitType::Binary),
|
||||
removable = removable_indicator,
|
||||
kind = self.kind,
|
||||
fs = self.fs,
|
||||
|
@ -183,8 +183,8 @@ fn select_sysinfo_disk(disks: &sysinfo::Disks) -> Result<&Disk> {
|
|||
let fs: &str = disk.file_system().to_str().unwrap_or("unknown");
|
||||
let kind = format!("{:?}", disk.kind());
|
||||
let mount_path = disk.mount_point();
|
||||
let total_space = byte_unit::Byte::from_bytes(disk.total_space().into())
|
||||
.get_appropriate_unit(true)
|
||||
let total_space = byte_unit::Byte::from_u64(disk.total_space())
|
||||
.get_appropriate_unit(UnitType::Binary)
|
||||
.to_string();
|
||||
format!(
|
||||
"{}: {} {} ({}, {}) {}",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue