Skip to content

Commit

Permalink
use h/l keys to move up/down dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Milde committed Dec 30, 2020
1 parent 4f482c6 commit 9922b91
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 10 deletions.
39 changes: 30 additions & 9 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
42 changes: 41 additions & 1 deletion cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}

0 comments on commit 9922b91

Please sign in to comment.