diff options
author | Daniel Milde <daniel@milde.cz> | 2022-02-12 23:02:31 +0100 |
---|---|---|
committer | Daniel Milde <daniel@milde.cz> | 2022-02-12 23:05:09 +0100 |
commit | ab4e2fac6d118fe93e8bdbc7bf8e78e5c693d4ff (patch) | |
tree | fad083b938bae81c5714de731e977b8dcd5f5e03 | |
parent | 5f9f3fa8ab8278672d3e28d0c1629bf386f328b3 (diff) |
fix(devices): go back to devices listv5.13.2
fixes #129
-rw-r--r-- | tui/actions.go | 1 | ||||
-rw-r--r-- | tui/actions_test.go | 6 | ||||
-rw-r--r-- | tui/keys.go | 7 | ||||
-rw-r--r-- | tui/keys_test.go | 7 | ||||
-rw-r--r-- | tui/show.go | 10 | ||||
-rw-r--r-- | tui/tui.go | 1 | ||||
-rw-r--r-- | tui/tui_test.go | 2 |
7 files changed, 30 insertions, 4 deletions
diff --git a/tui/actions.go b/tui/actions.go index b89d5fb..7f098be 100644 --- a/tui/actions.go +++ b/tui/actions.go @@ -24,6 +24,7 @@ const linesTreshold = 20 // ListDevices lists mounted devices and shows their disk usage func (ui *UI) ListDevices(getter device.DevicesInfoGetter) error { var err error + ui.getter = getter ui.devices, err = getter.GetDevicesInfo() if err != nil { return err diff --git a/tui/actions_test.go b/tui/actions_test.go index 746d21c..19b77bc 100644 --- a/tui/actions_test.go +++ b/tui/actions_test.go @@ -78,9 +78,9 @@ func TestDeviceSelected(t *testing.T) { assert.Equal(t, "test_dir", ui.currentDir.GetName()) - assert.Equal(t, 5, ui.table.GetRowCount()) - assert.Contains(t, ui.table.GetCell(0, 0).Text, "/..") - assert.Contains(t, ui.table.GetCell(1, 0).Text, "aaa") + assert.Equal(t, 4, ui.table.GetRowCount()) + assert.Contains(t, ui.table.GetCell(0, 0).Text, "aaa") + assert.Contains(t, ui.table.GetCell(1, 0).Text, "bbb") } func TestAnalyzePath(t *testing.T) { diff --git a/tui/keys.go b/tui/keys.go index 431f313..d73f9af 100644 --- a/tui/keys.go +++ b/tui/keys.go @@ -156,6 +156,13 @@ func (ui *UI) keyPressed(key *tcell.EventKey) *tcell.EventKey { func (ui *UI) handleLeft() { if ui.currentDirPath == ui.topDirPath { + if ui.devices != nil { + ui.currentDir = nil + err := ui.ListDevices(ui.getter) + if err != nil { + ui.showErr("Error listing devices", err) + } + } return } if ui.currentDir != nil { diff --git a/tui/keys_test.go b/tui/keys_test.go index 1ea4fa6..c7311bd 100644 --- a/tui/keys_test.go +++ b/tui/keys_test.go @@ -9,6 +9,7 @@ import ( "github.com/dundee/gdu/v5/internal/testapp" "github.com/dundee/gdu/v5/internal/testdir" "github.com/dundee/gdu/v5/pkg/analyze" + "github.com/dundee/gdu/v5/pkg/device" "github.com/dundee/gdu/v5/pkg/fs" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" @@ -158,6 +159,12 @@ func TestMoveRightOnDevice(t *testing.T) { } assert.Equal(t, "test_dir", ui.currentDir.GetName()) + + // go back to list of devices + ui.keyPressed(tcell.NewEventKey(tcell.KeyLeft, 'h', 0)) + + assert.Nil(t, ui.currentDir) + assert.Equal(t, "/dev/root", ui.table.GetCell(1, 0).GetReference().(*device.Device).Name) } func TestStop(t *testing.T) { diff --git a/tui/show.go b/tui/show.go index 7022417..d071b2b 100644 --- a/tui/show.go +++ b/tui/show.go @@ -103,6 +103,7 @@ func (ui *UI) showDir() { func (ui *UI) showDevices() { var totalUsage int64 + ui.table.Clear() ui.table.SetCell(0, 0, tview.NewTableCell("Device name").SetSelectable(false)) ui.table.SetCell(0, 1, tview.NewTableCell("Size").SetSelectable(false)) ui.table.SetCell(0, 2, tview.NewTableCell("Used").SetSelectable(false)) @@ -149,6 +150,15 @@ func (ui *UI) showDevices() { ui.table.Select(1, 0) ui.table.SetSelectedFunc(ui.deviceItemSelected) + + if ui.topDirPath != "" { + for i, device := range ui.devices { + if device.MountPoint == ui.topDirPath { + ui.table.Select(i+1, 0) + break + } + } + } } func (ui *UI) showErr(msg string, err error) { @@ -70,6 +70,7 @@ type UI struct { done chan struct{} remover func(fs.Item, fs.Item) error emptier func(fs.Item, fs.Item) error + getter device.DevicesInfoGetter exec func(argv0 string, argv []string, envv []string) error linkedItems fs.HardLinkedItems } diff --git a/tui/tui_test.go b/tui/tui_test.go index 3ea563c..61afc1e 100644 --- a/tui/tui_test.go +++ b/tui/tui_test.go @@ -357,7 +357,7 @@ func TestMin(t *testing.T) { func getDevicesInfoMock() device.DevicesInfoGetter { item := &device.Device{ Name: "/dev/root", - MountPoint: "/", + MountPoint: "test_dir", Size: 1e12, Free: 1e6, } |