summaryrefslogtreecommitdiffstats
path: root/alacritty_terminal
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2020-02-28 05:28:15 +0300
committerGitHub <noreply@github.com>2020-02-28 02:28:15 +0000
commit2365425fd27541b55870ec9cd131dbb2801e8787 (patch)
tree18818433d0f1a37fc27193ca8b1f829dfe888076 /alacritty_terminal
parent43f89a64c28a2896b93ebb2aba10a3e8e23b4ba1 (diff)
Fix log target of color config errors
Due to incorrect log target in the color config errors, the message bar was not cleared when the error was fixed.
Diffstat (limited to 'alacritty_terminal')
-rw-r--r--alacritty_terminal/src/term/color.rs64
1 files changed, 29 insertions, 35 deletions
diff --git a/alacritty_terminal/src/term/color.rs b/alacritty_terminal/src/term/color.rs
index f3f42e92..b452245e 100644
--- a/alacritty_terminal/src/term/color.rs
+++ b/alacritty_terminal/src/term/color.rs
@@ -7,7 +7,7 @@ use serde::de::Visitor;
use serde::{Deserialize, Deserializer, Serialize};
use crate::ansi;
-use crate::config::Colors;
+use crate::config::{Colors, LOG_TARGET_CONFIG};
pub const COUNT: usize = 269;
@@ -66,10 +66,14 @@ impl<'de> Deserialize<'de> for Rgb {
fn visit_str<E>(self, value: &str) -> ::std::result::Result<Rgb, E>
where
- E: ::serde::de::Error,
+ E: serde::de::Error,
{
- Rgb::from_str(&value[..])
- .map_err(|_| E::custom("failed to parse rgb; expected hex color like #ff00ff"))
+ Rgb::from_str(&value[..]).map_err(|_| {
+ E::custom(format!(
+ "failed to parse rgb color {}; expected hex color like #ff00ff",
+ value
+ ))
+ })
}
}
@@ -85,7 +89,10 @@ impl<'de> Deserialize<'de> for Rgb {
match value.deserialize_str(RgbVisitor) {
Ok(rgb) => Ok(rgb),
Err(err) => {
- error!("Problem with config: {}; using color #000000", err);
+ error!(
+ target: LOG_TARGET_CONFIG,
+ "Problem with config: {}; using color #000000", err
+ );
Ok(Rgb::default())
},
}
@@ -95,39 +102,26 @@ impl<'de> Deserialize<'de> for Rgb {
impl FromStr for Rgb {
type Err = ();
- fn from_str(s: &str) -> ::std::result::Result<Rgb, ()> {
- let mut chars = s.chars();
- let mut rgb = Rgb::default();
-
- macro_rules! component {
- ($($c:ident),*) => {
- $(
- match chars.next().and_then(|c| c.to_digit(16)) {
- Some(val) => rgb.$c = (val as u8) << 4,
- None => return Err(())
- }
-
- match chars.next().and_then(|c| c.to_digit(16)) {
- Some(val) => rgb.$c |= val as u8,
- None => return Err(())
- }
- )*
- }
- }
+ fn from_str(s: &str) -> std::result::Result<Rgb, ()> {
+ let chars = if s.starts_with("0x") && s.len() == 8 {
+ &s[2..]
+ } else if s.starts_with('#') && s.len() == 7 {
+ &s[1..]
+ } else {
+ return Err(());
+ };
- match chars.next() {
- Some('0') => {
- if chars.next() != Some('x') {
- return Err(());
- }
+ match u32::from_str_radix(chars, 16) {
+ Ok(mut color) => {
+ let b = (color & 0xff) as u8;
+ color >>= 8;
+ let g = (color & 0xff) as u8;
+ color >>= 8;
+ let r = color as u8;
+ Ok(Rgb { r, g, b })
},
- Some('#') => (),
- _ => return Err(()),
+ Err(_) => Err(()),
}
-
- component!(r, g, b);
-
- Ok(rgb)
}
}