Skip to content

Commit

Permalink
fix: do not show help if file info is shown
Browse files Browse the repository at this point in the history
  • Loading branch information
dundee committed Nov 9, 2021
1 parent 1733548 commit c60f4ca
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 34 deletions.
10 changes: 4 additions & 6 deletions tui/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ func TestShowInfo(t *testing.T) {

ui.keyPressed(tcell.NewEventKey(tcell.KeyRight, 'l', 0))
ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'i', 0))
ui.table.Select(2, 0)
ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'i', 0))

assert.True(t, ui.pages.HasPage("info"))

Expand Down Expand Up @@ -324,10 +322,12 @@ func TestShowInfoBW(t *testing.T) {

ui.keyPressed(tcell.NewEventKey(tcell.KeyRight, 'l', 0))
ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'i', 0))
ui.table.Select(2, 0)
ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'i', 0))

assert.True(t, ui.pages.HasPage("info"))

ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'i', 0))

assert.False(t, ui.pages.HasPage("info"))
}

func TestShowInfoWithHardlinks(t *testing.T) {
Expand Down Expand Up @@ -361,8 +361,6 @@ func TestShowInfoWithHardlinks(t *testing.T) {

ui.keyPressed(tcell.NewEventKey(tcell.KeyRight, 'l', 0))
ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'i', 0))
ui.table.Select(2, 0)
ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'i', 0))

assert.True(t, ui.pages.HasPage("info"))

Expand Down
55 changes: 29 additions & 26 deletions tui/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,26 @@ func (ui *UI) keyPressed(key *tcell.EventKey) *tcell.EventKey {
if key.Key() == tcell.KeyEsc || key.Rune() == 'q' {
if ui.pages.HasPage("help") {
ui.pages.RemovePage("help")
_, page := ui.pages.GetFrontPage()
ui.app.SetFocus(page)
ui.app.SetFocus(ui.table)
return nil
}
if ui.pages.HasPage("info") {
ui.pages.RemovePage("info")
_, page := ui.pages.GetFrontPage()
ui.app.SetFocus(page)
ui.app.SetFocus(ui.table)
return nil
}
}

if key.Rune() == 'i' {
if ui.pages.HasPage("info") {

if ui.pages.HasPage("info") {
switch key.Rune() {
case 'i':
ui.pages.RemovePage("info")
_, page := ui.pages.GetFrontPage()
ui.app.SetFocus(page)
ui.app.SetFocus(ui.table)
return nil
case '?':
return nil
}
}

switch key.Rune() {
case 'Q':
ui.app.Stop()
fmt.Fprintf(ui.output, "%s\n", ui.currentDirPath)
return nil
case 'q':
ui.app.Stop()
return nil
case 'b':
ui.spawnShell()
return nil
case '?':
ui.showHelp()
}

if ui.pages.HasPage("info") {
if key.Key() == tcell.KeyUp ||
key.Key() == tcell.KeyDown ||
key.Rune() == 'j' ||
Expand All @@ -71,6 +54,26 @@ func (ui *UI) keyPressed(key *tcell.EventKey) *tcell.EventKey {
defer ui.showInfo() // refresh file info after any change
}

switch key.Rune() {
case 'Q':
ui.app.Stop()
fmt.Fprintf(ui.output, "%s\n", ui.currentDirPath)
return nil
case 'q':
ui.app.Stop()
return nil
case 'b':
ui.spawnShell()
return nil
case '?':
if ui.pages.HasPage("help") {
ui.pages.RemovePage("help")
ui.app.SetFocus(ui.table)
return nil
}
ui.showHelp()
}

if ui.pages.HasPage("confirm") ||
ui.pages.HasPage("progress") ||
ui.pages.HasPage("deleting") ||
Expand Down
2 changes: 0 additions & 2 deletions tui/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,6 @@ func TestShowInfoAndMoveAround(t *testing.T) {

ui.keyPressed(tcell.NewEventKey(tcell.KeyRight, 'l', 0))
ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'i', 0))
ui.table.Select(2, 0)
ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'i', 0))

assert.True(t, ui.pages.HasPage("info"))

Expand Down

0 comments on commit c60f4ca

Please sign in to comment.