diff --git a/cli.go b/cli.go index 2581ed765..7f1d2b74c 100644 --- a/cli.go +++ b/cli.go @@ -14,8 +14,10 @@ import ( ) const helpText = ` -[red]up, down [white]Move cursor - [red]d [white]Delete selected file or dir +[red]up, down, j, k [white]Move cursor + [red]enter, h [white]Select dir/device + [red]l [white]Go to parent dir + [red]d [white]Delete selected file or dir ` // UI struct @@ -228,19 +230,38 @@ func (ui *UI) keyPressed(key *tcell.EventKey) *tcell.EventKey { ui.app.SetFocus(ui.table) return key } - if key.Rune() == 'q' { + switch key.Rune() { + case 'q': ui.app.Stop() return nil - } - if key.Rune() == '?' { + case '?': ui.showHelp() - } - if key.Rune() == 'd' { + break + case 'd': if ui.askBeforeDelete { ui.confirmDeletion() } else { ui.deleteSelected() } + break + case 'h': + row, column := ui.table.GetSelection() + if ui.currentDir != nil { + ui.fileItemSelected(row, column) + } else { + ui.deviceItemSelected(row, column) + } + break + case 'l': + if ui.currentDirPath == ui.topDirPath { + break + } + if ui.currentDir != nil { + ui.fileItemSelected(0, 0) + } else { + ui.deviceItemSelected(0, 0) + } + break } return key } @@ -277,8 +298,8 @@ func (ui *UI) showHelp() { AddItem(nil, 0, 1, false). AddItem(tview.NewFlex().SetDirection(tview.FlexRow). AddItem(nil, 0, 1, false). - AddItem(text, 10, 1, false). - AddItem(nil, 0, 1, false), 50, 1, false). + AddItem(text, 12, 1, false). + AddItem(nil, 0, 1, false), 55, 1, false). AddItem(nil, 0, 1, false) ui.help = flex diff --git a/cli_test.go b/cli_test.go index 01b58382e..7fc99ef5a 100644 --- a/cli_test.go +++ b/cli_test.go @@ -77,7 +77,7 @@ func TestHelp(t *testing.T) { b, _, _ := simScreen.GetContents() - cells := b[252:259] + cells := b[308:315] text := []byte("selected") for i, r := range cells { @@ -176,3 +176,43 @@ func printScreen(simScreen tcell.SimulationScreen) { println(i, string(r.Bytes)) } } + +func TestKeys(t *testing.T) { + fin := CreateTestDir() + defer fin() + + simScreen := tcell.NewSimulationScreen("UTF-8") + simScreen.Init() + simScreen.SetSize(50, 50) + + ui := CreateUI(simScreen) + ui.askBeforeDelete = false + + ui.AnalyzePath("test_dir") + + go func() { + time.Sleep(100 * time.Millisecond) + simScreen.InjectKey(tcell.KeyRune, 'j', 1) + time.Sleep(100 * time.Millisecond) + simScreen.InjectKey(tcell.KeyRune, 'h', 1) + time.Sleep(100 * time.Millisecond) + simScreen.InjectKey(tcell.KeyRune, 'j', 1) + time.Sleep(100 * time.Millisecond) + simScreen.InjectKey(tcell.KeyRune, 'h', 1) + time.Sleep(100 * time.Millisecond) + simScreen.InjectKey(tcell.KeyRune, 'j', 1) + time.Sleep(100 * time.Millisecond) + simScreen.InjectKey(tcell.KeyRune, 'd', 1) + time.Sleep(100 * time.Millisecond) + simScreen.InjectKey(tcell.KeyEnter, 'l', 1) + time.Sleep(100 * time.Millisecond) + simScreen.InjectKey(tcell.KeyRune, 'l', 1) + time.Sleep(100 * time.Millisecond) + simScreen.InjectKey(tcell.KeyRune, 'q', 1) + time.Sleep(100 * time.Millisecond) + }() + + ui.StartUILoop() + + assert.NoFileExists(t, "test_dir/nested/subnested/file") +}