feat: OSC 7501 (#1841)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Drew Smirnoff · committed by GitHub · parent 96d69d2 · Browse files · 11 files·+335 added−42 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Signed-off-by: drew <me@andrinoff.com>
Diff stats
11 files+335 added−42 removed
- other:+335 added−42 removed
Provenance
- Commit
41bc626- Tree
afe5ce9- Author
Drew Smirnoff <drew@charm.land>- Committer
GitHub <noreply@github.com>- Parent
96d69d2
11 files changed+335 added−42 removed
added:examples/program-status/main.go+93 added
1+package main2+3+import (4+ "fmt"5+ "log"6+ "time"7+8+ tea "charm.land/bubbletea/v2"9+)10+11+type tickMsg struct{}12+13+func tick() tea.Cmd {14+ return tea.Tick(200*time.Millisecond, func(time.Time) tea.Msg { return tickMsg{} })15+}16+17+var states = []tea.ProgramState{18+ tea.ProgramStateIdle,19+ tea.ProgramStateWorking,20+ tea.ProgramStateBlocked,21+ tea.ProgramStateDone,22+ tea.ProgramStateError,23+}24+25+var messages = map[tea.ProgramState]string{26+ tea.ProgramStateIdle: "Waiting for instructions",27+ tea.ProgramStateWorking: "Building the project",28+ tea.ProgramStateBlocked: "Deploy to production?",29+ tea.ProgramStateDone: "Build finished",30+ tea.ProgramStateError: "Build failed",31+}32+33+type model struct {34+ state int35+ progress int36+ supported bool37+}38+39+func (m model) Init() tea.Cmd {40+ return tea.Batch(tea.RequestProgramStatusSupport, tick())41+}42+43+func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {44+ switch msg := msg.(type) {45+ case tea.ProgramStatusSupportMsg:46+ m.supported = true47+ case tickMsg:48+ if states[m.state] == tea.ProgramStateWorking {49+ m.progress = (m.progress + 5) % 10550+ }51+ return m, tick()52+ case tea.KeyPressMsg:53+ switch msg.String() {54+ case "q", "ctrl+c":55+ return m, tea.Quit56+ case "right", "l", "space":57+ m.state = (m.state + 1) % len(states)58+ m.progress = 059+ case "left", "h":60+ m.state = (m.state + len(states) - 1) % len(states)61+ m.progress = 062+ }63+ }64+ return m, nil65+}66+67+func (m model) View() tea.View {68+ state := states[m.state]69+ support := "no reply yet (unsupported, or behind tmux)"70+ if m.supported {71+ support = "supported"72+ }73+74+ v := tea.NewView(fmt.Sprintf(75+ "Program Status Protocol (OSC 7501): %s\n\nState: %s\nMessage: %s\n\nPress left/right to change state, q to quit.\n",76+ support, state, messages[state],77+ ))78+ v.ProgramStatus = &tea.ProgramStatus{79+ State: state,80+ App: "program-status-example",81+ Kind: tea.ProgramStatusKindPermission,82+ Progress: m.progress,83+ HasProgress: state == tea.ProgramStateWorking,84+ Message: messages[state],85+ }86+ return v87+}88+89+func main() {90+ if _, err := tea.NewProgram(model{}).Run(); err != nil {91+ log.Fatalf("Error: %v", err)92+ }93+}modified:examples/go.mod+7 added-7 removed
9 unmodified lines10 charm.land/glamour/v2 v2.0.011 charm.land/lipgloss/v2 v2.0.312 github.com/charmbracelet/colorprofile v0.4.313 github.com/charmbracelet/harmonica v0.2.014- github.com/charmbracelet/x/ansi v0.11.714+ github.com/charmbracelet/x/ansi v0.11.915 github.com/charmbracelet/x/exp/charmtone v0.0.0-20250602192518-9e722df69bbb16 github.com/charmbracelet/x/term v0.2.217 github.com/fogleman/ease v0.0.0-20170301025033-8da417bf177618- github.com/lucasb-eyer/go-colorful v1.4.018+ github.com/lucasb-eyer/go-colorful v1.4.119 github.com/segmentio/ksuid v1.0.420 )21 22 require (23 github.com/alecthomas/chroma/v2 v2.14.0 // indirect24 github.com/atotto/clipboard v0.1.4 // indirect25 github.com/aymerick/douceur v0.2.0 // indirect26- github.com/charmbracelet/ultraviolet v0.0.0-20260703014108-f5a850f9c2b7 // indirect26+ github.com/charmbracelet/ultraviolet v0.0.0-20261008173134-6b8d4baf91b4 // indirect27 github.com/charmbracelet/x/exp/slice v0.0.0-20250327172914-2fdc97757edf // indirect28 github.com/charmbracelet/x/termios v0.1.1 // indirect29 github.com/charmbracelet/x/windows v0.2.2 // indirect30 github.com/clipperhouse/displaywidth v0.11.0 // indirect31 github.com/clipperhouse/uax29/v2 v2.7.0 // indirect32 github.com/dlclark/regexp2 v1.11.0 // indirect33 github.com/dustin/go-humanize v1.0.1 // indirect34 github.com/gorilla/css v1.0.1 // indirect35- github.com/mattn/go-runewidth v0.0.23 // indirect35+ github.com/mattn/go-runewidth v0.0.30 // indirect36 github.com/microcosm-cc/bluemonday v1.0.27 // indirect37 github.com/muesli/cancelreader v0.2.2 // indirect38 github.com/rivo/uniseg v0.4.7 // indirect39 github.com/sahilm/fuzzy v0.1.1 // indirect40- github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect40+ github.com/xo/terminfo v1.0.0 // indirect41 github.com/yuin/goldmark v1.7.8 // indirect42 github.com/yuin/goldmark-emoji v1.0.5 // indirect43 golang.org/x/net v0.39.0 // indirect44- golang.org/x/sync v0.21.0 // indirect45- golang.org/x/sys v0.46.0 // indirect44+ golang.org/x/sync v0.22.0 // indirect45+ golang.org/x/sys v0.47.0 // indirect46 golang.org/x/text v0.24.0 // indirect47 )modified:examples/go.sum+14 added-14 removed
20 unmodified lines21 github.com/charmbracelet/colorprofile v0.4.3 h1:QPa1IWkYI+AOB+fE+mg/5/4HRMZcaXex9t5KX76i20Q=22 github.com/charmbracelet/colorprofile v0.4.3/go.mod h1:/zT4BhpD5aGFpqQQqw7a+VtHCzu+zrQtt1zhMt9mR4Q=23 github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=24 github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=25-github.com/charmbracelet/ultraviolet v0.0.0-20260703014108-f5a850f9c2b7 h1:3FmWoGNWK4STvqg0O0Aeav2T7rodWJAPeF0QpH+8gFw=26-github.com/charmbracelet/ultraviolet v0.0.0-20260703014108-f5a850f9c2b7/go.mod h1:f/jRa757WUmaOZrbPspXymbg/GnbF+rwe4OLsG7aXYo=27-github.com/charmbracelet/x/ansi v0.11.7 h1:kzv1kJvjg2S3r9KHo8hDdHFQLEqn4RBCb39dAYC84jI=28-github.com/charmbracelet/x/ansi v0.11.7/go.mod h1:9qGpnAVYz+8ACONkZBUWPtL7lulP9No6p1epAihUZwQ=25+github.com/charmbracelet/ultraviolet v0.0.0-20261008173134-6b8d4baf91b4 h1:hISLzUbwcvJbGoNR6A3L/TpguRRnACBmZOee8LcHLJw=26+github.com/charmbracelet/ultraviolet v0.0.0-20261008173134-6b8d4baf91b4/go.mod h1:aJDVk+WOVM1K04rdc/71PMPoUGfjxjhvXfP3Pjz1Zio=27+github.com/charmbracelet/x/ansi v0.11.9 h1:kIrqLBxtTVbLyyHO2Evoi93EjQo1mylWmpNEsfPxXAM=28+github.com/charmbracelet/x/ansi v0.11.9/go.mod h1:DG/hpOnaI2QJ/KMMqLL2h0KVhluuJLazf8973P+Vy5w=29 github.com/charmbracelet/x/exp/charmtone v0.0.0-20250602192518-9e722df69bbb h1:oTM8tZxV7FY0ehvYjFuICouuhzE08UZYNqUIp/lDQdY=30 github.com/charmbracelet/x/exp/charmtone v0.0.0-20250602192518-9e722df69bbb/go.mod h1:T9jr8CzFpjhFVHjNjKwbAD7KwBNyFnj2pntAO7F2zw0=31 github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f h1:pk6gmGpCE7F3FcjaOEKYriCvpmIN4+6OS/RD0vm4uIA=32 github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f/go.mod h1:IfZAMTHB6XkZSeXUqriemErjAWCCzT0LwjKFYCZyw0I=20 unmodified lines53 github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=54 github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=55 github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=56 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=57-github.com/lucasb-eyer/go-colorful v1.4.0 h1:UtrWVfLdarDgc44HcS7pYloGHJUjHV/4FwW4TvVgFr4=58-github.com/lucasb-eyer/go-colorful v1.4.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=59-github.com/mattn/go-runewidth v0.0.23 h1:7ykA0T0jkPpzSvMS5i9uoNn2Xy3R383f9HDx3RybWcw=60-github.com/mattn/go-runewidth v0.0.23/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=57+github.com/lucasb-eyer/go-colorful v1.4.1 h1:1EO+WB73+EH8EVbzlrG3KLAfEypQWVHIBqlTf+2hNss=58+github.com/lucasb-eyer/go-colorful v1.4.1/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=59+github.com/mattn/go-runewidth v0.0.30 h1:+KUuiDA4fF0R1p5FeueHefjDm+GIM+kWfFnDjybOPgk=60+github.com/mattn/go-runewidth v0.0.30/go.mod h1:3qAiGCV4Koz/yuveO58qUefmUTRm8r0IGEXZ9jeHp/8=61 github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=62 github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=63 github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=64 github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=2 unmodified lines67 github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA=68 github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=69 github.com/segmentio/ksuid v1.0.4 h1:sBo2BdShXjmcugAMwjugoGUdUV0pcxY5mW4xKRn3v4c=70 github.com/segmentio/ksuid v1.0.4/go.mod h1:/XUiZBD3kVx5SmUOl55voK5yeAbBNNIed+2O73XgrPE=71-github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=72-github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=71+github.com/xo/terminfo v1.0.0 h1:2ZpYzqWzyyytjk3TP6aJVDhkMAkc99/1xKQdA3TDTBY=72+github.com/xo/terminfo v1.0.0/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=73 github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=74 github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=75 github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=76 github.com/yuin/goldmark-emoji v1.0.5 h1:EMVWyCGPlXJfUXBXpuMu+ii3TIaxbVBnEX9uaDC4cIk=1 unmodified line78 golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=79 golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=80 golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY=81 golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E=82-golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=83-golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=84-golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=85-golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=82+golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=83+golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=84+golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=85+golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=86 golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=87 golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=modified:cursed_renderer.go+37 added
154 unmodified lines155 }156 if s.lastView.ProgressBar != nil {157 setProgressBar(s, s.lastView.ProgressBar)158 }159+ if s.lastView.ProgramStatus != nil {160+ setProgramStatus(s, nil, s.lastView.ProgramStatus)161+ }162 if !s.noInput {163 // Enable modifyOtherKeys and Kitty keyboard protocol.164 // Both can coexist; terminals ignore what they don't support.165 _, _ = s.scr.WriteString(ansi.SetModifyOtherKeys2)81 unmodified lines247 }248 if lv.ProgressBar != nil && lv.ProgressBar.State != ProgressBarNone {249 _, _ = s.scr.WriteString(ansi.ResetProgressBar)250 }251+ // Unlike the progress bar, the program status is left in place: done252+ // and error reports should outlive the program, and terminals drop253+ // working and blocked records when the process exits.254 }255 256 if s.cellbuf.Method == ansi.GraphemeWidth {257 // Make sure to turn off Unicode mode (2027)253 unmodified lines511 // Render or clear the progress bar if it was added or removed.512 setProgressBar(s, view.ProgressBar)513 }514 515+ // Report the program status if it's changed.516+ var lps *ProgramStatus517+ if s.lastView != nil {518+ lps = s.lastView.ProgramStatus519+ }520+ if !programStatusEquals(lps, view.ProgramStatus) {521+ setProgramStatus(s, lps, view.ProgramStatus)522+ }523+524 // Render and queue changes to the screen buffer.525 s.scr.Render(s.cellbuf.RenderBuffer)526 527 if cur := view.Cursor; cur != nil {336 unmodified lines864 _, _ = s.scr.WriteString(seq)865 }866 }867 868+func programStatusEquals(a, b *ProgramStatus) bool {869+ if a == nil || b == nil {870+ return a == b871+ }872+ return *a == *b873+}874+875+// setProgramStatus reports cur to the terminal. When cur is nil, or addresses876+// a different record than prev, the record of prev is cleared first.877+func setProgramStatus(s *cursedRenderer, prev, cur *ProgramStatus) {878+ if prev != nil && (cur == nil || cur.ID != prev.ID) {879+ _, _ = s.scr.WriteString(ansi.ClearProgramStatusID(prev.ID))880+ }881+ if cur != nil {882+ _, _ = s.scr.WriteString(ansi.SetProgramStatus(*cur))883+ }884+}885+886 func viewEquals(a, b *View) bool {887 if a == nil || b == nil {888 return false889 }890 891+ if !programStatusEquals(a.ProgramStatus, b.ProgramStatus) {892+ return false893+ }894+895 if a.Content != b.Content ||896 a.AltScreen != b.AltScreen ||897 a.DisableBracketedPasteMode != b.DisableBracketedPasteMode ||898 a.ReportFocus != b.ReportFocus ||49 unmodified linesmodified:go.mod+7 added-7 removed
4 unmodified lines5 go 1.26.06 7 require (8 github.com/charmbracelet/colorprofile v0.4.39- github.com/charmbracelet/ultraviolet v0.0.0-20260703014108-f5a850f9c2b710- github.com/charmbracelet/x/ansi v0.11.79+ github.com/charmbracelet/ultraviolet v0.0.0-20261008173134-6b8d4baf91b410+ github.com/charmbracelet/x/ansi v0.11.911 github.com/charmbracelet/x/exp/golden v0.0.0-20241212170349-ad4b7ae0f25f12 github.com/charmbracelet/x/term v0.2.213- github.com/lucasb-eyer/go-colorful v1.4.013+ github.com/lucasb-eyer/go-colorful v1.4.114 github.com/muesli/cancelreader v0.2.215- golang.org/x/sys v0.46.015+ golang.org/x/sys v0.47.016 )17 18 require (19 github.com/aymanbagabas/go-udiff v0.2.0 // indirect20 github.com/charmbracelet/x/termios v0.1.1 // indirect21 github.com/charmbracelet/x/windows v0.2.2 // indirect22 github.com/clipperhouse/displaywidth v0.11.0 // indirect23 github.com/clipperhouse/uax29/v2 v2.7.0 // indirect24- github.com/mattn/go-runewidth v0.0.23 // indirect24+ github.com/mattn/go-runewidth v0.0.30 // indirect25 github.com/rivo/uniseg v0.4.7 // indirect26- github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect27- golang.org/x/sync v0.21.0 // indirect26+ github.com/xo/terminfo v1.0.0 // indirect27+ golang.org/x/sync v0.22.0 // indirect28 )modified:go.sum+14 added-14 removed
1 github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=2 github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=3 github.com/charmbracelet/colorprofile v0.4.3 h1:QPa1IWkYI+AOB+fE+mg/5/4HRMZcaXex9t5KX76i20Q=4 github.com/charmbracelet/colorprofile v0.4.3/go.mod h1:/zT4BhpD5aGFpqQQqw7a+VtHCzu+zrQtt1zhMt9mR4Q=5-github.com/charmbracelet/ultraviolet v0.0.0-20260703014108-f5a850f9c2b7 h1:3FmWoGNWK4STvqg0O0Aeav2T7rodWJAPeF0QpH+8gFw=6-github.com/charmbracelet/ultraviolet v0.0.0-20260703014108-f5a850f9c2b7/go.mod h1:f/jRa757WUmaOZrbPspXymbg/GnbF+rwe4OLsG7aXYo=7-github.com/charmbracelet/x/ansi v0.11.7 h1:kzv1kJvjg2S3r9KHo8hDdHFQLEqn4RBCb39dAYC84jI=8-github.com/charmbracelet/x/ansi v0.11.7/go.mod h1:9qGpnAVYz+8ACONkZBUWPtL7lulP9No6p1epAihUZwQ=5+github.com/charmbracelet/ultraviolet v0.0.0-20261008173134-6b8d4baf91b4 h1:hISLzUbwcvJbGoNR6A3L/TpguRRnACBmZOee8LcHLJw=6+github.com/charmbracelet/ultraviolet v0.0.0-20261008173134-6b8d4baf91b4/go.mod h1:aJDVk+WOVM1K04rdc/71PMPoUGfjxjhvXfP3Pjz1Zio=7+github.com/charmbracelet/x/ansi v0.11.9 h1:kIrqLBxtTVbLyyHO2Evoi93EjQo1mylWmpNEsfPxXAM=8+github.com/charmbracelet/x/ansi v0.11.9/go.mod h1:DG/hpOnaI2QJ/KMMqLL2h0KVhluuJLazf8973P+Vy5w=9 github.com/charmbracelet/x/exp/golden v0.0.0-20241212170349-ad4b7ae0f25f h1:UytXHv0UxnsDFmL/7Z9Q5SBYPwSuRLXHbwx+6LycZ2w=10 github.com/charmbracelet/x/exp/golden v0.0.0-20241212170349-ad4b7ae0f25f/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=11 github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=12 github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI=4 unmodified lines17 github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSEFgwIwO+UVM8=18 github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0=19 github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk=20 github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=21-github.com/lucasb-eyer/go-colorful v1.4.0 h1:UtrWVfLdarDgc44HcS7pYloGHJUjHV/4FwW4TvVgFr4=22-github.com/lucasb-eyer/go-colorful v1.4.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=23-github.com/mattn/go-runewidth v0.0.23 h1:7ykA0T0jkPpzSvMS5i9uoNn2Xy3R383f9HDx3RybWcw=24-github.com/mattn/go-runewidth v0.0.23/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=21+github.com/lucasb-eyer/go-colorful v1.4.1 h1:1EO+WB73+EH8EVbzlrG3KLAfEypQWVHIBqlTf+2hNss=22+github.com/lucasb-eyer/go-colorful v1.4.1/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=23+github.com/mattn/go-runewidth v0.0.30 h1:+KUuiDA4fF0R1p5FeueHefjDm+GIM+kWfFnDjybOPgk=24+github.com/mattn/go-runewidth v0.0.30/go.mod h1:3qAiGCV4Koz/yuveO58qUefmUTRm8r0IGEXZ9jeHp/8=25 github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=26 github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=27 github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=28 github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=29-github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=30-github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=29+github.com/xo/terminfo v1.0.0 h1:2ZpYzqWzyyytjk3TP6aJVDhkMAkc99/1xKQdA3TDTBY=30+github.com/xo/terminfo v1.0.0/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=31 golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=32 golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=33-golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=34-golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=35-golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=36-golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=33+golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=34+golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=35+golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=36+golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=modified:input.go+2 added
47 unmodified lines48 case uv.KeyboardEnhancementsEvent:49 return KeyboardEnhancementsMsg(e)50 case uv.ModeReportEvent:51 return ModeReportMsg(e)52+ case uv.ProgramStatusSupportEvent:53+ return ProgramStatusSupportMsg{}54 }55 return e56 }added:programstatus_test.go+88 added
1+package tea2+3+import (4+ "bytes"5+ "strings"6+ "testing"7+8+ uv "github.com/charmbracelet/ultraviolet"9+ "github.com/charmbracelet/x/ansi"10+)11+12+func TestCursedRenderer_programStatus(t *testing.T) {13+ t.Parallel()14+15+ var out bytes.Buffer16+ r := newCursedRenderer(&out, []string{"TERM=xterm-256color"}, 80, 24)17+ r.start()18+19+ step := func(name string, ps *ProgramStatus) string {20+ t.Helper()21+ out.Reset()22+ v := NewView("hello")23+ v.ProgramStatus = ps24+ r.render(v)25+ if err := r.flush(false); err != nil {26+ t.Fatalf("%s: %v", name, err)27+ }28+ return out.String()29+ }30+31+ working := &ProgramStatus{State: ProgramStateWorking, App: "tea", Message: "Building"}32+ if got := step("first", working); !strings.Contains(got, ansi.SetProgramStatus(*working)) {33+ t.Fatalf("first frame: missing report in %q", got)34+ }35+36+ same := *working37+ if got := step("unchanged", &same); strings.Contains(got, "7501") {38+ t.Fatalf("unchanged status was written again: %q", got)39+ }40+41+ changed := same42+ changed.Message = "Linking"43+ if got := step("changed", &changed); !strings.Contains(got, ansi.SetProgramStatus(changed)) {44+ t.Fatalf("changed status not written: %q", got)45+ }46+47+ child := &ProgramStatus{State: ProgramStateBlocked, ID: "job", Kind: ProgramStatusKindQuestion}48+ got := step("id change", child)49+ if strings.Contains(got, ansi.ClearProgramStatusID("job")) {50+ t.Fatalf("new record should not be cleared: %q", got)51+ }52+ assertInOrder(t, got, ansi.ClearProgramStatus, ansi.SetProgramStatus(*child))53+54+ if got := step("removed", nil); !strings.Contains(got, ansi.ClearProgramStatusID("job")) {55+ t.Fatalf("removed status not cleared: %q", got)56+ }57+58+ if got := step("invalid", &ProgramStatus{State: ProgramStateIdle, ID: "bad id"}); strings.Contains(got, "7501") {59+ t.Fatalf("invalid status was written: %q", got)60+ }61+62+ done := &ProgramStatus{State: ProgramStateDone, App: "tea"}63+ step("done", done)64+ out.Reset()65+ if err := r.close(); err != nil {66+ t.Fatal(err)67+ }68+ if got := out.String(); strings.Contains(got, "7501") {69+ t.Fatalf("close should leave the status in place, got %q", got)70+ }71+72+ // Resuming re-sends the last status.73+ out.Reset()74+ r.start()75+ if err := r.flush(false); err != nil {76+ t.Fatal(err)77+ }78+ if got := out.String(); !strings.Contains(got, ansi.SetProgramStatus(*done)) {79+ t.Fatalf("restart did not restore the status: %q", got)80+ }81+}82+83+func TestTranslateProgramStatusSupport(t *testing.T) {84+ var p Program85+ if got := p.translateInputEvent(uv.ProgramStatusSupportEvent{}); got != (ProgramStatusSupportMsg{}) {86+ t.Fatalf("got %T, want ProgramStatusSupportMsg", got)87+ }88+}added:programstatus.go+55 added
1+package tea2+3+import uv "github.com/charmbracelet/ultraviolet"4+5+// ProgramStatus is a Program Status Protocol (OSC 7501) report. It tells the6+// terminal whether the program is idle, working, waiting on the user, done,7+// or failed, and why. Set it on [View.ProgramStatus].8+//9+// Support depends on the terminal. Terminals that don't support it ignore it.10+//11+// See: https://www.superlogical.com/rex/docs/build/program-status12+type ProgramStatus = uv.ProgramStatus13+14+// ProgramState is the state of a [ProgramStatus].15+type ProgramState = uv.ProgramState16+17+// ProgramStatusKind says what a blocked program waits for.18+type ProgramStatusKind = uv.ProgramStatusKind19+20+// Program states.21+const (22+ ProgramStateIdle = uv.ProgramStateIdle23+ ProgramStateWorking = uv.ProgramStateWorking24+ ProgramStateDone = uv.ProgramStateDone25+ ProgramStateBlocked = uv.ProgramStateBlocked26+ ProgramStateError = uv.ProgramStateError27+ ProgramStateClear = uv.ProgramStateClear28+)29+30+// Program status kinds.31+const (32+ ProgramStatusKindPermission = uv.ProgramStatusKindPermission33+ ProgramStatusKindQuestion = uv.ProgramStatusKindQuestion34+ ProgramStatusKindAuth = uv.ProgramStatusKindAuth35+)36+37+// ProgramStatusSupportMsg is sent when the terminal replies to38+// [RequestProgramStatusSupport], meaning it supports the Program Status39+// Protocol.40+type ProgramStatusSupportMsg struct{}41+42+// programStatusSupportMsg is an internal message that queries the terminal43+// for Program Status Protocol support.44+type programStatusSupportMsg struct{}45+46+// RequestProgramStatusSupport is a command that asks the terminal whether it47+// supports the Program Status Protocol (OSC 7501). A supporting terminal48+// replies with a [ProgramStatusSupportMsg]. Terminals that don't support it49+// never reply, so pick your own timeout. Use [WithInput] to enable input,50+// since the reply cannot be read otherwise.51+//52+// Detection is optional: reports can be sent without it.53+func RequestProgramStatusSupport() Msg {54+ return programStatusSupportMsg{}55+}modified:tea.go+17 added
144 unmodified lines145 // ProgressBar when not nil, shows a progress bar in the terminal's146 // progress bar section. Support depends on the terminal.147 ProgressBar *ProgressBar148 149+ // ProgramStatus when not nil, reports the program status to the terminal150+ // using the Program Status Protocol (OSC 7501): whether the program is151+ // idle, working, waiting on the user, done, or failed. Support depends on152+ // the terminal.153+ //154+ // The status usually addresses the root record (empty ID). Changing it155+ // sends a new report, and setting it back to nil clears the record.156+ //157+ // The status is not cleared when the program exits, so done and error158+ // reports stay visible to the user. Report [ProgramStateDone],159+ // [ProgramStateError], or [ProgramStateIdle] before quitting rather than160+ // leaving a working or blocked status behind.161+ ProgramStatus *ProgramStatus162+163 // AltScreen puts the program in the alternate screen buffer164 // (i.e. the program goes into full window mode). Note that the altscreen will165 // be automatically exited when the program quits.166 //684 unmodified lines851 852 case cursorColorMsg:853 p.executeQuery(ansi.RequestCursorColor)854 855+ case programStatusSupportMsg:856+ p.executeQuery(ansi.RequestProgramStatusSupport)857+858 case execMsg:859 // NB: this blocks.860 p.exec(msg.cmd, msg.fn)861 622 unmodified linesmodified:UPGRADE_GUIDE_V2.md+1 added
96 unmodified lines97 | `Cursor` | Control cursor position, shape, color, and blink |98 | `ForegroundColor` | Set the terminal foreground color |99 | `BackgroundColor` | Set the terminal background color |100 | `ProgressBar` | Show a native terminal progress bar |101+| `ProgramStatus` | Report whether the program is working, waiting on the user, done, or failed (OSC 7501) |102 | `KeyboardEnhancements` | Request keyboard enhancement features |103 | `OnMouse` | Intercept mouse messages based on view content |104 105 ## Key Messages469 unmodified lines