Files
Bjarne Øverli 2f7044d071
Release / build (amd64, darwin, macos-latest) (push) Has been cancelled
Release / build (amd64, linux, ubuntu-latest) (push) Has been cancelled
Release / build (amd64, windows, windows-latest) (push) Has been cancelled
Release / build (arm64, darwin, macos-latest) (push) Has been cancelled
Release / build (arm64, linux, ubuntu-latest) (push) Has been cancelled
Release / release (push) Has been cancelled
Release / update-homebrew (push) Has been cancelled
Add cliamp.message plugin API for status bar messages
Plugins can now call cliamp.message(text, duration_secs?) to display
transient messages in the UI status bar. Closes #175.

Delivery flows through prog.Send to the Bubbletea model thread, so
plugin timers and event handlers never touch UI state directly.
2026-04-17 19:06:13 +02:00

31 lines
991 B
Go

package luaplugin
import (
"time"
lua "github.com/yuin/gopher-lua"
)
// messageMaxDuration caps how long a plugin-supplied status message can stay on
// screen. Plugins can request longer durations, but they get clamped so a
// runaway script cannot pin the status bar indefinitely.
const messageMaxDuration = 60 * time.Second
// registerMessageAPI adds cliamp.message(text, duration_secs?) which displays a
// temporary message in the status bar at the bottom of the UI. A missing or
// non-positive duration falls back to the default status TTL (set by the UI).
func registerMessageAPI(L *lua.LState, cliamp *lua.LTable, ui *UIProvider) {
L.SetField(cliamp, "message", L.NewFunction(func(L *lua.LState) int {
if ui.ShowMessage == nil {
return 0
}
text := L.CheckString(1)
var dur time.Duration
if secs := float64(L.OptNumber(2, 0)); secs > 0 {
dur = min(time.Duration(secs*float64(time.Second)), messageMaxDuration)
}
ui.ShowMessage(text, dur)
return 0
}))
}