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

Module: i3status

parent 47d5fe49
No related branches found
No related tags found
No related merge requests found
...@@ -131,6 +131,77 @@ namespace i3csstatus { ...@@ -131,6 +131,77 @@ namespace i3csstatus {
return new Element[]{new Element(text, color: color)}; return new Element[]{new Element(text, color: color)};
} }
} }
[ModuleName("i3status")]
class ModuleI3Status: Module
{
string name;
string configuration;
Element[] elements;
class Global: GlobalModuleResource
{
public List<ModuleI3Status> modules = new();
System.Diagnostics.Process process;
public override void InitEnd()
{
process = new();
//process.StartInfo.FileName = "tail";
//process.StartInfo.Arguments = "-n 5";
process.StartInfo.FileName = "i3status";
process.StartInfo.Arguments = "-c /dev/stdin";
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
TextWriter stdin = process.StandardInput;
//stdin = Console.Out;
var stdout = process.StandardOutput;
stdin.WriteLine("general {");
stdin.WriteLine("output_format = \"i3bar\"");
stdin.WriteLine("colors = true");
stdin.WriteLine("interval = 1000000000");
stdin.WriteLine("}");
foreach(var m in modules)
{
stdin.WriteLine($"order += \"{m.name}\"");
stdin.WriteLine($"{m.name} {{");
if(m.configuration != null)
stdin.WriteLine(m.configuration);
stdin.WriteLine($"}}");
}
stdin.Close();
stdout.ReadLine();
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()
{
process.KillBySignal(10);
string str = process.StandardOutput.ReadLine()[1..];
Console.WriteLine(str);
JsonArray json = JsonObject.Parse(str).AsArray();
if(json.Count != modules.Count)
throw new Exception("Parse i3status error");
for(int i=0;i<modules.Count;i++)
{
modules[i].elements = new []{parseElement(json[i].AsObject())};
}
}
}
public void Init(StatusBar _bar, ConfigParser config, ConfigSection section)
{
name = section.GetMandatory("name");
configuration = config.GetValue(section.SectionName, "config");
_bar.GetGlobal<Global>().modules.Add(this);
}
public IEnumerable<Element> Get() => elements ?? new Element[]{};
}
#nullable restore #nullable restore
abstract class StatusBar abstract class StatusBar
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment