Skip to content

Commit 6b54870

Browse files
committed
attempt on title customisation
1 parent 8fc8696 commit 6b54870

File tree

4 files changed

+72
-27
lines changed

4 files changed

+72
-27
lines changed

src/cli.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ pub struct TextFormattingCliOptions {
196196
/// Turns off bold formatting
197197
#[arg(long)]
198198
pub no_bold: bool,
199+
#[arg(long, default_value = ":", value_name = "STRING", value_hint = ValueHint::CommandString)]
200+
pub separator: String,
201+
#[arg(long, default_value = "_", value_name = "STRING", value_hint = ValueHint::CommandString)]
202+
pub underline: String,
199203
}
200204
#[derive(Clone, Debug, Args, PartialEq, Eq, Default)]
201205
#[command(next_help_heading = "VISUALS")]
@@ -278,6 +282,8 @@ impl Default for TextFormattingCliOptions {
278282
iso_time: Default::default(),
279283
number_separator: NumberSeparator::Plain,
280284
no_bold: Default::default(),
285+
separator: "->".to_string(),
286+
underline: "_".to_string(),
281287
}
282288
}
283289
}
@@ -331,7 +337,7 @@ pub fn get_git_version() -> String {
331337
// TODO: make those replaces controllable with config
332338
Ok(v) => String::from_utf8_lossy(&v.stdout)
333339
.replace('\n', "")
334-
.replace("version ","v"),
340+
.replace("version ", "v"),
335341
Err(_) => String::new(),
336342
}
337343
}

