fork/gdu

git clone https://git.julia.blue/fork/gdu

Julia RyanRestore cursor pos on rescan98ee348

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