2022-07-18 16:38:36 +03:00
|
|
|
# `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
|
2022-07-18 22:35:36 +03:00
|
|
|
wezterm.time.call_after(60, function()
|
2022-07-18 16:38:36 +03:00
|
|
|
wezterm.reload_configuration()
|
|
|
|
end)
|
|
|
|
|
2022-07-19 17:54:31 +03:00
|
|
|
local amount =
|
|
|
|
math.ceil((tonumber(wezterm.time.now():format '%M') / 60) * 255)
|
2022-07-18 16:38:36 +03:00
|
|
|
|
|
|
|
return {
|
|
|
|
colors = {
|
2022-07-19 17:54:31 +03:00
|
|
|
background = 'rgb(' .. amount .. ',' .. amount .. ',' .. amount .. ')',
|
|
|
|
},
|
2022-07-18 16:38:36 +03:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
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.
|
|
|
|
|