feat(upgrade): add terminal progress indication

This commit is contained in:
Jan De Dobbeleer 2024-07-01 11:47:19 +02:00 committed by Jan De Dobbeleer
parent 7c7bd14a45
commit be8954867f
2 changed files with 25 additions and 0 deletions

View file

@ -7,6 +7,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/engine"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/terminal"
"github.com/jandedobbeleer/oh-my-posh/src/upgrade"
"github.com/spf13/cobra"
)
@ -37,6 +38,11 @@ var upgradeCmd = &cobra.Command{
env.Init()
defer env.Close()
terminal.Init(env.Shell())
fmt.Print(terminal.StartProgress())
defer fmt.Print(terminal.StopProgress())
if force {
upgrade.Run(env)
return

View file

@ -134,6 +134,9 @@ const (
hyperLinkText = "<TEXT>"
hyperLinkTextEnd = "</TEXT>"
startProgress = "\x1b]9;4;3;0\x07"
endProgress = "\x1b]9;4;0;0\x07"
WindowsTerminal = "Windows Terminal"
Warp = "WarpTerminal"
ITerm = "iTerm.app"
@ -360,6 +363,22 @@ func LineBreak() string {
return cr + lf
}
func StartProgress() string {
if Program != WindowsTerminal {
return ""
}
return fmt.Sprintf(formats.escape, startProgress)
}
func StopProgress() string {
if Program != WindowsTerminal {
return ""
}
return fmt.Sprintf(formats.escape, endProgress)
}
func Write(background, foreground, text string) {
if len(text) == 0 {
return