Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lua: add wezterm.time.call_after and wezterm.reload_configuration
These allow setting up some basic timers and constructing time-dependent config files. Needs to be used respsonsibly!
- Loading branch information
Showing
7 changed files
with
211 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# `wezterm.time.call_after(interval_seconds, function)` | ||
|
||
*Since: nightly builds only* | ||
|
||
Arranges to call your callback function after the specified number of seconds | ||
have elapsed. | ||
|
||
Here's a contrived example that demonstrates a configuration that | ||
varies based on the time. In this case, the idea is that the background | ||
color is derived from the current number of minutes past the hour. | ||
|
||
In order for the value to be picked up for the next minute, `call_after` | ||
is used to schedule a callback 60 seconds later and it then generates | ||
a background color by extracting the current minute value and scaing | ||
it to the range 0-255 and using that to assign a background color: | ||
|
||
```lua | ||
local wezterm = require 'wezterm' | ||
|
||
-- Reload the configuration every minute | ||
wezterm.time.call_after(60, function(window, pane) | ||
wezterm.reload_configuration() | ||
end) | ||
|
||
local amount = math.ceil((tonumber(wezterm.time.now():format("%M")) / 60) * 255) | ||
|
||
return { | ||
colors = { | ||
background = "rgb(" .. amount .. "," .. amount .. "," .. amount .. ")", | ||
} | ||
} | ||
``` | ||
|
||
With great power comes great responsibility: if you schedule a lot of frequent | ||
callbacks, or frequently reload your configuration in this way, you may | ||
increase the CPU load on your system because you are asking it to work harder. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# `wezterm.reload_configuration()` | ||
|
||
*Since: nightly builds only* | ||
|
||
Immediately causes the configuration to be reloaded and re-applied. | ||
|
||
If you call this at the file scope in your config you will create | ||
an infinite loop that renders wezterm unresponsive, so don't do that! | ||
|
||
The intent is for this to be used from an event or timer callback function. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters