Use match instead of if-lets (fix #11)
This commit is contained in:
@@ -15,26 +15,36 @@ impl Terminal {
|
|||||||
|
|
||||||
pub fn print_separator<P: AsRef<str>>(&self, message: P) {
|
pub fn print_separator<P: AsRef<str>>(&self, message: P) {
|
||||||
let message = message.as_ref();
|
let message = message.as_ref();
|
||||||
if let Some(width) = self.width {
|
match self.width {
|
||||||
print!("\n{}―― {} ", color::Fg(color::LightWhite), message);
|
Some(width) => {
|
||||||
let border = max(2, min(80, width as usize) - 3 - message.len());
|
print!("\n{}―― {} ", color::Fg(color::LightWhite), message);
|
||||||
for _ in 0..border {
|
let border = max(2, min(80, width as usize) - 3 - message.len());
|
||||||
print!("―");
|
for _ in 0..border {
|
||||||
|
print!("―");
|
||||||
|
}
|
||||||
|
println!("{}", color::Fg(color::Reset));
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
println!("―― {} ――", message);
|
||||||
}
|
}
|
||||||
println!("{}", color::Fg(color::Reset));
|
|
||||||
} else {
|
|
||||||
println!("―― {} ――", message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_warning<P: AsRef<str>>(&self, message: P) {
|
pub fn print_warning<P: AsRef<str>>(&self, message: P) {
|
||||||
if let Some(_) = self.width {
|
let message = message.as_ref();
|
||||||
println!(
|
|
||||||
"{}{}{}",
|
match self.width {
|
||||||
color::Fg(color::LightYellow),
|
Some(_) => {
|
||||||
message.as_ref(),
|
println!(
|
||||||
color::Fg(color::Reset)
|
"{}{}{}",
|
||||||
);
|
color::Fg(color::LightYellow),
|
||||||
|
message,
|
||||||
|
color::Fg(color::Reset)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
println!("{}", message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user