Skip to content

Commit 317e02a

Browse files
committed
add support for more types of configurations (#450)
1 parent 92e082a commit 317e02a

File tree

1 file changed

+62
-19
lines changed

1 file changed

+62
-19
lines changed

Diff for: src/plumbing/progress.rs

+62-19
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,87 @@
11
use crosstermion::crossterm::style::Stylize;
2+
use owo_colors::OwoColorize;
23
use std::fmt::{Display, Formatter};
34

5+
#[derive(Clone)]
46
enum Usage {
5-
InModule(&'static str),
7+
NotApplicable,
8+
Planned {
9+
note: Option<&'static str>,
10+
},
11+
InModule {
12+
name: &'static str,
13+
deviation: Option<&'static str>,
14+
},
615
}
716
use Usage::*;
817

918
impl Display for Usage {
1019
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1120
match self {
12-
InModule(m) => write!(f, "mod {m}"),
21+
NotApplicable => f.write_str("not applicable")?,
22+
Planned { note } => {
23+
write!(f, "{}", "planned".blink())?;
24+
if let Some(note) = note {
25+
write!(f, " ℹ {} ℹ", note.bright_white())?;
26+
}
27+
}
28+
InModule { name, deviation } => {
29+
write!(f, "mod {name}")?;
30+
if let Some(deviation) = deviation {
31+
write!(f, "{}", format!(" ❗️{deviation}❗️").bright_white())?
32+
}
33+
}
1334
}
35+
Ok(())
1436
}
1537
}
1638

39+
impl Usage {
40+
pub fn icon(&self) -> &'static str {
41+
match self {
42+
NotApplicable => "❌",
43+
Planned { .. } => "🕒",
44+
InModule { deviation, .. } => deviation.is_some().then(|| "👌️").unwrap_or("✅"),
45+
}
46+
}
47+
}
48+
49+
#[derive(Clone)]
1750
struct Record {
1851
config: &'static str,
1952
usage: Usage,
20-
deviation: Option<&'static str>,
2153
}
2254

23-
static GIT_CONFIG: &[Record] = &[Record {
24-
config: "pack.threads",
25-
usage: InModule("remote::connection::fetch"),
26-
deviation: Some("if unset, it uses all threads as opposed to just 1"),
27-
}];
55+
static GIT_CONFIG: &[Record] = &[
56+
Record {
57+
config: "fetch.output",
58+
usage: NotApplicable,
59+
},
60+
Record {
61+
config: "fetch.negotiationAlgorithm",
62+
usage: Planned {
63+
note: Some("Implements our own 'naive' algorithm, only"),
64+
},
65+
},
66+
Record {
67+
config: "pack.threads",
68+
usage: InModule {
69+
name: "remote::connection::fetch",
70+
deviation: Some("if unset, it uses all threads as opposed to just 1"),
71+
},
72+
},
73+
];
2874

2975
/// A programmatic way to record and display progress.
3076
pub fn show_progress() -> anyhow::Result<()> {
31-
for Record {
32-
config,
33-
usage,
34-
deviation,
35-
} in GIT_CONFIG
36-
{
37-
println!(
38-
"{}: {usage}{}",
39-
config.bold(),
40-
deviation.map(|d| format!(" ({d})")).unwrap_or_default().dark_grey()
41-
);
77+
let sorted = {
78+
let mut v: Vec<_> = GIT_CONFIG.into();
79+
v.sort_by_key(|r| r.config);
80+
v
81+
};
82+
83+
for Record { config, usage } in sorted {
84+
println!("{} {}: {usage}", usage.icon(), config.bold(),);
4285
}
4386
Ok(())
4487
}

0 commit comments

Comments
 (0)