@@ -49,6 +49,12 @@ func (pb *progressBar) Close(path string, err error) {
4949 pb .wg .Wait ()
5050
5151 p := pb .printer
52+
53+ // Clear native progress state.
54+ if core .IsStdoutTerm {
55+ emitProgress (0 , 0 , p )
56+ }
57+
5258 if err != nil {
5359 // An error will be printed after this.
5460 p .WriteString ("\n \n " )
@@ -102,6 +108,12 @@ func (pb *progressBar) render() {
102108 completedWidth := min (barWidth * percentage / 100 , barWidth )
103109
104110 p := pb .printer
111+
112+ // Render native progress bar.
113+ if core .IsStdoutTerm {
114+ emitProgress (1 , int (percentage ), p )
115+ }
116+
105117 p .WriteString ("\r " )
106118
107119 p .Set (core .Bold )
@@ -166,6 +178,12 @@ func (ps *progressSpinner) Close(path string, err error) {
166178 ps .wg .Wait ()
167179
168180 p := ps .printer
181+
182+ // Clear native progress state.
183+ if core .IsStdoutTerm {
184+ emitProgress (0 , 0 , p )
185+ }
186+
169187 if err != nil {
170188 p .WriteString ("\n \n " )
171189 } else {
@@ -186,6 +204,11 @@ func (ps *progressSpinner) Read(p []byte) (int, error) {
186204func (ps * progressSpinner ) renderLoop () {
187205 defer ps .wg .Done ()
188206
207+ // Render native progress bar.
208+ if core .IsStdoutTerm {
209+ emitProgress (3 , 0 , ps .printer )
210+ }
211+
189212 ticker := time .NewTicker (50 * time .Millisecond )
190213 defer ticker .Stop ()
191214 for {
@@ -334,3 +357,17 @@ func writeFinalProgress(p *core.Printer, bytesRead int64, dur time.Duration, toC
334357 p .WriteString ("\n " )
335358
336359}
360+
361+ func emitProgress (state , percent int , p * core.Printer ) {
362+ if percent < 0 {
363+ percent = 0
364+ } else if percent > 100 {
365+ percent = 100
366+ }
367+
368+ p .WriteString ("\x1b ]9;4;" )
369+ p .WriteString (strconv .Itoa (state ))
370+ p .WriteString (";" )
371+ p .WriteString (strconv .Itoa (percent ))
372+ p .WriteString ("\x1b \\ " )
373+ }
0 commit comments