-
-
Notifications
You must be signed in to change notification settings - Fork 815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add YAML/TOML parsers for Lua configuration API #4969
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! I think this sounds reasonable.
Please also add docs for this new module. I'd suggest looking at https://github.com/wez/wezterm/tree/main/docs/config/lua/wezterm.url for an example of how to lay it out.
The since
macro is important for tracking the version; you can use {{since('nightly')}}
as a placeholder for the version. That will get replaced by the actual version when I make a release.
You can link your new docs into the toc by adding something similar to this:
Lines 401 to 404 in 39d2b6c
Gen( | |
"module: wezterm.url", | |
"config/lua/wezterm.url", | |
), |
You can run the doc build locally using:
./ci/build-docs.sh serve
it will spawn a webserver and print out the port number for you to open it in your browser, and will auto-rebuild and reload your browser as you edit existing doc pages. If you add docs or change the generate-docs.py
script, you will need to ctrl-c and re-run ci/build-docs.sh
for those changes to take effect.
Thank you for your suggestions! Docs, unit tests, and the |
Thanks! |
This PR adds the following two features to the configuration Lua API:
yaml
/toml
formats.yaml
/toml
strings.I renamed the original
lua-api-crates/json
tolua-api-crates/serde-funcs
and added support foryaml
/toml
formats on top of the existingjson
format support. These functions are registered under thewezterm.serde
submodule and include:yaml_encode
/yaml_decode
toml_encode
/toml_decode
json_encode
/json_decode
(copied and renamed from the original functions)Additionally, I re-registered
json_decode
andjson_encode
underwezterm.json_parse
andwezterm.json_encode
, respectively, for backward compatibility.Since both the
toml
andserde_yaml
crates are already in the original project's dependency list, the added functionality has minimal impact on the program's size.This functionality is particularly useful when configuration files need to store or access data in
yaml
/toml
formats.Some users may prefer using
yaml
/toml
as the configuration language, and this feature provides convenience for that purpose.For example, users may want to write some static configuration items in a
yaml
file and then parse that file in thewezterm.lua
configuration file to obtain the final configuration result.In practice, most static configurations can be accomplished using languages like
yaml
.Below is a fragment of my
yaml
configuration file and the corresponding Lua parsing code:In this configuration, I organize domains of different types under the same
yaml
object and use the domain name as the key to ensure the uniqueness domain names, even if they belong to different domains. Otherwise, a modern text editor would issue a warning.