Skip to content

Commit ded5f48

Browse files
committed
Refactor formatted label function to be a method of Info
1 parent dccea3d commit ded5f48

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

Diff for: src/main.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl fmt::Display for Info {
6565
writeln!(
6666
buffer,
6767
"{}{}",
68-
get_formatted_info_label("Project: ", color, self.bold_enabled),
68+
self.get_formatted_info_label("Project: ", color),
6969
self.project_name
7070
)?;
7171
}
@@ -74,7 +74,7 @@ impl fmt::Display for Info {
7474
writeln!(
7575
buffer,
7676
"{}{}",
77-
get_formatted_info_label("HEAD: ", color, self.bold_enabled),
77+
self.get_formatted_info_label("HEAD: ", color),
7878
self.current_commit
7979
)?;
8080
}
@@ -83,7 +83,7 @@ impl fmt::Display for Info {
8383
writeln!(
8484
buffer,
8585
"{}{}",
86-
get_formatted_info_label("Version: ", color, self.bold_enabled),
86+
self.get_formatted_info_label("Version: ", color),
8787
self.version
8888
)?;
8989
}
@@ -92,7 +92,7 @@ impl fmt::Display for Info {
9292
writeln!(
9393
buffer,
9494
"{}{}",
95-
get_formatted_info_label("Created: ", color, self.bold_enabled),
95+
self.get_formatted_info_label("Created: ", color),
9696
self.creation_date
9797
)?;
9898
}
@@ -113,15 +113,15 @@ impl fmt::Display for Info {
113113
writeln!(
114114
buffer,
115115
"{}{}",
116-
get_formatted_info_label(title, color, self.bold_enabled),
116+
self.get_formatted_info_label(title, color),
117117
s
118118
)?;
119119
} else {
120120
let title = "Language: ";
121121
writeln!(
122122
buffer,
123123
"{}{}",
124-
get_formatted_info_label(title, color, self.bold_enabled),
124+
self.get_formatted_info_label(title, color),
125125
self.dominant_language
126126
)?;
127127
};
@@ -137,7 +137,7 @@ impl fmt::Display for Info {
137137
writeln!(
138138
buffer,
139139
"{}{}% {} {}",
140-
get_formatted_info_label(title, color, self.bold_enabled),
140+
self.get_formatted_info_label(title, color),
141141
self.authors[0].2,
142142
self.authors[0].0,
143143
self.authors[0].1
@@ -149,7 +149,7 @@ impl fmt::Display for Info {
149149
writeln!(
150150
buffer,
151151
"{}{}% {} {}",
152-
get_formatted_info_label(&title, color, self.bold_enabled),
152+
self.get_formatted_info_label(&title, color),
153153
author.2,
154154
author.0,
155155
author.1
@@ -161,7 +161,7 @@ impl fmt::Display for Info {
161161
writeln!(
162162
buffer,
163163
"{}{}",
164-
get_formatted_info_label("Last change: ", color, self.bold_enabled),
164+
self.get_formatted_info_label("Last change: ", color),
165165
self.last_change
166166
)?;
167167
}
@@ -170,7 +170,7 @@ impl fmt::Display for Info {
170170
writeln!(
171171
buffer,
172172
"{}{}",
173-
get_formatted_info_label("Repo: ", color, self.bold_enabled),
173+
self.get_formatted_info_label("Repo: ", color),
174174
self.repo
175175
)?;
176176
}
@@ -179,7 +179,7 @@ impl fmt::Display for Info {
179179
writeln!(
180180
buffer,
181181
"{}{}",
182-
get_formatted_info_label("Commits: ", color, self.bold_enabled),
182+
self.get_formatted_info_label("Commits: ", color),
183183
self.commits
184184
)?;
185185
}
@@ -188,7 +188,7 @@ impl fmt::Display for Info {
188188
writeln!(
189189
buffer,
190190
"{}{}",
191-
get_formatted_info_label("Lines of code: ", color, self.bold_enabled),
191+
self.get_formatted_info_label("Lines of code: ", color),
192192
self.number_of_lines
193193
)?;
194194
}
@@ -197,7 +197,7 @@ impl fmt::Display for Info {
197197
writeln!(
198198
buffer,
199199
"{}{}",
200-
get_formatted_info_label("Size: ", color, self.bold_enabled),
200+
self.get_formatted_info_label("Size: ", color),
201201
self.repo_size
202202
)?;
203203
}
@@ -206,7 +206,7 @@ impl fmt::Display for Info {
206206
writeln!(
207207
buffer,
208208
"{}{}",
209-
get_formatted_info_label("License: ", color, self.bold_enabled),
209+
self.get_formatted_info_label("License: ", color),
210210
self.license
211211
)?;
212212
}
@@ -340,15 +340,6 @@ fn true_len(line: &str) -> usize {
340340
.len()
341341
}
342342

343-
// Returns a formatted label with the desired color and boldness
344-
fn get_formatted_info_label(label: &str, color: Color, bold: bool) -> ColoredString {
345-
let mut formatted_label = label.color(color);
346-
if bold {
347-
formatted_label = formatted_label.bold();
348-
}
349-
formatted_label
350-
}
351-
352343
struct CommitInfo {
353344
commit: Oid,
354345
refs: Vec<String>,
@@ -1142,6 +1133,15 @@ impl Info {
11421133
}
11431134
}
11441135

1136+
// Returns a formatted info label with the desired color and boldness
1137+
fn get_formatted_info_label(&self, label: &str, color: Color) -> ColoredString {
1138+
let mut formatted_label = label.color(color);
1139+
if self.bold_enabled {
1140+
formatted_label = formatted_label.bold();
1141+
}
1142+
formatted_label
1143+
}
1144+
11451145
fn colors(&self) -> Vec<Color> {
11461146
let language =
11471147
if let Language::Unknown = self.custom_logo {

0 commit comments

Comments
 (0)