src/info/mod.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,17 @@ pub fn build_info(cli_options: &CliOptions) -> Result<Info> {
177177
let number_of_file_churns_to_display = cli_options.info.number_of_file_churns;
178178
let globs_to_exclude = &cli_options.info.exclude;
179179
let show_email = cli_options.info.email;
180+
let separator = &cli_options.text_formatting.separator;
181+
let underline = &cli_options.text_formatting.underline;
180182

181183
Ok(InfoBuilder::new(cli_options)
182-
.title(&repo, no_bold, &text_colors)
184+
.title(
185+
&repo,
186+
no_bold,
187+
separator.to_string(),
188+
underline.to_string(),
189+
&text_colors,
190+
)
183191
.project(&repo, &repo_url, manifest.as_ref(), number_separator)?
184192
.description(manifest.as_ref())
185193
.head(&repo)?
@@ -226,14 +234,24 @@ impl InfoBuilder {
226234
}
227235
}
228236

229-
fn title(mut self, repo: &Repository, no_bold: bool, text_colors: &TextColors) -> Self {
237+
fn title(
238+
mut self,
239+
repo: &Repository,
240+
no_bold: bool,
241+
separator: String,
242+
underline: String,
243+
text_colors: &TextColors,
244+
) -> Self {
230245
if !self.no_title {
231246
let title = Title::new(
232247
repo,
233248
text_colors.title,
234-
text_colors.tilde,
235-
text_colors.underline,
236249
!no_bold,
250+
separator,
251+
text_colors.separator,
252+
!no_bold,
253+
underline,
254+
text_colors.underline,
237255
);
238256
self.title = Some(title);
239257
}

src/info/title.rs

+37-16
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,51 @@ use serde::Serialize;
88
pub struct Title {
99
pub git_username: String,
1010
pub git_version: String,
11+
1112
#[serde(skip_serializing)]
1213
pub title_color: DynColors,
1314
#[serde(skip_serializing)]
14-
pub tilde_color: DynColors,
15+
pub is_title_bold: bool,
16+
1517
#[serde(skip_serializing)]
16-
pub underline_color: DynColors,
18+
pub separator: String,
19+
#[serde(skip_serializing)]
20+
pub separator_color: DynColors,
21+
#[serde(skip_serializing)]
22+
pub is_separator_bold: bool,
23+
1724
#[serde(skip_serializing)]
18-
pub is_bold: bool,
25+
pub underline: String,
26+
#[serde(skip_serializing)]
27+
pub underline_color: DynColors,
1928
}
2029

2130
impl Title {
2231
pub fn new(
2332
repo: &Repository,
33+
2434
title_color: DynColors,
25-
tilde_color: DynColors,
35+
is_title_bold: bool,
36+
37+
separator: String,
38+
separator_color: DynColors,
39+
is_separator_bold: bool,
40+
41+
underline: String,
2642
underline_color: DynColors,
27-
is_bold: bool,
2843
) -> Self {
2944
let git_username = get_git_username(repo);
3045
let git_version = cli::get_git_version();
3146
Self {
3247
git_username,
3348
git_version,
3449
title_color,
35-
tilde_color,
50+
is_title_bold,
51+
separator,
52+
separator_color,
53+
is_separator_bold,
54+
underline,
3655
underline_color,
37-
is_bold,
3856
}
3957
}
4058
}
@@ -49,16 +67,16 @@ impl std::fmt::Display for Title {
4967
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
5068
if !&self.git_username.is_empty() || !&self.git_version.is_empty() {
5169
let git_info_length = self.git_username.len() + self.git_version.len();
52-
let title_style = get_style(self.is_bold, self.title_color);
70+
let title_style = get_style(self.is_title_bold, self.title_color);
5371

5472
let (git_info_field_str, git_info_field_len) =
5573
if !&self.git_username.is_empty() && !&self.git_version.is_empty() {
56-
let tilde_style = get_style(self.is_bold, self.tilde_color);
74+
let separator_style = get_style(self.is_separator_bold, self.separator_color);
5775
(
5876
format!(
5977
"{} {} {}",
6078
&self.git_username.style(title_style),
61-
"~".style(tilde_style),
79+
&self.separator.style(separator_style),
6280
&self.git_version.style(title_style)
6381
),
6482
git_info_length + 3,
@@ -75,8 +93,8 @@ impl std::fmt::Display for Title {
7593
};
7694

7795
writeln!(f, "{git_info_field_str}")?;
78-
let separator = "-".repeat(git_info_field_len);
79-
writeln!(f, "{}", separator.color(self.underline_color))
96+
let underline = self.underline.repeat(git_info_field_len);
97+
writeln!(f, "{}", underline.color(self.underline_color))
8098
} else {
8199
Ok(())
82100
}
@@ -94,19 +112,22 @@ mod tests {
94112
git_username: "onefetch-committer-name".to_string(),
95113
git_version: "git v2.37.2".to_string(),
96114
title_color: DynColors::Ansi(AnsiColors::Red),
97-
tilde_color: DynColors::Ansi(AnsiColors::White),
115+
is_title_bold: true,
116+
separator: "->".to_string(),
117+
separator_color: DynColors::Ansi(AnsiColors::White),
118+
is_separator_bold: false,
119+
underline: "_".to_string(),
98120
underline_color: DynColors::Ansi(AnsiColors::Blue),
99-
is_bold: true,
100121
};
101122

102123
title.git_version = "git v2.37.2".to_string();
103124
assert!(title.to_string().contains("onefetch-committer-name"));
104-
assert!(title.to_string().contains('~'));
125+
assert!(title.to_string().contains("->"));
105126
assert!(title.to_string().contains("git v2.37.2"));
106127

107128
title.git_version = String::new();
108129
assert!(title.to_string().contains("onefetch-committer-name"));
109-
assert!(!title.to_string().contains('~'));
130+
assert!(!title.to_string().contains("->"));
110131
assert!(!title.to_string().contains("git v2.37.2"));
111132

112133
title.git_username = String::new();

src/ui/text_colors.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use owo_colors::{AnsiColors, DynColors};
44
#[derive(Clone)]
55
pub struct TextColors {
66
pub title: DynColors,
7-
pub tilde: DynColors,
7+
pub separator: DynColors,
88
pub underline: DynColors,
99
pub subtitle: DynColors,
1010
pub colon: DynColors,
@@ -15,7 +15,7 @@ impl TextColors {
1515
pub fn new(colors: &[u8], logo_primary_color: DynColors) -> Self {
1616
let mut text_colors = Self {
1717
title: logo_primary_color,
18-
tilde: DynColors::Ansi(AnsiColors::Default),
18+
separator: DynColors::Ansi(AnsiColors::Default),
1919
underline: DynColors::Ansi(AnsiColors::Default),
2020
subtitle: logo_primary_color,
2121
colon: DynColors::Ansi(AnsiColors::Default),
@@ -26,7 +26,7 @@ impl TextColors {
2626
let custom_color = colors.iter().map(num_to_color).collect::<Vec<DynColors>>();
2727

2828
text_colors.title = *custom_color.first().unwrap_or(&logo_primary_color);
29-
text_colors.tilde = *custom_color
29+
text_colors.separator = *custom_color
3030
.get(1)
3131
.unwrap_or(&DynColors::Ansi(AnsiColors::Default));
3232
text_colors.underline = *custom_color
@@ -53,7 +53,7 @@ mod test {
5353
let primary_color = DynColors::Ansi(AnsiColors::Blue);
5454
let text_colors = TextColors::new(&[], primary_color);
5555
assert_eq!(text_colors.title, primary_color);
56-
assert_eq!(text_colors.tilde, DynColors::Ansi(AnsiColors::Default));
56+
assert_eq!(text_colors.separator, DynColors::Ansi(AnsiColors::Default));
5757
assert_eq!(text_colors.underline, DynColors::Ansi(AnsiColors::Default));
5858
assert_eq!(text_colors.subtitle, primary_color);
5959
assert_eq!(text_colors.colon, DynColors::Ansi(AnsiColors::Default));
@@ -65,7 +65,7 @@ mod test {
6565
let custom_colors = vec![0, 1, 2, 3, 4, 5];
6666
let text_colors = TextColors::new(&custom_colors, DynColors::Ansi(AnsiColors::Blue));
6767
assert_eq!(text_colors.title, num_to_color(&custom_colors[0]));
68-
assert_eq!(text_colors.tilde, num_to_color(&custom_colors[1]));
68+
assert_eq!(text_colors.separator, num_to_color(&custom_colors[1]));
6969
assert_eq!(text_colors.underline, num_to_color(&custom_colors[2]));
7070
assert_eq!(text_colors.subtitle, num_to_color(&custom_colors[3]));
7171
assert_eq!(text_colors.colon, num_to_color(&custom_colors[4]));
@@ -78,7 +78,7 @@ mod test {
7878
let primary_color = DynColors::Ansi(AnsiColors::Blue);
7979
let text_colors = TextColors::new(&custom_colors, primary_color);
8080
assert_eq!(text_colors.title, num_to_color(&custom_colors[0]));
81-
assert_eq!(text_colors.tilde, num_to_color(&custom_colors[1]));
81+
assert_eq!(text_colors.separator, num_to_color(&custom_colors[1]));
8282
assert_eq!(text_colors.underline, num_to_color(&custom_colors[2]));
8383
assert_eq!(text_colors.subtitle, primary_color);
8484
assert_eq!(text_colors.colon, DynColors::Ansi(AnsiColors::Default));

0 commit comments

Comments
 (0)