|
|
|
@ -5,6 +5,7 @@ use std::{
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use crossterm::style::Stylize;
|
|
|
|
|
use enumset::{EnumSet, EnumSetType};
|
|
|
|
|
use semver::Version;
|
|
|
|
|
use termtree::Tree;
|
|
|
|
|
|
|
|
|
@ -20,6 +21,19 @@ pub struct Project {
|
|
|
|
|
profile_map: HashMap<String, String>, // vcs profile name to branch names
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(EnumSetType, Debug)]
|
|
|
|
|
pub enum ProjectDisplayOptions {
|
|
|
|
|
Profiles,
|
|
|
|
|
Msrv,
|
|
|
|
|
Changes,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ProjectDisplayOptions {
|
|
|
|
|
pub fn all() -> EnumSet<Self> {
|
|
|
|
|
Self::Profiles | Self::Msrv | Self::Changes
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub type Projects<'origin> = std::slice::Iter<'origin, Project>;
|
|
|
|
|
|
|
|
|
|
impl Project {
|
|
|
|
@ -109,7 +123,7 @@ impl Project {
|
|
|
|
|
Ok(None)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn display(&self, profiles: bool, changes: bool) -> Result<Tree<String>, Error> {
|
|
|
|
|
pub fn display(&self, options: EnumSet<ProjectDisplayOptions>) -> Result<Tree<String>, Error> {
|
|
|
|
|
let title = format!(
|
|
|
|
|
"{}: {} [{}]",
|
|
|
|
|
self.name().bold().with(PROJECT_COLOR),
|
|
|
|
@ -118,8 +132,9 @@ impl Project {
|
|
|
|
|
);
|
|
|
|
|
let mut root = Tree::new(title);
|
|
|
|
|
|
|
|
|
|
if profiles {
|
|
|
|
|
if options & ProjectDisplayOptions::Profiles == ProjectDisplayOptions::Profiles {
|
|
|
|
|
let mut profiles_tree = Tree::new("[PROFILES]".with(PROFILE_COLOR).to_string());
|
|
|
|
|
let mut count = 0;
|
|
|
|
|
for (profile_name, branch_name) in &self.profile_map {
|
|
|
|
|
let leaf = Tree::new(format!(
|
|
|
|
|
"{} -> {}",
|
|
|
|
@ -127,20 +142,25 @@ impl Project {
|
|
|
|
|
branch_name.as_str().with(REFS_COLOR)
|
|
|
|
|
));
|
|
|
|
|
profiles_tree.push(leaf);
|
|
|
|
|
count += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
root.push(profiles_tree);
|
|
|
|
|
if count > 0 {
|
|
|
|
|
root.push(profiles_tree);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Some(msrv) = &self.msrv {
|
|
|
|
|
let leaf = Tree::new(msrv.to_string().with(MSRV_COLOR).to_string());
|
|
|
|
|
let mut msrv_tree = Tree::new("[MSRV]".with(MSRV_COLOR).to_string());
|
|
|
|
|
msrv_tree.push(leaf);
|
|
|
|
|
if options & ProjectDisplayOptions::Msrv == ProjectDisplayOptions::Msrv {
|
|
|
|
|
if let Some(msrv) = &self.msrv {
|
|
|
|
|
let leaf = Tree::new(msrv.to_string().with(MSRV_COLOR).to_string());
|
|
|
|
|
let mut msrv_tree = Tree::new("[MSRV]".with(MSRV_COLOR).to_string());
|
|
|
|
|
msrv_tree.push(leaf);
|
|
|
|
|
|
|
|
|
|
root.push(msrv_tree);
|
|
|
|
|
root.push(msrv_tree);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if changes {
|
|
|
|
|
if options & ProjectDisplayOptions::Changes == ProjectDisplayOptions::Changes {
|
|
|
|
|
let statuses = self.repo.uncommitted_changes()?;
|
|
|
|
|
let uncommitted = statuses
|
|
|
|
|
.iter()
|
|
|
|
@ -166,7 +186,8 @@ impl Display for Project {
|
|
|
|
|
write!(
|
|
|
|
|
f,
|
|
|
|
|
"{}",
|
|
|
|
|
self.display(true, true).map_err(|_| std::fmt::Error)?
|
|
|
|
|
self.display(ProjectDisplayOptions::all())
|
|
|
|
|
.map_err(|_| std::fmt::Error)?
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|