1
mirror of https://github.com/rclone/rclone synced 2024-11-21 22:50:16 +01:00

cmd/ncdu: add keybinding to rescan filesystem

Fixes #7255
This commit is contained in:
eNV25 2023-08-29 19:32:40 +02:00 committed by Nick Craig-Wood
parent 82c8d78a44
commit 0bd0a992a4

View File

@ -112,6 +112,7 @@ func helpText() (tr []string) {
tr = append(tr, []string{
" Y display current path",
" ^L refresh screen (fix screen corruption)",
" r recalculate file sizes",
" ? to toggle help on and off",
" q/ESC/^c to quit",
}...)
@ -122,6 +123,7 @@ func helpText() (tr []string) {
type UI struct {
s tcell.Screen
f fs.Fs // fs being displayed
cancel func() // cancel the current scanning process
fsName string // human name of Fs
root *scan.Dir // root directory
d *scan.Dir // current directory being displayed
@ -900,6 +902,15 @@ func NewUI(f fs.Fs) *UI {
}
}
func (u *UI) scan() (chan *scan.Dir, chan error, chan struct{}) {
if cancel := u.cancel; cancel != nil {
cancel()
}
ctx := context.Background()
ctx, u.cancel = context.WithCancel(ctx)
return scan.Scan(ctx, u.f)
}
// Run shows the user interface
func (u *UI) Run() error {
var err error
@ -936,8 +947,7 @@ func (u *UI) Run() error {
defer u.s.Fini()
// scan the disk in the background
u.listing = true
rootChan, errChan, updated := scan.Scan(context.Background(), u.f)
rootChan, errChan, updated := u.scan()
// Poll the events into a channel
events := make(chan tcell.Event)
@ -1038,6 +1048,9 @@ outer:
u.deleteSelected()
case '?':
u.togglePopupBox(helpText())
case 'r':
// restart scan
rootChan, errChan, updated = u.scan()
// Refresh the screen. Not obvious what key to map
// this onto, but ^L is a common choice.