fork/gdu
git clone https://git.julia.blue/fork/gdu
99a7f2a
master
1package tui 2 3import ( 4"fmt" 5"os" 6"time" 7 8"github.com/dundee/gdu/v5/internal/common" 9) 10 11func (ui * UI )updateProgress (analyzer common.Analyzer ,doneChan common.SignalGroup ) { 12color := "[white:black:b]" 13if ui .UseColors { 14color = "[red:black:b]" 15 } 16 17deviceSize := ui .currentDeviceSize 18showBar := ui .showDiskProgressBar 19 20start := time .Now () 21ticker := time .NewTicker (100 * time .Millisecond ) 22defer ticker .Stop () 23 24for { 25select { 26case <- doneChan : 27if deviceSize > 0 && showBar { 28clearTerminalProgress () 29ui .currentDeviceSize = 0 30 } 31ui .app .QueueUpdateDraw (func () { 32ui .progress .SetTitle (" Finalizing... " ) 33ui .progress .SetText ("Calculating disk usage..." ) 34 }) 35return 36case <- ticker .C : 37 } 38 39progress := analyzer .GetProgress () 40 41func (itemCount int64 ,totalUsage int64 ) { 42delta := time .Since (start ).Round (time .Second ) 43 44if deviceSize > 0 && showBar { 45percent := int (totalUsage * 100 / deviceSize ) 46writeTerminalProgress (percent ) 47if ui .progressBar != nil { 48ui .progressBar .SetProgress (percent ) 49 } 50 } 51 52ui .app .QueueUpdateDraw (func () { 53ui .progress .SetText ("Total items: " + 54color + 55common .FormatNumber (int64 (itemCount ))+ 56"[white:black:-], size: " + 57color + 58ui .formatSize (totalUsage ,false ,false )+ 59"[white:black:-], elapsed time: " + 60color + 61delta .String ()+ 62"[white:black:-]\n\nPress Tab to preview results found so far\n" + 63"Press Ctrl+C to stop scanning and keep results" ) 64 }) 65 }(progress .ItemCount ,progress .TotalUsage ) 66 } 67} 68 69// writeTerminalProgress emits an OSC 9;4 sequence to update the terminal 70// tab/taskbar progress indicator. percent must be in the range [0, 100]. 71// This sequence is supported by Windows Terminal, ConEmu, and compatible 72// terminals. Writing to stderr ensures it reaches the terminal even when 73// the TUI has taken over stdout/stdin via tcell. 74func writeTerminalProgress (percent int ) { 75fmt .Fprintf (os .Stderr ,"\x1b]9;4;1;%d\x1b\\" ,percent ) 76} 77 78// clearTerminalProgress removes the terminal tab/taskbar progress indicator. 79func clearTerminalProgress () { 80fmt .Fprintf (os .Stderr ,"\x1b]9;4;0;0\x1b\\" ) 81}