ok/jj
1
0
Fork 0
forked from mirrors/jj

formatter: make color_for_name() a free function

The function doesn't use its `&self` argument anyway.
This commit is contained in:
Martin von Zweigbergk 2022-12-31 14:18:14 -08:00 committed by Martin von Zweigbergk
parent efd652d7ea
commit 8db8da5990

View file

@ -208,14 +208,15 @@ impl<W> ColorFormatter<W> {
} }
} }
let color = self.color_for_name(best_match.1); let color = color_for_name(best_match.1);
self.cached_colors self.cached_colors
.insert(self.labels.clone(), color.clone()); .insert(self.labels.clone(), color.clone());
color color
} }
} }
}
fn color_for_name(&self, color_name: &str) -> Vec<u8> { fn color_for_name(color_name: &str) -> Vec<u8> {
match color_name { match color_name {
"black" => b"\x1b[30m".to_vec(), "black" => b"\x1b[30m".to_vec(),
"red" => b"\x1b[31m".to_vec(), "red" => b"\x1b[31m".to_vec(),
@ -236,7 +237,6 @@ impl<W> ColorFormatter<W> {
_ => b"\x1b[0m".to_vec(), _ => b"\x1b[0m".to_vec(),
} }
} }
}
impl<W: Write> Write for ColorFormatter<W> { impl<W: Write> Write for ColorFormatter<W> {
fn write(&mut self, data: &[u8]) -> Result<usize, Error> { fn write(&mut self, data: &[u8]) -> Result<usize, Error> {