Report OSC 9;4 progress when building

As supported by the Ghostty terminal and others.
This commit is contained in:
Bjørn Erik Pedersen
2025-09-30 11:43:26 +02:00
parent 4d2743e4c8
commit ec463c0977
8 changed files with 155 additions and 3 deletions
+25
View File
@@ -16,6 +16,7 @@ package terminal
import (
"fmt"
"io"
"os"
"strings"
@@ -72,3 +73,27 @@ func doublePercent(str string) string {
func singlePercent(str string) string {
return strings.Replace(str, "%%", "%", -1)
}
type ProgressState int
const (
ProgressHidden ProgressState = iota
ProgressNormal
ProgressError
ProgressIntermediate
ProgressWarning
)
// ReportProgress writes OSC 9;4 sequence to w.
func ReportProgress(w io.Writer, state ProgressState, progress float64) {
if progress < 0 {
progress = 0.0
}
if progress > 1 {
progress = 1.0
}
pi := int(progress * 100)
fmt.Fprintf(w, "\033]9;4;%d;%d\007", state, pi)
}