|
1 | 1 | use crosstermion::crossterm::style::Stylize;
|
| 2 | +use owo_colors::OwoColorize; |
2 | 3 | use std::fmt::{Display, Formatter};
|
3 | 4 |
|
| 5 | +#[derive(Clone)] |
4 | 6 | 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 | + }, |
6 | 15 | }
|
7 | 16 | use Usage::*;
|
8 | 17 |
|
9 | 18 | impl Display for Usage {
|
10 | 19 | fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
11 | 20 | 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 | + } |
13 | 34 | }
|
| 35 | + Ok(()) |
14 | 36 | }
|
15 | 37 | }
|
16 | 38 |
|
| 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)] |
17 | 50 | struct Record {
|
18 | 51 | config: &'static str,
|
19 | 52 | usage: Usage,
|
20 |
| - deviation: Option<&'static str>, |
21 | 53 | }
|
22 | 54 |
|
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 | +]; |
28 | 74 |
|
29 | 75 | /// A programmatic way to record and display progress.
|
30 | 76 | 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(),); |
42 | 85 | }
|
43 | 86 | Ok(())
|
44 | 87 | }
|
0 commit comments