fork/gdu
git clone https://git.julia.blue/fork/gdu
34f3996
master
1package tui 2 3import ( 4"fmt" 5"io" 6"os" 7"os/signal" 8"runtime" 9"strings" 10"sync" 11"sync/atomic" 12"syscall" 13"time" 14"unicode" 15 16 log"github.com/sirupsen/logrus" 17 18"github.com/dundee/gdu/v5/internal/common" 19"github.com/dundee/gdu/v5/pkg/analyze" 20"github.com/dundee/gdu/v5/pkg/device" 21"github.com/dundee/gdu/v5/pkg/fs" 22"github.com/dundee/gdu/v5/pkg/remove" 23"github.com/dundee/gdu/v5/pkg/timefilter" 24"github.com/gdamore/tcell/v2" 25"github.com/rivo/tview" 26) 27 28// UI struct 29type UI struct { 30app common.TermApplication 31screen tcell.Screen 32output io.Writer 33currentDir fs.Item 34topDir fs.Item 35getter device.DevicesInfoGetter 36* common.UI 37grid * tview.Grid 38header * tview.TextView 39footer * tview.Flex 40footerLabel * tview.TextView 41currentDirLabel * tview.TextView 42pages * tview.Pages 43progress * tview.TextView 44progressBar * ProgressBar 45status * tview.TextView 46help * tview.Flex 47table * tview.Table 48filteringInput * tview.InputField 49typeFilteringInput * tview.InputField 50done chan struct {} 51remover func (fs.Item , fs.Item )error 52emptier func (fs.Item , fs.Item )error 53trasher func (fs.Item , fs.Item )error 54exec func (argv0 string ,argv []string ,envv []string )error 55changeCwdFn func (string )error 56linkedItems fs.HardLinkedItems 57ignoredRows map [int ]struct {} 58markedRows map [int ]struct {} 59markedPaths []string 60deleteQueue chan deleteQueueItem 61resultRow ResultRow 62topDirPath string 63currentDirPath string 64filterValue string 65typeFilterValue string 66sortBy string 67sortOrder string 68footerTextColor string 69footerBackgroundColor string 70footerNumberColor string 71headerTextColor string 72headerBackgroundColor string 73defaultSortBy string 74defaultSortOrder string 75exportName string 76devices []* device.Device 77selectedTextColor tcell.Color 78selectedBackgroundColor tcell.Color 79markedTextColor tcell.Color 80markedBackgroundColor tcell.Color 81currentItemNameMaxLen int 82activeWorkers int 83deleteWorkersCount int 84statusMut sync.RWMutex 85workersMut sync.Mutex 86askBeforeDelete bool 87showItemCount bool 88showSymlinkTarget bool 89showMtime bool 90filtering bool 91typeFiltering bool 92headerHidden bool 93useOldSizeBar bool 94showBarPercentage bool 95showItemCountBar bool 96noDelete bool 97noViewFile bool 98noSpawnShell bool 99deleteInBackground bool 100timeFilter * timefilter.TimeFilter 101timeFilterLoc * time.Location 102noDeleteWithFilter bool 103collapsePath bool 104browseParentDirs bool 105showDiskProgressBar bool 106currentDeviceSize int64 107confirmQuit bool 108scanning bool 109scanCancelled bool 110// scanCancelRequested mirrors scanCancelled for readers outside the UI 111// goroutine. A multi-root scan resets the analyzer between roots, which 112// clears the analyzer's own cancelled flag, so the request has to survive 113// somewhere the scanning goroutine can safely read it. 114scanCancelRequested atomic.Bool 115scanStart time.Time 116scanDuration time.Duration 117previewing bool 118previewSavedDir fs.Item 119progressFlex * tview.Flex 120} 121 122type deleteQueueItem struct { 123item fs.Item 124action DeleteAction 125} 126 127// ResultRow is a struct for a row in the result table 128type ResultRow struct { 129NumberColor string 130DirectoryColor string 131} 132 133// Option is optional function customizing the behaviour of UI 134type Option func (ui * UI ) 135 136// CreateUI creates the whole UI app 137func CreateUI ( 138app common.TermApplication , 139screen tcell.Screen , 140output io.Writer , 141useColors bool , 142showApparentSize bool , 143showRelativeSize bool , 144useSIPrefix bool , 145opts ... Option , 146)* UI { 147ui := & UI { 148UI :& common.UI { 149UseColors :useColors , 150ShowApparentSize :showApparentSize , 151ShowRelativeSize :showRelativeSize , 152Analyzer :analyze .CreateAnalyzer (), 153UseSIPrefix :useSIPrefix , 154 }, 155app :app , 156screen :screen , 157output :output , 158askBeforeDelete :true , 159confirmQuit :true , 160showItemCount :false , 161remover :remove .ItemFromDir , 162emptier :remove .EmptyFileFromDir , 163trasher :remove .MoveItemToTrash , 164exec :Execute , 165linkedItems :make (fs.HardLinkedItems ,10 ), 166selectedTextColor :tview .Styles .TitleColor , 167selectedBackgroundColor :tview .Styles .MoreContrastBackgroundColor , 168markedTextColor :tview .Styles .PrimaryTextColor , 169markedBackgroundColor :tview .Styles .ContrastBackgroundColor , 170currentItemNameMaxLen :70 , 171defaultSortBy :"size" , 172defaultSortOrder :"desc" , 173ignoredRows :make (map [int ]struct {}), 174markedRows :make (map [int ]struct {}), 175exportName :"export.json" , 176noDelete :false , 177noViewFile :false , 178noSpawnShell :false , 179deleteQueue :make (chan deleteQueueItem ,1000 ), 180deleteWorkersCount :3 * runtime .GOMAXPROCS (0 ), 181 } 182if ! useSIPrefix { 183ui .SetBlockSizeFromEnvironment () 184 } 185for _ ,o := range opts { 186o (ui ) 187 } 188 189ui .resetSorting () 190 191app .SetBeforeDrawFunc (func (screen tcell.Screen )bool { 192screen .Clear () 193return false 194 }) 195 196ui .app .SetInputCapture (ui .keyPressed ) 197ui .app .SetMouseCapture (ui .onMouse ) 198 199ui .header = tview .NewTextView () 200ui .header .SetText (" gdu ~ Use arrow keys to navigate, press ? for help " ) 201ui .header .SetTextColor (tcell .GetColor (ui .headerTextColor )) 202ui .header .SetBackgroundColor (tcell .GetColor (ui .headerBackgroundColor )) 203 204ui .currentDirLabel = tview .NewTextView () 205ui .currentDirLabel .SetTextColor (tcell .ColorDefault ) 206ui .currentDirLabel .SetBackgroundColor (tcell .ColorDefault ) 207 208ui .table = tview .NewTable ().SetSelectable (true ,false ) 209ui .table .SetBackgroundColor (tcell .ColorDefault ) 210ui .table .SetSelectedFunc (ui .fileItemSelected ) 211 212if ui .UseColors { 213ui .table .SetSelectedStyle (tcell.Style {}. 214Foreground (ui .selectedTextColor ). 215Background (ui .selectedBackgroundColor ).Bold (true )) 216 }else { 217ui .table .SetSelectedStyle (tcell.Style {}. 218Foreground (tcell .ColorWhite ). 219Background (tcell .ColorGray ).Bold (true )) 220 } 221 222ui .footerLabel = tview .NewTextView ().SetDynamicColors (true ) 223ui .footerLabel .SetTextColor (tcell .GetColor (ui .footerTextColor )) 224ui .footerLabel .SetBackgroundColor (tcell .GetColor (ui .footerBackgroundColor )) 225ui .footerLabel .SetText (" No items to display. " ) 226 227ui .footer = tview .NewFlex () 228ui .footer .AddItem (ui .footerLabel ,0 ,1 ,false ) 229 230ui .createGrid () 231 232ui .pages = tview .NewPages (). 233AddPage ("background" ,ui .grid ,true ,true ) 234ui .pages .SetBackgroundColor (tcell .ColorDefault ) 235 236ui .app .SetRoot (ui .pages ,true ) 237 238return ui 239} 240 241// createGrid creates the main grid layout 242func (ui * UI )createGrid () { 243if ui .headerHidden { 244ui .grid = tview .NewGrid ().SetRows (1 ,0 ,1 ).SetColumns (0 ) 245ui .grid .AddItem (ui .currentDirLabel ,0 ,0 ,1 ,1 ,0 ,0 ,false ). 246AddItem (ui .table ,1 ,0 ,1 ,1 ,0 ,0 ,true ). 247AddItem (ui .footer ,2 ,0 ,1 ,1 ,0 ,0 ,false ) 248 }else { 249ui .grid = tview .NewGrid ().SetRows (1 ,1 ,0 ,1 ).SetColumns (0 ) 250ui .grid .AddItem (ui .header ,0 ,0 ,1 ,1 ,0 ,0 ,false ). 251AddItem (ui .currentDirLabel ,1 ,0 ,1 ,1 ,0 ,0 ,false ). 252AddItem (ui .table ,2 ,0 ,1 ,1 ,0 ,0 ,true ). 253AddItem (ui .footer ,3 ,0 ,1 ,1 ,0 ,0 ,false ) 254 } 255} 256 257// SetSelectedTextColor sets the color for the highlighted selected text 258func (ui * UI )SetSelectedTextColor (color tcell.Color ) { 259ui .selectedTextColor = color 260} 261 262// SetSelectedBackgroundColor sets the color for the highlighted selected text 263func (ui * UI )SetSelectedBackgroundColor (color tcell.Color ) { 264ui .selectedBackgroundColor = color 265} 266 267// SetMarkedTextColor sets the text color for marked items 268func (ui * UI )SetMarkedTextColor (color tcell.Color ) { 269ui .markedTextColor = color 270} 271 272// SetMarkedBackgroundColor sets the background color for marked items 273func (ui * UI )SetMarkedBackgroundColor (color tcell.Color ) { 274ui .markedBackgroundColor = color 275} 276 277// SetFooterTextColor sets the color for the footer text 278func (ui * UI )SetFooterTextColor (color string ) { 279ui .footerTextColor = color 280} 281 282// SetFooterBackgroundColor sets the color for the footer background 283func (ui * UI )SetFooterBackgroundColor (color string ) { 284ui .footerBackgroundColor = color 285} 286 287// SetFooterNumberColor sets the color for the footer number 288func (ui * UI )SetFooterNumberColor (color string ) { 289ui .footerNumberColor = color 290} 291 292// SetHeaderTextColor sets the color for the header text 293func (ui * UI )SetHeaderTextColor (color string ) { 294ui .headerTextColor = color 295} 296 297// SetHeaderBackgroundColor sets the color for the header background 298func (ui * UI )SetHeaderBackgroundColor (color string ) { 299ui .headerBackgroundColor = color 300} 301 302// SetHeaderHidden sets the flag to hide the header 303func (ui * UI )SetHeaderHidden () { 304ui .headerHidden = true 305} 306 307// SetResultRowDirectoryColor sets the color for the result row directory 308func (ui * UI )SetResultRowDirectoryColor (color string ) { 309ui .resultRow .DirectoryColor = color 310} 311 312// SetResultRowNumberColor sets the color for the result row number 313func (ui * UI )SetResultRowNumberColor (color string ) { 314ui .resultRow .NumberColor = color 315} 316 317// SetCurrentItemNameMaxLen sets the maximum length of the path of the currently processed item 318// to be shown in the progress modal 319func (ui * UI )SetCurrentItemNameMaxLen (maxLen int ) { 320ui .currentItemNameMaxLen = maxLen 321} 322 323// UseOldSizeBar uses the old size bar (# chars) instead of the new one (unicode block elements) 324func (ui * UI )UseOldSizeBar () { 325ui .useOldSizeBar = true 326} 327 328// SetShowBarPercentage shows the numeric usage percentage next to the size bar 329func (ui * UI )SetShowBarPercentage () { 330ui .showBarPercentage = true 331} 332 333// SetShowItemCountBar shows a bar next to the item count column, drawn in 334// proportion to the item counts of the sibling items. It only takes effect 335// while the item count column itself is visible (the "c" key). 336func (ui * UI )SetShowItemCountBar () { 337ui .showItemCountBar = true 338} 339 340// SetChangeCwdFn sets function that can be used to change current working dir 341// during dir browsing 342func (ui * UI )SetChangeCwdFn (fn func (string )error ) { 343ui .changeCwdFn = fn 344} 345 346// SetDeleteInParallel sets the flag to delete files in parallel 347func (ui * UI )SetDeleteInParallel () { 348ui .remover = remove .ItemFromDirParallel 349} 350 351// SetTrashCommand replaces the built-in trash with an external command 352func (ui * UI )SetTrashCommand (command string ) { 353ui .trasher = remove .TrashCommand (command ) 354} 355 356// StartUILoop starts tview application 357func (ui * UI )StartUILoop ()error { 358signals := make (chan os.Signal ,1 ) 359signal .Notify ( 360signals , 361syscall .SIGHUP , 362syscall .SIGINT , 363syscall .SIGQUIT , 364syscall .SIGILL , 365syscall .SIGTRAP , 366syscall .SIGABRT , 367syscall .SIGPIPE , 368syscall .SIGTERM , 369 ) 370defer signal .Stop (signals ) 371 372return ui .runUILoop (signals ) 373} 374 375func (ui * UI )runUILoop (signals <- chan os.Signal )error { 376stopSignals := make (chan struct {}) 377signalsDone := make (chan struct {}) 378go func () { 379defer close (signalsDone ) 380ui .handleSignals (signals ,stopSignals ) 381 }() 382 383err := ui .app .Run () 384close (stopSignals ) 385<- signalsDone 386return err 387} 388 389func (ui * UI )handleSignals (signals <- chan os.Signal ,stop <- chan struct {}) { 390for { 391select { 392case <- stop : 393return 394case current ,ok := <- signals : 395if ! ok { 396return 397 } 398log .Printf ("Got signal: %s" ,current ) 399ui .postSignalEvent (signalEvent (current ),stop ) 400 } 401 } 402} 403 404func (ui * UI )postSignalEvent (event * tcell.EventKey ,stop <- chan struct {}) { 405if err := ui .screen .PostEvent (event );err == nil { 406return 407 } 408 409retry := time .NewTicker (time .Millisecond ) 410defer retry .Stop () 411for { 412select { 413case <- stop : 414return 415case <- retry .C : 416if err := ui .screen .PostEvent (event );err == nil { 417return 418 } 419 } 420 } 421} 422 423func signalEvent (current os.Signal )* tcell.EventKey { 424modifiers := tcell .ModNone 425if current == syscall .SIGINT { 426modifiers = tcell .ModCtrl 427 } 428return tcell .NewEventKey (tcell .KeyExit ,0 ,modifiers ) 429} 430 431func (ui * UI )handleSignalEvent (event * tcell.EventKey ) { 432if event .Modifiers ()== tcell .ModCtrl && (ui .cancelScan ()|| ui .scanning ) { 433return 434 } 435ui .printMarkedPaths () 436ui .app .Stop () 437} 438 439func (ui * UI )cancelScan ()bool { 440if ! ui .scanning || ui .scanCancelled { 441return false 442 } 443 444ui .Analyzer .Cancel () 445ui .scanCancelled = true 446ui .scanCancelRequested .Store (true ) 447ui .progress .SetTitle (" Stopping scan... " ) 448ui .progress .SetText ("Stopping scan and keeping results..." ) 449return true 450} 451 452// SetConfirmQuit sets whether gdu asks for confirmation before quitting 453// after a scan that took a noticeable amount of time 454func (ui * UI )SetConfirmQuit (value bool ) { 455ui .confirmQuit = value 456} 457 458// SetShowItemCount sets the flag to show number of items in directory 459func (ui * UI )SetShowItemCount () { 460ui .showItemCount = true 461} 462 463// SetShowMTime sets the flag to show last modification time of items in directory 464func (ui * UI )SetShowMTime () { 465ui .showMtime = true 466} 467 468// SetShowSymlinkTarget enables displaying the symlink target (name -> target) 469func (ui * UI )SetShowSymlinkTarget (value bool ) { 470ui .showSymlinkTarget = value 471} 472 473// SetNoDelete disables all write operations 474func (ui * UI )SetNoDelete () { 475ui .noDelete = true 476} 477 478// SetNoSpawnShell disables shell spawning 479func (ui * UI )SetNoSpawnShell () { 480ui .noSpawnShell = true 481} 482 483func (ui * UI )SetNoViewFile () { 484ui .noViewFile = true 485} 486 487// SetNoDelete disables delete when time filters are active 488func (ui * UI )SetNoDeleteWithFilter () { 489ui .noDeleteWithFilter = true 490} 491 492// SetBrowseParentDirs enables navigating above the launch directory 493func (ui * UI )SetBrowseParentDirs () { 494ui .browseParentDirs = true 495} 496 497// SetCollapsePath sets the flag to collapse paths 498func (ui * UI )SetCollapsePath (value bool ) { 499ui .collapsePath = value 500} 501 502// SetShowDiskProgressBar sets whether to show a progress bar when scanning a whole disk 503func (ui * UI )SetShowDiskProgressBar (value bool ) { 504ui .showDiskProgressBar = value 505} 506 507// SetDeleteInBackground sets the flag to delete files in background 508func (ui * UI )SetDeleteInBackground () { 509ui .deleteInBackground = true 510 511for i := 0 ;i < ui .deleteWorkersCount ;i ++ { 512go ui .deleteWorker () 513 } 514go ui .updateStatusWorker () 515} 516 517func (ui * UI )resetSorting () { 518ui .sortBy = ui .defaultSortBy 519ui .sortOrder = ui .defaultSortOrder 520} 521 522// atVirtualRoot reports whether the view is at the synthetic dir grouping 523// several scanned roots. That dir has no path on disk, so operations that 524// resolve currentDirPath back to the filesystem must not run there. 525func (ui * UI )atVirtualRoot ()bool { 526return analyze .IsVirtualRootDir (ui .currentDir ) 527} 528 529func (ui * UI )rescanDir () { 530ui .linkedItems = make (fs.HardLinkedItems ) 531 532// at the virtual root there is nothing to rescan but the roots below it 533if ui .atVirtualRoot () { 534if err := ui .AnalyzePaths (ui .scannedRootPaths ());err != nil { 535ui .showErr ("Error rescanning paths" ,err ) 536 } 537return 538 } 539 540err := ui .AnalyzePath (ui .currentDirPath ,ui .currentDir .GetParent ()) 541if err != nil { 542ui .showErr ("Error rescanning path" ,err ) 543 } 544} 545 546// scannedRootPaths returns the paths of the roots grouped under the virtual root. 547func (ui * UI )scannedRootPaths () []string { 548paths := make ([]string ,0 ) 549for item := range ui .currentDir .GetFiles (fs .SortByName ,fs .SortAsc ) { 550paths = append (paths ,item .GetPath ()) 551 } 552return paths 553} 554 555func (ui * UI )fileItemSelected (row ,column int ) { 556if ui .currentDir == nil { 557return // Add this check to handle nil case 558 } 559 560selectedDirCell := ui .table .GetCell (row ,column ) 561 562// Check if the selectedDirCell is nil before using it 563if selectedDirCell == nil || selectedDirCell .GetReference ()== nil { 564return 565 } 566 567selectedDir := selectedDirCell .GetReference ().(fs.Item ) 568if selectedDir == nil || ! selectedDir .IsDir () { 569return 570 } 571 572origDir := ui .currentDir 573ui .currentDir = selectedDir 574ui .hideFilterInput () 575ui .hideTypeFilterInput () 576ui .markedRows = make (map [int ]struct {}) 577ui .ignoredRows = make (map [int ]struct {}) 578ui .showDir () 579 580// while previewing a mid-scan snapshot there is no stable top dir to anchor 581// the "select last visited" logic to, so just render the navigated dir 582if ui .previewing { 583return 584 } 585 586if row != 0 || origDir .GetPath ()== ui .topDir .GetPath () { 587return 588 } 589 590// we are going up in the directory tree, select the last visited directory 591if origDir .GetParent ()!= nil { 592nestedDir := origDir 593for nestedDir .GetParent ()!= nil { 594if selectedDir .GetName ()== nestedDir .GetParent ().GetName () { 595sortBy ,sortOrder := ui .getSortParams () 596index := - 1 597i := 0 598for item := range ui .currentDir .GetFiles (sortBy ,sortOrder ) { 599if item .GetName ()== nestedDir .GetName () { 600index = i 601break 602 } 603i ++ 604 } 605if index >= 0 { 606if ui .currentDir .GetPath ()!= ui .topDir .GetPath () { 607index ++ 608 } 609ui .table .Select (index ,0 ) 610 } 611break 612 } 613nestedDir = nestedDir .GetParent () 614 } 615 } 616} 617 618func (ui * UI )deviceItemSelected (row ,column int ) { 619var err error 620selectedDevice ,ok := ui .table .GetCell (row ,column ).GetReference ().(* device.Device ) 621if ! ok { 622return 623 } 624 625paths := device .GetNestedMountpointsPaths (selectedDevice .MountPoint ,ui .devices ) 626ui .IgnoreDirPathPatterns ,err = common .CreateIgnorePattern (paths ) 627if err != nil { 628log .Printf ("Creating path patterns for other devices failed: %s" ,paths ) 629 } 630 631ui .resetSorting () 632 633ui .currentDeviceSize = selectedDevice .Size 634ui .Analyzer .ResetProgress () 635ui .linkedItems = make (fs.HardLinkedItems ) 636err = ui .AnalyzePath (selectedDevice .MountPoint ,nil ) 637if err != nil { 638ui .showErr ("Error analyzing device" ,err ) 639 } 640} 641 642func (ui * UI )confirmDeletion (action DeleteAction ) { 643if ui .noDelete { 644ui .showMessage (" Deletion is disabled!" ) 645return 646 } 647 648// Check if deletion is allowed with active time filters 649if ui .noDeleteWithFilter { 650modal := tview .NewModal (). 651SetText ("Deletion is disabled when a time filter is active.\n\n" + 652"To override, set GDU_ALLOW_DELETE_WITH_FILTER=1" ). 653AddButtons ([]string {"OK" }). 654SetDoneFunc (func (buttonIndex int ,buttonLabel string ) { 655ui .pages .RemovePage ("confirm" ) 656 }) 657if ! ui .UseColors { 658modal .SetBackgroundColor (tcell .ColorGray ) 659 } 660ui .pages .AddPage ("confirm" ,modal ,true ,true ) 661return 662 } 663 664if len (ui .markedRows )> 0 { 665ui .confirmDeletionMarked (action ) 666 }else { 667ui .confirmDeletionSelected (action ) 668 } 669} 670 671func (ui * UI )confirmDeletionSelected (action DeleteAction ) { 672row ,column := ui .table .GetSelection () 673selectedFile := ui .table .GetCell (row ,column ).GetReference ().(fs.Item ) 674modal := tview .NewModal (). 675SetText ( 676"Are you sure you want to " + 677action .Verb ()+ 678" \"" + 679tview .Escape (selectedFile .GetName ())+ 680"\"?" , 681 ). 682AddButtons ([]string {No ,Yes ,DontAskAgain }). 683SetDoneFunc (func (buttonIndex int ,buttonLabel string ) { 684switch buttonIndex { 685case 2 : 686ui .askBeforeDelete = false 687fallthrough 688case 1 : 689ui .deleteSelected (action ) 690 } 691ui .pages .RemovePage ("confirm" ) 692 }) 693 694if ! ui .UseColors { 695modal .SetBackgroundColor (tcell .ColorGray ) 696 }else { 697modal .SetBackgroundColor (tcell .ColorBlack ) 698 } 699modal .SetBorderColor (tcell .ColorDefault ) 700 701ui .pages .AddPage ("confirm" ,modal ,true ,true ) 702} 703 704// SetTimeFilterWithInfo sets both the time filter function and stores the filter info for display 705func (ui * UI )SetTimeFilterWithInfo (tf * timefilter.TimeFilter ,loc * time.Location ) { 706ui .timeFilter = tf 707ui .timeFilterLoc = loc 708 709if tf != nil && ! tf .IsEmpty () { 710timeFilterFunc := func (mtime time.Time )bool { 711return tf .IncludeByTimeFilter (mtime ,loc ) 712 } 713ui .SetTimeFilter (timeFilterFunc ) 714if ! ui .isDeleteAllowedWithFilter () { 715ui .SetNoDeleteWithFilter () 716 } 717 } 718} 719 720// hasActiveTimeFilter returns true if any time filter is active 721func (ui * UI )hasActiveTimeFilter ()bool { 722return ui .timeFilter != nil && ! ui .timeFilter .IsEmpty () 723} 724 725// formatTimeFilterInfo formats the time filter information for display 726func (ui * UI )formatTimeFilterInfo ()string { 727if ! ui .hasActiveTimeFilter () { 728return "" 729 } 730 731return ui .timeFilter .FormatForDisplay (ui .timeFilterLoc ) 732} 733 734// isDeleteAllowedWithFilter checks if deletion is allowed when filters are active 735func (ui * UI )isDeleteAllowedWithFilter ()bool { 736if ! ui .hasActiveTimeFilter () { 737return true 738 } 739 740// Check environment variable override 741if os .Getenv ("GDU_ALLOW_DELETE_WITH_FILTER" )== "1" { 742return true 743 } 744 745return false 746} 747 748// sanitizePathForDisplay replaces control characters (which can include 749// terminal escape sequences) with the Unicode replacement character. A 750// scanned directory entry's name has no character restrictions, and these 751// paths are printed to the real terminal after the tview screen has 752// stopped, bypassing tview's own protective rendering entirely. 753func sanitizePathForDisplay (s string )string { 754return strings .Map (func (r rune )rune { 755if unicode .IsControl (r ) { 756return '�' 757 } 758return r 759 },s ) 760} 761 762// printMarkedPaths prints the paths of the marked items to the output 763func (ui * UI )printMarkedPaths () { 764for _ ,path := range ui .markedPaths { 765fmt .Fprintf (ui .output ,"%s\n" ,sanitizePathForDisplay (path )) 766 } 767}