Add keybinding backspace to focus the current folder after returning to the parent folder

This commit is contained in:
Trevor Slocum 2020-01-15 21:01:41 -08:00
parent fc13cb0928
commit 18812b2913
4 changed files with 54 additions and 8 deletions

View file

@ -1,5 +1,6 @@
0.1.2:
- Allow audio buffer size to be configured
- Add keybinding backspace to focus the current folder after returning to the parent folder
0.1.1:
- Improve list browsing

View file

@ -8,6 +8,7 @@ This document covers the [ditty](https://git.sr.ht/~tslocum/ditty) configuration
* Select: Enter
* Pause: Space
* Volume: -/+
* Parent folder, focus current: Backspace
# config.yaml

53
gui.go
View file

@ -5,6 +5,7 @@ import (
"fmt"
"math"
"os"
"path"
"path/filepath"
"strings"
"sync"
@ -28,6 +29,7 @@ var (
mainBufferCursor int
mainBufferDirectory string
mainBufferOrigin int
mainBufferAutoFocus string // Entry path to focus after loading display
seekStart, seekEnd int
volumeStart, volumeEnd int
@ -86,17 +88,52 @@ func browseFolder(browse string) {
if err != nil {
return
}
if browse == mainBufferDirectory {
mainBufferAutoFocus = ""
return
}
mainBufferFiles = scanFolder(browse)
if len(mainBufferFiles) > 0 {
mainBufferCursor = 1
} else {
mainBufferCursor = 0
}
mainBufferCursor = 0
mainBufferOrigin = 0
mainBufferDirectory = browse
if mainBufferAutoFocus != "" {
autoSelectAbs, err := filepath.Abs(mainBufferAutoFocus)
if err == nil && autoSelectAbs != mainBufferDirectory {
autoSelect := -1
var entryPath string
for i, entry := range mainBufferFiles {
if !entry.File.IsDir() {
continue
}
entryPath, err = filepath.Abs(path.Join(mainBufferDirectory, entry.File.Name()))
if err == nil {
if entryPath == autoSelectAbs {
autoSelect = i
break
}
}
}
if autoSelect >= 0 {
mainBufferCursor = autoSelect
mainBufferNewOrigin := (mainBufferCursor - (mainBufHeight - 4)) + ((mainBufHeight - 2) / 2)
if mainBufferNewOrigin <= 0 {
mainBufferNewOrigin = 0
} else if mainBufferNewOrigin > len(mainBufferFiles)-(mainBufHeight-3) {
mainBufferNewOrigin = len(mainBufferFiles) - (mainBufHeight - 3)
}
mainBufferOrigin = mainBufferNewOrigin
mainBufferAutoFocus = ""
go listNext()
return
}
}
mainBufferAutoFocus = ""
}
go app.QueueUpdateDraw(updateMain)
}
@ -264,9 +301,9 @@ func updateStatus() {
for i := -7.5; i < v-0.5; i += 0.5 {
statusBuffer.WriteRune(tcell.RuneHLine)
}
statusBuffer.WriteRune(tcell.RuneBlock)
statusBuffer.WriteRune('▷')
for i := v; i < 0; i += 0.5 {
statusBuffer.WriteRune(tcell.RuneHLine)
statusBuffer.WriteRune(' ')
}
}
@ -277,7 +314,7 @@ func updateStatus() {
if paused {
progressIndicator = "||"
} else {
progressIndicator = string(tcell.RuneBlock)
progressIndicator = "▷"
}
padding := screenWidth - runewidth.StringWidth(bottomStatus) - len(formatDuration(p)) - runewidth.StringWidth(progressIndicator) - 3

View file

@ -1,6 +1,8 @@
package main
import (
"path"
"github.com/faiface/beep/speaker"
"github.com/gdamore/tcell"
)
@ -95,6 +97,11 @@ func handleKeyPress(event *tcell.EventKey) *tcell.EventKey {
case tcell.KeyEscape:
done <- true
return nil
case tcell.KeyBackspace, tcell.KeyBackspace2:
mainBufferAutoFocus = mainBufferDirectory
go browseFolder(path.Join(mainBufferDirectory, ".."))
return nil
case tcell.KeyEnter:
go listSelect()
return nil