Skip to content
Snippets Groups Projects
Commit 62efb842 authored by Jiří Kalvoda's avatar Jiří Kalvoda
Browse files

Parser: I3

parent 4db22bae
No related branches found
No related tags found
No related merge requests found
......@@ -386,6 +386,7 @@ class ModuleI3Status: Module
System.Diagnostics.Process process;
public int? cache_ms;
long lastGet_ms = 0;
Parser parser = new ParserI3();
public override void InitEnd()
{
process = new();
......@@ -417,14 +418,6 @@ class ModuleI3Status: Module
stdout.ReadLine();
stdout.ReadLine();
}
static Element parseElement(JsonObject json)
{
return new Element(
text: json["full_text"].AsValue().GetValue<string>(),
short_text: json["short_text"]?.AsValue()?.GetValue<string>(),
color: System.Drawing.ColorTranslator.FromHtml(json["color"]?.AsValue()?.GetValue<string>() ?? "white")
);
}
public override void GetBegin()
{
long t = Environment.TickCount64;
......@@ -437,12 +430,12 @@ class ModuleI3Status: Module
{
throw new ModuleI3StatusException();
}
JsonArray json = JsonObject.Parse(line[1..]).AsArray();
if(json.Count != modules.Count)
Element[] data = (Element[])parser.Parse(line[1..]);
if(data.Length != modules.Count)
throw new Exception("Parse i3status error");
for(int i=0;i<modules.Count;i++)
{
modules[i].elements = new []{parseElement(json[i].AsObject())};
modules[i].elements = new []{data[i]};
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment