fork/gdu
git clone https://git.julia.blue/fork/gdu
755b20d
master
1package tui 2 3import ( 4"fmt" 5"time" 6 7"github.com/gdamore/tcell/v2" 8"github.com/rivo/tview" 9) 10 11func (ui * UI )toggleStatusBar (show bool ) { 12var textColor ,textBgColor tcell.Color 13if ui .UseColors { 14textColor = tcell .NewRGBColor (0 ,0 ,0 ) 15textBgColor = tcell .NewRGBColor (36 ,121 ,208 ) 16 }else { 17textColor = tcell .NewRGBColor (0 ,0 ,0 ) 18textBgColor = tcell .NewRGBColor (255 ,255 ,255 ) 19 } 20 21ui .grid .Clear () 22 23ui .statusMut .Lock () 24defer ui .statusMut .Unlock () 25 26if show { 27ui .status = tview .NewTextView ().SetDynamicColors (true ) 28ui .status .SetTextColor (textColor ) 29ui .status .SetBackgroundColor (textBgColor ) 30 31ui .grid .SetRows (1 ,1 ,0 ,1 ,1 ) 32ui .grid .AddItem (ui .header ,0 ,0 ,1 ,1 ,0 ,0 ,false ). 33AddItem (ui .currentDirLabel ,1 ,0 ,1 ,1 ,0 ,0 ,false ). 34AddItem (ui .table ,2 ,0 ,1 ,1 ,0 ,0 ,true ). 35AddItem (ui .status ,3 ,0 ,1 ,1 ,0 ,0 ,false ). 36AddItem (ui .footer ,4 ,0 ,1 ,1 ,0 ,0 ,false ) 37return 38 } 39ui .status = nil 40ui .grid .SetRows (1 ,1 ,0 ,1 ) 41ui .grid .AddItem (ui .header ,0 ,0 ,1 ,1 ,0 ,0 ,false ). 42AddItem (ui .currentDirLabel ,1 ,0 ,1 ,1 ,0 ,0 ,false ). 43AddItem (ui .table ,2 ,0 ,1 ,1 ,0 ,0 ,true ). 44AddItem (ui .footer ,3 ,0 ,1 ,1 ,0 ,0 ,false ) 45} 46 47func (ui * UI )updateStatusWorker () { 48for { 49ui .updateStatus () 50time .Sleep (500 * time .Millisecond ) 51 } 52} 53 54func (ui * UI )updateStatus () { 55ui .workersMut .Lock () 56cnt := ui .activeWorkers 57ui .workersMut .Unlock () 58 59ui .statusMut .RLock () 60status := ui .status 61ui .statusMut .RUnlock () 62 63if cnt == 0 && status == nil { 64return 65 } 66 67if cnt > 0 && status == nil { 68ui .app .QueueUpdateDraw (func () { 69ui .toggleStatusBar (true ) 70 }) 71 }else if cnt == 0 { 72ui .app .QueueUpdateDraw (func () { 73ui .toggleStatusBar (false ) 74 }) 75return 76 } 77 78ui .app .QueueUpdateDraw (func () { 79msg := fmt .Sprintf (" Active background deletions: %d" ,cnt ) 80ui .statusMut .RLock () 81ui .status .SetText (msg ) 82ui .statusMut .RUnlock () 83 }) 84}