mirror of
https://github.com/qwjyh/xdbm
synced 2025-04-20 03:35:55 +09:00
Style for storage list
This commit is contained in:
parent
592226f1b6
commit
eb08634d9d
2 changed files with 21 additions and 11 deletions
|
@ -7,7 +7,7 @@ use std::{
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use byte_unit::{Byte, UnitType};
|
use byte_unit::{Byte, UnitType};
|
||||||
use console::Style;
|
use console::style;
|
||||||
use dunce::canonicalize;
|
use dunce::canonicalize;
|
||||||
use git2::Repository;
|
use git2::Repository;
|
||||||
use inquire::{Confirm, CustomType, Text};
|
use inquire::{Confirm, CustomType, Text};
|
||||||
|
@ -212,7 +212,7 @@ fn write_storages_list(
|
||||||
"-"
|
"-"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
" "
|
""
|
||||||
};
|
};
|
||||||
let path = storage.mount_path(device).map_or_else(
|
let path = storage.mount_path(device).map_or_else(
|
||||||
|e| {
|
|e| {
|
||||||
|
@ -228,23 +228,24 @@ fn write_storages_list(
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
|
let typestyle = storage.typestyle();
|
||||||
writeln!(
|
writeln!(
|
||||||
writer,
|
writer,
|
||||||
"{stype}{isremovable}: {name:<name_width$} {size:>10} {parent:<name_width$} {path}",
|
"{stype}{isremovable:<1}: {name:<name_width$} {size:>10} {parent:<name_width$} {path}",
|
||||||
stype = storage.shorttypename(),
|
stype = typestyle.apply_to(storage.shorttypename()),
|
||||||
isremovable = isremovable,
|
isremovable = isremovable,
|
||||||
name = storage.name(),
|
name = typestyle.apply_to(storage.name()),
|
||||||
size = size_str,
|
size = size_str,
|
||||||
parent = parent_name,
|
parent = console::style(parent_name).bright().black(),
|
||||||
path = path,
|
path = path,
|
||||||
)?;
|
)?;
|
||||||
if long_display {
|
if long_display {
|
||||||
let note = match storage {
|
let note = match storage {
|
||||||
Storage::Physical(s) => s.kind(),
|
Storage::Physical(s) => format!("kind: {}", s.kind()),
|
||||||
Storage::SubDirectory(s) => &s.notes,
|
Storage::SubDirectory(s) => s.notes.clone(),
|
||||||
Storage::Online(s) => &s.provider,
|
Storage::Online(s) => s.provider.clone(),
|
||||||
};
|
};
|
||||||
writeln!(writer, " {}", note)?;
|
writeln!(writer, " {}", style(note).italic())?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
//! Manipulates storages.
|
//! Manipulates storages.
|
||||||
|
|
||||||
|
use console::{style, Style, StyledObject};
|
||||||
use crate::devices;
|
use crate::devices;
|
||||||
use crate::storages::{
|
use crate::storages::{
|
||||||
directory::Directory, online_storage::OnlineStorage,
|
directory::Directory, online_storage::OnlineStorage,
|
||||||
|
@ -9,7 +10,7 @@ use anyhow::{anyhow, Context, Result};
|
||||||
use clap::ValueEnum;
|
use clap::ValueEnum;
|
||||||
use core::panic;
|
use core::panic;
|
||||||
use serde::{Deserialize, Serialize};
|
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..
|
/// YAML file to store known storages..
|
||||||
pub const STORAGESFILE: &str = "storages.yml";
|
pub const STORAGESFILE: &str = "storages.yml";
|
||||||
|
@ -50,6 +51,14 @@ impl Storage {
|
||||||
Self::Online(_) => "O",
|
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 {
|
impl StorageExt for Storage {
|
||||||
|
|
Loading…
Add table
Reference in a new issue