Added return-type json to custom module

This commit is contained in:
Robinhuett
2018-11-01 00:40:44 +01:00
parent 341d3300fa
commit e23fbd0add
2 changed files with 24 additions and 3 deletions

View File

@ -73,7 +73,12 @@ auto waybar::modules::Custom::update() -> void
} else {
label_.set_name("custom-" + name_);
parseOutput();
if (config_["return-type"].asString() == "json") {
parseOutputJson();
} else {
parseOutputRaw();
}
auto str = fmt::format(format_, text_);
label_.set_text(str);
if (text_ == tooltip_) {
@ -96,7 +101,7 @@ auto waybar::modules::Custom::update() -> void
}
}
void waybar::modules::Custom::parseOutput()
void waybar::modules::Custom::parseOutputRaw()
{
std::istringstream output(output_.out);
std::string line;
@ -115,4 +120,17 @@ void waybar::modules::Custom::parseOutput()
}
i++;
}
}
void waybar::modules::Custom::parseOutputJson()
{
std::istringstream output(output_.out);
std::string line;
while (getline(output, line)) {
auto parsed = parser_.parse(line);
text_ = parsed["text"].asString();
tooltip_ = parsed["tooltip"].asString();
class_ = parsed["class"].asString();
break;
}
}