Style for storage list

This commit is contained in:
qwjyh 2024-06-27 17:55:11 +09:00
parent 592226f1b6
commit eb08634d9d
2 changed files with 21 additions and 11 deletions

View file

@ -7,7 +7,7 @@ use std::{
use anyhow::{anyhow, Context, Result};
use byte_unit::{Byte, UnitType};
use console::Style;
use console::style;
use dunce::canonicalize;
use git2::Repository;
use inquire::{Confirm, CustomType, Text};
@ -212,7 +212,7 @@ fn write_storages_list(
"-"
}
} else {
" "
""
};
let path = storage.mount_path(device).map_or_else(
|e| {
@ -228,23 +228,24 @@ fn write_storages_list(
} else {
""
};
let typestyle = storage.typestyle();
writeln!(
writer,
"{stype}{isremovable}: {name:<name_width$} {size:>10} {parent:<name_width$} {path}",
stype = storage.shorttypename(),
"{stype}{isremovable:<1}: {name:<name_width$} {size:>10} {parent:<name_width$} {path}",
stype = typestyle.apply_to(storage.shorttypename()),
isremovable = isremovable,
name = storage.name(),
name = typestyle.apply_to(storage.name()),
size = size_str,
parent = parent_name,
parent = console::style(parent_name).bright().black(),
path = path,
)?;
if long_display {
let note = match storage {
Storage::Physical(s) => s.kind(),
Storage::SubDirectory(s) => &s.notes,
Storage::Online(s) => &s.provider,
Storage::Physical(s) => format!("kind: {}", s.kind()),
Storage::SubDirectory(s) => s.notes.clone(),
Storage::Online(s) => s.provider.clone(),
};
writeln!(writer, " {}", note)?;
writeln!(writer, " {}", style(note).italic())?;
}
}
Ok(())

View file

@ -1,5 +1,6 @@
//! Manipulates storages.
use console::{style, Style, StyledObject};
use crate::devices;
use crate::storages::{
directory::Directory, online_storage::OnlineStorage,
@ -9,7 +10,7 @@ use anyhow::{anyhow, Context, Result};
use clap::ValueEnum;
use core::panic;
use serde::{Deserialize, Serialize};
use std::{collections::BTreeMap, fmt, fs, io, path, u64};
use std::{collections::BTreeMap, fmt, fs, io, path};
/// YAML file to store known storages..
pub const STORAGESFILE: &str = "storages.yml";
@ -50,6 +51,14 @@ impl Storage {
Self::Online(_) => "O",
}
}
pub fn typestyle(&self) -> Style {
match self {
Storage::Physical(_) => Style::new().cyan(),
Storage::SubDirectory(_) => Style::new().yellow(),
Storage::Online(_) => Style::new().green(),
}
}
}
impl StorageExt for Storage {