Alexays / Waybar

Highly customizable Wayland bar for Sway and Wlroots based compositors. :v: :tada:
MIT License
6.67k stars 709 forks source link

Define configuration format #434

Open lovesegfault opened 5 years ago

lovesegfault commented 5 years ago

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/

cafehaine commented 5 years ago

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.

lovesegfault commented 5 years ago

@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.

asmigala commented 5 years ago

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)

eoli3n commented 4 years ago

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

eoli3n commented 4 years ago

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.

lovesegfault commented 4 years ago

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

WhyNotHugo commented 4 years ago

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.

eoli3n commented 3 years ago

Any news ?

ghost commented 3 years ago

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?

WhyNotHugo commented 3 years ago

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.

liiil825 commented 1 year ago

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

sascha-wi commented 8 months ago

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

xmalbertox commented 8 months ago

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.

wille commented 3 months ago

+1 for yaml configuration

sascha-wi commented 3 months ago

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?

yvvki commented 1 week ago

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/).