-
-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for more types of configurations (#450)
- Loading branch information
Showing
1 changed file
with
62 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,87 @@ | ||
use crosstermion::crossterm::style::Stylize; | ||
use owo_colors::OwoColorize; | ||
use std::fmt::{Display, Formatter}; | ||
|
||
#[derive(Clone)] | ||
enum Usage { | ||
InModule(&'static str), | ||
NotApplicable, | ||
Planned { | ||
note: Option<&'static str>, | ||
}, | ||
InModule { | ||
name: &'static str, | ||
deviation: Option<&'static str>, | ||
}, | ||
} | ||
use Usage::*; | ||
|
||
impl Display for Usage { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
InModule(m) => write!(f, "mod {m}"), | ||
NotApplicable => f.write_str("not applicable")?, | ||
Planned { note } => { | ||
write!(f, "{}", "planned".blink())?; | ||
if let Some(note) = note { | ||
write!(f, " ℹ {} ℹ", note.bright_white())?; | ||
} | ||
} | ||
InModule { name, deviation } => { | ||
write!(f, "mod {name}")?; | ||
if let Some(deviation) = deviation { | ||
write!(f, "{}", format!(" ❗️{deviation}❗️").bright_white())? | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Usage { | ||
pub fn icon(&self) -> &'static str { | ||
match self { | ||
NotApplicable => "❌", | ||
Planned { .. } => "🕒", | ||
InModule { deviation, .. } => deviation.is_some().then(|| "👌️").unwrap_or("✅"), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
struct Record { | ||
config: &'static str, | ||
usage: Usage, | ||
deviation: Option<&'static str>, | ||
} | ||
|
||
static GIT_CONFIG: &[Record] = &[Record { | ||
config: "pack.threads", | ||
usage: InModule("remote::connection::fetch"), | ||
deviation: Some("if unset, it uses all threads as opposed to just 1"), | ||
}]; | ||
static GIT_CONFIG: &[Record] = &[ | ||
Record { | ||
config: "fetch.output", | ||
usage: NotApplicable, | ||
}, | ||
Record { | ||
config: "fetch.negotiationAlgorithm", | ||
usage: Planned { | ||
note: Some("Implements our own 'naive' algorithm, only"), | ||
}, | ||
}, | ||
Record { | ||
config: "pack.threads", | ||
usage: InModule { | ||
name: "remote::connection::fetch", | ||
deviation: Some("if unset, it uses all threads as opposed to just 1"), | ||
}, | ||
}, | ||
]; | ||
|
||
/// A programmatic way to record and display progress. | ||
pub fn show_progress() -> anyhow::Result<()> { | ||
for Record { | ||
config, | ||
usage, | ||
deviation, | ||
} in GIT_CONFIG | ||
{ | ||
println!( | ||
"{}: {usage}{}", | ||
config.bold(), | ||
deviation.map(|d| format!(" ({d})")).unwrap_or_default().dark_grey() | ||
); | ||
let sorted = { | ||
let mut v: Vec<_> = GIT_CONFIG.into(); | ||
v.sort_by_key(|r| r.config); | ||
v | ||
}; | ||
|
||
for Record { config, usage } in sorted { | ||
println!("{} {}: {usage}", usage.icon(), config.bold(),); | ||
} | ||
Ok(()) | ||
} |