mirror of
https://github.com/wez/wezterm.git
synced 2024-12-25 22:33:52 +03:00
e0ea0f46a8
refs: https://github.com/wez/wezterm/pull/2273 refs: https://github.com/wez/wezterm/issues/2253
39 lines
1.2 KiB
Markdown
39 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()
|
|
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.
|
|
|