Waybar icon indicating copy to clipboard operation
Waybar copied to clipboard

Define configuration format

Open lovesegfault opened this issue 6 years ago • 15 comments

Right now the configuration file's format is a weird JSON variation with // comments, at least as I understand it.

It'd be nice if we, instead, used a more config-friendly format (such as TOML or even YAML) that allowed for things like comments. Moreover, it'd be useful if the file was called config.json or config.toml so that editors can pick-up the filetype automatically.

I'll leave a link to an article I enjoy on why JSON is a poor choice for a configuration language: https://www.lucidchart.com/techblog/2018/07/16/why-json-isnt-a-good-configuration-language/

lovesegfault avatar Aug 25 '19 23:08 lovesegfault

That would mean breaking the compatibility with all installs of waybar. The user-base might be small, but this still would cause a lot of troubles.

cafehaine avatar Aug 26 '19 05:08 cafehaine

@cafehaine Not necessarily, the old config could remain, but be removed from wiki/readme and left alongside the TOML one for some time. If you load the old config format it works with a deprecation warning.

A breaking change nonetheless, but with a nice adaption period.

lovesegfault avatar Aug 26 '19 06:08 lovesegfault

The great thing about yaml is that you can actually use a yaml parser to parse json. So that would kind of ensure backwards compatibility with older configs, the only problem being the // comments.

A dirty way to convert old config to yaml:

cat ~/.config/waybar/config | sed 's|//.*$||' | yq -y .

(this won't work if you have // in a string somewhere, but you get the idea)

asmigala avatar Sep 19 '19 15:09 asmigala

+10 i'm really confused about that choice...

eoli3n avatar Dec 12 '19 20:12 eoli3n

Toml is a bad choice too : https://hitchdev.com/strictyaml/why-not/toml/ Yaml is still the easier and cleaner human readable configuration language and would be a great choice for that kind of project.

eoli3n avatar Dec 30 '19 08:12 eoli3n

@eoli3n Agree to disagree and I'll avoid bikeshedding this :laughing:

lovesegfault avatar Dec 30 '19 17:12 lovesegfault

FWIW, current format is just "a JSON variation", it's called jsonc, and actually used by plenty of tools. So I wouldn't discredit is as non-standard.

WhyNotHugo avatar Aug 20 '20 11:08 WhyNotHugo

Any news ?

eoli3n avatar Feb 11 '21 12:02 eoli3n

FWIW, current format is just "a JSON variation", it's called jsonc, and actually used by plenty of tools. So I wouldn't discredit is as non-standard.

I was only able to find that VS Code uses this format for configuration. What other tools were you talking about here?

ghost avatar Oct 06 '21 02:10 ghost

Off the top of my head, nvim-coc uses jsonc, as do flatpak manifests (example). I guess waybar also counts on this list really. There's plenty of libraries for working with jsonc in various languages too.

I'm sure I've seen other applications, but my memory is bad.

Most of these tools use the .json extension, which is a bit annoying since editors are bad at figuring out it's actually jsonc.

I don't think popularity is that important though; it's very easy to explain that jsonc is just "json with comments", and it's not like end users have to learn an entirely new format.

That said, I don't disagree with the initial criticism of JSON. But there's also a lot of valid criticism for YAML (e.g.: type handling). TOML is bad for highly nested structures, or when you have a large set of files that share a schema. For a configuration format like waybars, it's actually not a bad candidate.

Ultimately though, I think this falls into bikeshedding a bit. A PR showing pros and cons of a change is probably best at this point.

WhyNotHugo avatar Oct 15 '21 10:10 WhyNotHugo

I think it is unnecessary to criticize json or jsonc now, but it is necessary to add support for yaml files, and the format of yaml is obviously more beautiful

liiil825 avatar May 14 '23 15:05 liiil825

It boggles my mind that I can't get syntax highlighting...

sascha-wi avatar Feb 23 '24 13:02 sascha-wi

It boggles my mind that I can't get syntax highlighting...

May I ask which editor you use? For vim you can use the jsonc syntax highliting by installing vim-polyglot.

xmalbertox avatar Feb 23 '24 20:02 xmalbertox

+1 for yaml configuration

wille avatar Jul 31 '24 07:07 wille

It boggles my mind that I can't get syntax highlighting...

May I ask which editor you use? For vim you can use the jsonc syntax highliting by installing vim-polyglot.

Did you read this issue thread at all?

sascha-wi avatar Jul 31 '24 09:07 sascha-wi

I just wanted to ask if we can have a defined schema too, especially in the current JSON config. The schema can be included in with the $schema key (See https://json-schema.org/).

yvvki avatar Nov 05 '24 01:11 yvvki