proxmox-backup-client: use HumanByte to render snapshot size

This commit is contained in:
Dietmar Maurer 2020-10-20 11:43:48 +02:00
parent 6f757b8458
commit 23440482d4
2 changed files with 14 additions and 1 deletions

View File

@ -510,7 +510,7 @@ async fn list_snapshots(param: Value) -> Result<Value, Error> {
.sortby("backup-id", false) .sortby("backup-id", false)
.sortby("backup-time", false) .sortby("backup-time", false)
.column(ColumnConfig::new("backup-id").renderer(render_snapshot_path).header("snapshot")) .column(ColumnConfig::new("backup-id").renderer(render_snapshot_path).header("snapshot"))
.column(ColumnConfig::new("size")) .column(ColumnConfig::new("size").renderer(tools::format::render_bytes_human_readable))
.column(ColumnConfig::new("files").renderer(render_files)) .column(ColumnConfig::new("files").renderer(render_files))
; ;

View File

@ -50,6 +50,19 @@ pub fn render_bool_with_default_true(value: &Value, _record: &Value) -> Result<S
Ok((if value { "1" } else { "0" }).to_string()) Ok((if value { "1" } else { "0" }).to_string())
} }
pub fn render_bytes_human_readable(value: &Value, _record: &Value) -> Result<String, Error> {
if value.is_null() { return Ok(String::new()); }
let text = match value.as_u64() {
Some(bytes) => {
HumanByte::from(bytes).to_string()
}
None => {
value.to_string()
}
};
Ok(text)
}
pub struct HumanByte { pub struct HumanByte {
b: usize, b: usize,
} }