fix(color_util): Parsing

This commit is contained in:
Michael Carlberg 2017-01-27 13:46:27 +01:00
parent af5f129b76
commit beedc5ab84
5 changed files with 61 additions and 26 deletions
src/components

View file

@ -172,9 +172,9 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
}
}
const auto parse_or_throw = [&](string key, string def) {
const auto parse_or_throw = [&](string key, unsigned int def) -> unsigned int {
try {
return color_util::parse(m_conf.get(bs, key, def));
return m_conf.get(bs, key, rgba{def});
} catch (const exception& err) {
throw application_error(sstream() << "Failed to set " << key << " (reason: " << err.what() << ")");
}
@ -192,14 +192,14 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
m_log.warn("Ignoring `%s.background` (overridden by gradient background)", bs);
}
} else {
m_opts.background = parse_or_throw("background", color_util::hex<uint16_t>(m_opts.background));
m_opts.background = parse_or_throw("background", m_opts.background);
}
// Load foreground
m_opts.foreground = parse_or_throw("foreground", color_util::hex<uint16_t>(m_opts.foreground));
m_opts.foreground = parse_or_throw("foreground", m_opts.foreground);
// Load over-/underline
auto line_color = m_conf.get(bs, "line-color", "#ffff0000"s);
auto line_color = m_conf.get(bs, "line-color", rgba{0xFFFF0000});
auto line_size = m_conf.get(bs, "line-size", 0);
m_opts.overline.size = m_conf.get(bs, "overline-size", line_size);
@ -208,7 +208,7 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
m_opts.underline.color = parse_or_throw("underline-color", line_color);
// Load border settings
auto border_color = m_conf.get(bs, "border-color", "#00000000"s);
auto border_color = m_conf.get(bs, "border-color", rgba{0x00000000});
auto border_size = m_conf.get(bs, "border-size", 0);
m_opts.borders.emplace(edge::TOP, border_settings{});