mirror of
https://github.com/wez/wezterm.git
synced 2024-12-26 14:54:16 +03:00
38 lines
1.2 KiB
Markdown
38 lines
1.2 KiB
Markdown
|
# `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.
|
||
|
|