A View holds one status, so it can only ever describe the program itself.
Its own type makes child ids and the clear state impossible to write
instead of silently ignoring them.
💘 Generated with Crush
Assisted-by: Crush:claude-opus-5-5
88 lines
2.9 KiB
Go
88 lines
2.9 KiB
Go
package tea
|
|
|
|
import (
|
|
uv "github.com/charmbracelet/ultraviolet"
|
|
"github.com/charmbracelet/x/ansi"
|
|
)
|
|
|
|
// ProgramStatus is a Program Status Protocol (OSC 7501) report. It tells the
|
|
// terminal whether the program is idle, working, waiting on the user, done,
|
|
// or failed, and why. Set it on [View.ProgramStatus].
|
|
//
|
|
// Support depends on the terminal. Terminals that don't support it ignore it.
|
|
//
|
|
// See: https://www.superlogical.com/rex/docs/build/program-status
|
|
type ProgramStatus struct {
|
|
// State is the program state. Required.
|
|
State ProgramState
|
|
// App is a stable machine-readable program name matching
|
|
// [A-Za-z0-9_.+-]{1,32}. Invalid values are omitted.
|
|
App string
|
|
// Kind says what a blocked program waits for. Only used with
|
|
// [ProgramStateBlocked].
|
|
Kind ProgramStatusKind
|
|
// Progress is a percentage between 0 and 100. Only used with
|
|
// [ProgramStateWorking] and [ProgramStateBlocked] when HasProgress is
|
|
// true. Otherwise progress is indeterminate.
|
|
Progress int
|
|
// HasProgress reports whether Progress is set.
|
|
HasProgress bool
|
|
// Title is a short human-readable label.
|
|
Title string
|
|
// Message is one human-readable line describing the status.
|
|
Message string
|
|
}
|
|
|
|
func (ps ProgramStatus) toANSI() ansi.ProgramStatus {
|
|
return ansi.ProgramStatus{
|
|
State: ps.State,
|
|
App: ps.App,
|
|
Kind: ps.Kind,
|
|
Progress: ps.Progress,
|
|
HasProgress: ps.HasProgress,
|
|
Title: ps.Title,
|
|
Message: ps.Message,
|
|
}
|
|
}
|
|
|
|
// ProgramState is the state of a [ProgramStatus].
|
|
type ProgramState = uv.ProgramState
|
|
|
|
// ProgramStatusKind says what a blocked program waits for.
|
|
type ProgramStatusKind = uv.ProgramStatusKind
|
|
|
|
// Program states. Set [View.ProgramStatus] to nil to clear the status.
|
|
const (
|
|
ProgramStateIdle = uv.ProgramStateIdle
|
|
ProgramStateWorking = uv.ProgramStateWorking
|
|
ProgramStateDone = uv.ProgramStateDone
|
|
ProgramStateBlocked = uv.ProgramStateBlocked
|
|
ProgramStateError = uv.ProgramStateError
|
|
)
|
|
|
|
// Program status kinds.
|
|
const (
|
|
ProgramStatusKindPermission = uv.ProgramStatusKindPermission
|
|
ProgramStatusKindQuestion = uv.ProgramStatusKindQuestion
|
|
ProgramStatusKindAuth = uv.ProgramStatusKindAuth
|
|
)
|
|
|
|
// ProgramStatusSupportMsg is sent when the terminal replies to
|
|
// [RequestProgramStatusSupport], meaning it supports the Program Status
|
|
// Protocol.
|
|
type ProgramStatusSupportMsg struct{}
|
|
|
|
// programStatusSupportMsg is an internal message that queries the terminal
|
|
// for Program Status Protocol support.
|
|
type programStatusSupportMsg struct{}
|
|
|
|
// RequestProgramStatusSupport is a command that asks the terminal whether it
|
|
// supports the Program Status Protocol (OSC 7501). A supporting terminal
|
|
// replies with a [ProgramStatusSupportMsg]. Terminals that don't support it
|
|
// never reply, so pick your own timeout. Use [WithInput] to enable input,
|
|
// since the reply cannot be read otherwise.
|
|
//
|
|
// Detection is optional: reports can be sent without it.
|
|
func RequestProgramStatusSupport() Msg {
|
|
return programStatusSupportMsg{}
|
|
}
|