Skip to content

Commit

Permalink
cmd/ncdu: add keybinding to rescan filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
eNV25 authored and ncw committed Aug 30, 2023
1 parent 82c8d78 commit 0bd0a99
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions cmd/ncdu/ncdu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}...)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 0bd0a99

Please sign in to comment.