diff --git a/Module.cs b/Module.cs index a30a0d28531663a647eac0a3235565978d52d316..1234eea67f2c2016f0847a8374230525a022bf77 100644 --- a/Module.cs +++ b/Module.cs @@ -112,7 +112,7 @@ class ModuleConstant: Module string text; public void Init(ModuleParent _bar, ConfigSection section) { - text = section.Mandatory("text"); + text = section.OptionalDefaultIsSectionName("text").AsString(); } public IEnumerable<Block> Get() { @@ -146,7 +146,7 @@ text = NFound _color = red text = ERR ")); - parser = _bar.GetGlobal<ParserGetter>().ByNameFromConfig(section.Optional("parser")); + parser = _bar.GetGlobal<ParserGetter>().ByNameFromConfig(section.OptionalDefaultIsSectionName("parser")); parser.Init(_bar, this, section); } public IEnumerable<Block> Get() @@ -191,7 +191,7 @@ abstract class ModuleSourceThreadAndParser: Module scheudleIn_ms = section.Optional("delay")?.AsMs() ?? 10; showOld_ms = section.Optional("show_old")?.AsMs(); maxOld_ms = section.Optional("max_old")?.AsMs(); - parser = _bar.GetGlobal<ParserGetter>().ByNameFromConfig(section.Optional("parser")); + parser = _bar.GetGlobal<ParserGetter>().ByNameFromConfig(section.OptionalDefaultIsSectionName("parser")); parser.Init(_bar, this, section); inputThread = new Thread(this.inputThreadFunc); @@ -493,7 +493,7 @@ class ModuleI3Status: Module } public void Init(ModuleParent _bar, ConfigSection section) { - name = section["name"]; + name = section.OptionalDefaultIsSectionName("name").AsString(); configuration = section.Optional("config")?.AsString(); var g = _bar.GetGlobal<Global>(); g.modules.Add(this); diff --git a/Parsers.cs b/Parsers.cs index 649ded0757a95b92274836ced6508ebdc7a19532..fb514e7b3d376924a35d9bbcc73239a4805abf57 100644 --- a/Parsers.cs +++ b/Parsers.cs @@ -88,7 +88,7 @@ class ParserGetter: GlobalModuleResource if(val == null) return new ParserText(); var p = ByName(val.AsString()); if(p == null) - throw new ConfigMistake(val, $"Parser with name {val.AsString()} not exists."); + throw new ConfigMistake(val, $"Parser with name \"{val.AsString()}\" not exists."); return p; } diff --git a/Program.cs b/Program.cs index 72ce47dbbc9a08a8e4764f6b1da26a81e259a2cd..edc16a96ff7fd83b63bf9c74c363f4c05dc605e8 100644 --- a/Program.cs +++ b/Program.cs @@ -243,12 +243,10 @@ refresh foreach(var s in p) { - #pragma warning disable 8600 - string type = s["_type"] ?? s.SectionName; - #pragma warning restore 8600 - #pragma warning disable 8604 - var constructor = moduleTypes[type].GetConstructor(constructorSignature); - #pragma warning restore 8604 + ConfigValue type = s.OptionalDefaultIsSectionName("_type"); + if(!moduleTypes.ContainsKey(type.AsString())) + throw new ConfigMistake(type, $"Module type with name \"{type.AsString()}\" not exists."); + var constructor = moduleTypes[type.AsString()].GetConstructor(constructorSignature); if(constructor == null) throw new Exception($"Missing constructor of {type} module"); Module module = (Module) constructor.Invoke(new object[]{}); diff --git a/Wrappers.cs b/Wrappers.cs index 743c0941c45109b74a1b1074934c7168f84ace2a..443994a7424d5794aaec28165b6d009bdc8e39cc 100644 --- a/Wrappers.cs +++ b/Wrappers.cs @@ -40,6 +40,9 @@ abstract partial class StatusBar if(section.Contains("_color")) module = new WrapperColor(module, section.Mandatory("_color").AsColor()); + if(section.Contains("_exec")) + module = new WrapperExec(module, section.Mandatory("_exec").AsString(), MouseButton.Left, 0); + module.Init(parrent, section); return module; } diff --git a/sample.conf b/sample.conf index 44c872662c1190351ba7749a49b0a9872fac4acd..611f43249792b53d1db1451264745b9d943d5bb6 100644 --- a/sample.conf +++ b/sample.conf @@ -112,7 +112,7 @@ refresh = 1 # Note that only one i3status instance is running for the whole status bar. # Due to technical limitations of i3status the `name` option must be unique. name=ethernet _first_ -# mandatory <string> +# <string> default is section name config format_up = "E: %ip (%speed)" format_down = "E: down" @@ -176,6 +176,7 @@ short_format = {percent} [constant] # Just show some text text = Hi! +# <string> default is section name [file] @@ -311,6 +312,7 @@ _default_color = red # Some of modules use parsers. It is part of module that is responsible for # processing text oriented message to a part of the status bar. # You can specify which parser you would like to use by `parser` option. +# If `parser` option is not defined, section name will be used as parse name. # Parsers can specify extra options. # Parser: text