Handle key events with cbind

This commit is contained in:
Trevor Slocum 2020-01-21 17:10:20 -08:00
parent 18812b2913
commit 6a88324acb
9 changed files with 246 additions and 164 deletions

View File

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

View File

@ -158,6 +158,21 @@ func play(audioFile *AudioFile) {
})
}
func pause() {
audioLock.Lock()
defer audioLock.Unlock()
if ctrl == nil {
return
}
speaker.Lock()
ctrl.Paused = !ctrl.Paused
speaker.Unlock()
go app.QueueUpdateDraw(updateStatus)
}
func nextTrack() {
if mainBufferCursor-1 < len(mainBufferFiles)-1 {
mainBufferCursor++
@ -173,6 +188,28 @@ func nextTrack() {
}
}
func skipPrevious() {
if mainBufferCursor > 1 {
if offsetEntry(-1).File.IsDir() {
return
}
listPrevious()
go listSelect()
}
}
func skipNext() {
if mainBufferCursor < len(mainBufferFiles) {
if offsetEntry(1).File.IsDir() {
return
}
listNext()
go listSelect()
}
}
func roundUnit(x, unit float64) float64 {
return math.Round(x/unit) * unit
}
@ -206,3 +243,63 @@ func fileFormat(fileName string) string {
return "?"
}
}
func adjustVolume(adjustment float64) {
audioLock.Lock()
defer audioLock.Unlock()
if volume == nil {
return
}
speaker.Lock()
volume.Volume += adjustment
volumeUpdated()
speaker.Unlock()
go app.QueueUpdateDraw(updateStatus)
}
func setVolume(vol float64) {
audioLock.Lock()
defer audioLock.Unlock()
if volume == nil {
return
}
speaker.Lock()
volume.Volume = vol
volumeUpdated()
speaker.Unlock()
go app.QueueUpdateDraw(updateStatus)
}
func volumeUpdated() {
if volume.Volume <= -7.5 {
volume.Volume = -7.5
volume.Silent = true
} else {
volume.Silent = false
if volume.Volume > 0 {
volume.Volume = 0
}
}
}
func toggleMute() {
audioLock.Lock()
defer audioLock.Unlock()
if volume == nil {
return
}
speaker.Lock()
volume.Silent = !volume.Silent
speaker.Unlock()
go app.QueueUpdateDraw(updateStatus)
}

13
go.mod
View File

@ -3,17 +3,18 @@ module git.sr.ht/~tslocum/ditty
go 1.13
require (
git.sr.ht/~tslocum/cview v0.2.2
git.sr.ht/~tslocum/cbind v0.0.0-20200122005705-c4f326764399
git.sr.ht/~tslocum/cview v1.4.1-0.20200117063451-51704b98449e
github.com/dhowden/tag v0.0.0-20191122115059-7e5c04feccd8
github.com/faiface/beep v1.0.2
github.com/gdamore/tcell v1.3.0
github.com/hajimehoshi/go-mp3 v0.2.1 // indirect
github.com/hajimehoshi/oto v0.5.4 // indirect
github.com/jfreymuth/oggvorbis v1.0.1 // indirect
github.com/mattn/go-runewidth v0.0.7
github.com/mattn/go-runewidth v0.0.8
github.com/mewkiz/flac v1.0.6 // indirect
golang.org/x/exp v0.0.0-20191227195350-da58074b4299 // indirect
golang.org/x/image v0.0.0-20191214001246-9130b4cfad52 // indirect
golang.org/x/mobile v0.0.0-20191210151939-1a1fef82734d // indirect
golang.org/x/sys v0.0.0-20200107162124-548cf772de50 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a // indirect
golang.org/x/image v0.0.0-20200119044424-58c23975cae1 // indirect
golang.org/x/mobile v0.0.0-20200121160505-1d4ecbb920e2 // indirect
)

31
go.sum
View File

@ -1,6 +1,8 @@
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
git.sr.ht/~tslocum/cview v0.2.2 h1:eIN9Wy/DIHP9///qcz9Q7JkMP36duA5iyTP0GJ+WhvY=
git.sr.ht/~tslocum/cview v0.2.2/go.mod h1:TLTjvAd3pw6MqV6SaBMpxOdOdODW4O2gtQJ3B3H6PoU=
git.sr.ht/~tslocum/cbind v0.0.0-20200122005705-c4f326764399 h1:r7VQ34sqmzSQzuWS7nrHqaR92ARCN62s032M7cJ9Heo=
git.sr.ht/~tslocum/cbind v0.0.0-20200122005705-c4f326764399/go.mod h1:NE2mliwcbn3v+eT4rCiQsQYEUftKzGXMfii83F385rA=
git.sr.ht/~tslocum/cview v1.4.1-0.20200117063451-51704b98449e h1:gKRY1WnpfiBLT7ypBPz9njkkqBXrjMfru1QfnhFDnG8=
git.sr.ht/~tslocum/cview v1.4.1-0.20200117063451-51704b98449e/go.mod h1:TLTjvAd3pw6MqV6SaBMpxOdOdODW4O2gtQJ3B3H6PoU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/d4l3k/messagediff v1.2.2-0.20190829033028-7e0a312ae40b/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo=
@ -50,6 +52,8 @@ github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.8 h1:3tS41NlGYSmhhe/8fhGRzc+z3AYCw1Fe1WAyLuujKs0=
github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mewkiz/flac v1.0.5 h1:dHGW/2kf+/KZ2GGqSVayNEhL9pluKn/rr/h/QqD9Ogc=
github.com/mewkiz/flac v1.0.5/go.mod h1:EHZNU32dMF6alpurYyKHDLYpW1lYpBZ5WrXi/VuNIGs=
github.com/mewkiz/flac v1.0.6 h1:OnMwCWZPAnjDndjEzLynOZ71Y2U+/QYHoVI4JEKgKkk=
@ -58,31 +62,35 @@ github.com/mewkiz/pkg v0.0.0-20190919212034-518ade7978e2 h1:EyTNMdePWaoWsRSGQnXi
github.com/mewkiz/pkg v0.0.0-20190919212034-518ade7978e2/go.mod h1:3E2FUC/qYUfM8+r9zAwpeHJzqRVVMIYnpzD/clwWxyA=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp v0.0.0-20180710024300-14dda7b62fcd h1:nLIcFw7GiqKXUS7HiChg6OAYWgASB2H97dZKd1GhDSs=
golang.org/x/exp v0.0.0-20180710024300-14dda7b62fcd/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
golang.org/x/exp v0.0.0-20191227195350-da58074b4299 h1:zQpM52jfKHG6II1ISZY1ZcpygvuSFZpLwfluuF89XOg=
golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a h1:7Wlg8L54In96HTWOaI4sreLJ6qfyGuvSau5el3fK41Y=
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81 h1:00VmoueYNlNz/aHIilyyQz/MHSqGoWJzpFv/HW8xpzI=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/image v0.0.0-20190220214146-31aff87c08e9/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20191214001246-9130b4cfad52 h1:2fktqPPvDiVEEVT/vSTeoUPXfmRxRaGy6GU8jypvEn0=
golang.org/x/image v0.0.0-20191214001246-9130b4cfad52/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20200119044424-58c23975cae1 h1:5h3ngYt7+vXCDZCup/HkCQgW5XwmSvR/nA2JmJ0RErg=
golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/mobile v0.0.0-20180806140643-507816974b79 h1:t2JRgCWkY7Qaa1J2jal+wqC9OjbyHCHwIA9rVlRUSMo=
golang.org/x/mobile v0.0.0-20180806140643-507816974b79/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mobile v0.0.0-20191210151939-1a1fef82734d h1:LlA9R5JFi974qK4gm9FRK1+qSkduxnQKcrimdzcidyc=
golang.org/x/mobile v0.0.0-20191210151939-1a1fef82734d/go.mod h1:p895TfNkDgPEmEQrNiOtIl3j98d/tGU95djDj7NfyjQ=
golang.org/x/mobile v0.0.0-20200121160505-1d4ecbb920e2 h1:TS20rpqvAKnsQyB5U8xbPW/64dThaaUO/2PLmq5JZ2o=
golang.org/x/mobile v0.0.0-20200121160505-1d4ecbb920e2/go.mod h1:xVnulspMBrznVIwB4CQrGc712u7ETbNKUJ+GCqGLaEc=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.1.1-0.20191209134235-331c550502dd/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
@ -96,14 +104,15 @@ golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200103143344-a1369afcdac7 h1:/W9OPMnnpmFXHYkcp2rQsbFUbRlRzfECQjmAFiOyHE8=
golang.org/x/sys v0.0.0-20200103143344-a1369afcdac7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200107162124-548cf772de50 h1:YvQ10rzcqWXLlJZ3XCUoO25savxmscf4+SC+ZqiCHhA=
golang.org/x/sys v0.0.0-20200107162124-548cf772de50/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200121082415-34d275377bf9 h1:N19i1HjUnR7TF7rMt8O4p3dLvqvmYyzB6ifMFmrbY50=
golang.org/x/sys v0.0.0-20200121082415-34d275377bf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190909214602-067311248421/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0/go.mod h1:OdE7CF6DbADk7lN8LIKRzRJTTZXIjtWgA5THM5lhBAw=

14
gui.go
View File

@ -50,7 +50,8 @@ func initTUI() error {
app.EnableMouse()
app.SetInputCapture(handleKeyPress)
setDefaultKeyBinds()
app.SetInputCapture(inputConfig.Capture)
app.SetAfterResizeFunc(handleResize)
@ -137,6 +138,11 @@ func browseFolder(browse string) {
go app.QueueUpdateDraw(updateMain)
}
func browseParent() {
mainBufferAutoFocus = mainBufferDirectory
go browseFolder(path.Join(mainBufferDirectory, ".."))
}
func updateMain() {
mainLock.Lock()
defer mainLock.Unlock()
@ -293,7 +299,7 @@ func updateStatus() {
statusBuffer.WriteString("Mut ")
for i := -7.5; i < 0.0; i += 0.5 {
statusBuffer.WriteRune(tcell.RuneHLine)
statusBuffer.WriteRune(' ')
}
} else {
statusBuffer.WriteString("Vol ")
@ -351,8 +357,8 @@ func formatDuration(d time.Duration) string {
return fmt.Sprintf("%02d:%02d", minutes, seconds)
}
func handleResize(screen tcell.Screen) {
screenWidth, screenHeight = screen.Size()
func handleResize(width int, height int) {
screenWidth, screenHeight = width, height
updateMain()
updateQueue()

View File

@ -1,150 +1,93 @@
package main
import (
"path"
"github.com/faiface/beep/speaker"
"git.sr.ht/~tslocum/cbind"
"github.com/gdamore/tcell"
)
func handleKeyPress(event *tcell.EventKey) *tcell.EventKey {
switch event.Rune() {
case '-':
audioLock.Lock()
defer audioLock.Unlock()
var inputConfig = cbind.NewConfiguration()
if volume == nil {
return nil
}
speaker.Lock()
volume.Volume -= 0.5
if volume.Volume <= -7.5 {
volume.Volume = -7.5
volume.Silent = true
}
speaker.Unlock()
go app.QueueUpdateDraw(updateStatus)
return nil
case '+':
audioLock.Lock()
defer audioLock.Unlock()
if ctrl == nil {
return nil
}
speaker.Lock()
volume.Volume += 0.5
if volume.Volume > 0 {
volume.Volume = 0
}
volume.Silent = false
speaker.Unlock()
go app.QueueUpdateDraw(updateStatus)
return nil
case ' ':
audioLock.Lock()
defer audioLock.Unlock()
if ctrl == nil {
return nil
}
speaker.Lock()
ctrl.Paused = !ctrl.Paused
speaker.Unlock()
go app.QueueUpdateDraw(updateStatus)
return nil
case 'j':
listNext()
return nil
case 'k':
func setDefaultKeyBinds() {
inputConfig.SetKey(tcell.ModNone, tcell.KeyUp, func(ev *tcell.EventKey) *tcell.EventKey {
listPrevious()
return nil
case 'p':
if mainBufferCursor > 1 {
if offsetEntry(-1).File.IsDir() {
return nil
}
})
listPrevious()
go listSelect()
}
inputConfig.SetKey(tcell.ModNone, tcell.KeyDown, func(ev *tcell.EventKey) *tcell.EventKey {
listNext()
return nil
case 'n':
if mainBufferCursor < len(mainBufferFiles) {
if offsetEntry(1).File.IsDir() {
return nil
}
})
inputConfig.SetRune(tcell.ModNone, 'k', func(ev *tcell.EventKey) *tcell.EventKey {
listPrevious()
return nil
})
listNext()
go listSelect()
}
inputConfig.SetRune(tcell.ModNone, 'j', func(ev *tcell.EventKey) *tcell.EventKey {
listNext()
return nil
case 'q':
// Queue non-recursively
return nil
case 'Q':
// Queue recursively
return nil
}
})
switch event.Key() {
case tcell.KeyEscape:
done <- true
return nil
case tcell.KeyBackspace, tcell.KeyBackspace2:
mainBufferAutoFocus = mainBufferDirectory
go browseFolder(path.Join(mainBufferDirectory, ".."))
return nil
case tcell.KeyEnter:
inputConfig.SetKey(tcell.ModNone, tcell.KeyEnter, func(ev *tcell.EventKey) *tcell.EventKey {
go listSelect()
return nil
case tcell.KeyDown:
listNext()
})
inputConfig.SetRune(tcell.ModNone, ' ', func(ev *tcell.EventKey) *tcell.EventKey {
pause()
return nil
case tcell.KeyUp:
listPrevious()
})
inputConfig.SetRune(tcell.ModNone, 'p', func(ev *tcell.EventKey) *tcell.EventKey {
skipPrevious()
return nil
case tcell.KeyPgDn:
numEntries := len(mainBufferFiles)
})
if mainBufferOrigin >= numEntries-(mainBufHeight-1) {
mainBufferCursor = numEntries
go app.QueueUpdateDraw(updateMain)
return nil
}
mainBufferOrigin += (mainBufHeight - 1) - 2
if mainBufferOrigin > (numEntries-(mainBufHeight-1))+2 {
mainBufferOrigin = (numEntries - (mainBufHeight - 1)) + 2
}
mainBufferCursor = mainBufferOrigin
go app.QueueUpdateDraw(updateMain)
inputConfig.SetRune(tcell.ModNone, 'n', func(ev *tcell.EventKey) *tcell.EventKey {
skipNext()
return nil
case tcell.KeyPgUp:
if mainBufferOrigin == 0 {
mainBufferCursor = 0
})
go app.QueueUpdateDraw(updateMain)
return nil
}
mainBufferOrigin -= (mainBufHeight - 1) - 2
if mainBufferOrigin < 0 {
mainBufferOrigin = 0
}
mainBufferCursor = mainBufferOrigin
go app.QueueUpdateDraw(updateMain)
inputConfig.SetRune(tcell.ModNone, '-', func(ev *tcell.EventKey) *tcell.EventKey {
adjustVolume(-0.5)
return nil
}
return event
})
inputConfig.SetRune(tcell.ModNone, '+', func(ev *tcell.EventKey) *tcell.EventKey {
adjustVolume(0.5)
return nil
})
inputConfig.SetRune(tcell.ModNone, 'm', func(ev *tcell.EventKey) *tcell.EventKey {
toggleMute()
return nil
})
inputConfig.SetKey(tcell.ModNone, tcell.KeyEscape, func(ev *tcell.EventKey) *tcell.EventKey {
done <- true
return nil
})
inputConfig.SetKey(tcell.ModNone, tcell.KeyBackspace, func(ev *tcell.EventKey) *tcell.EventKey {
browseParent()
return nil
})
inputConfig.SetKey(tcell.ModNone, tcell.KeyBackspace2, func(ev *tcell.EventKey) *tcell.EventKey {
browseParent()
return nil
})
inputConfig.SetKey(tcell.ModNone, tcell.KeyPgUp, func(ev *tcell.EventKey) *tcell.EventKey {
listPreviousPage()
return nil
})
inputConfig.SetKey(tcell.ModNone, tcell.KeyPgDn, func(ev *tcell.EventKey) *tcell.EventKey {
listNextPage()
return nil
})
// TODO:
// Queue non-recursively - q
// Queue recursively - Q
}

View File

@ -66,3 +66,39 @@ func selectedEntry() *LibraryEntry {
func offsetEntry(offset int) *LibraryEntry {
return mainBufferFiles[(mainBufferCursor-1)+offset]
}
func listPreviousPage() {
if mainBufferOrigin == 0 {
mainBufferCursor = 0
go app.QueueUpdateDraw(updateMain)
return
}
mainBufferOrigin -= (mainBufHeight - 1) - 2
if mainBufferOrigin < 0 {
mainBufferOrigin = 0
}
mainBufferCursor = mainBufferOrigin
go app.QueueUpdateDraw(updateMain)
}
func listNextPage() {
numEntries := len(mainBufferFiles)
if mainBufferOrigin >= numEntries-(mainBufHeight-1) {
mainBufferCursor = numEntries
go app.QueueUpdateDraw(updateMain)
return
}
mainBufferOrigin += (mainBufHeight - 1) - 2
if mainBufferOrigin > (numEntries-(mainBufHeight-1))+2 {
mainBufferOrigin = (numEntries - (mainBufHeight - 1)) + 2
}
mainBufferCursor = mainBufferOrigin
go app.QueueUpdateDraw(updateMain)
}

View File

@ -58,21 +58,11 @@ func handleMouse(event *cview.EventMouse) *cview.EventMouse {
go app.QueueUpdateDraw(updateStatus)
} else {
audioLock.Lock()
speaker.Lock()
setVolume := -7.5 + float64(7.5)*(float64(mouseX-volumeStart-3)/float64(volumeEnd-volumeStart-3))
if setVolume < -7.0 {
setVolume = -7.0
vol := -7.5 + float64(7.5)*(float64(mouseX-volumeStart-3)/float64(volumeEnd-volumeStart-3))
if vol < -7.0 {
vol = -7.0
}
volume.Volume = roundUnit(setVolume, 0.5)
if volume.Volume > 0 {
volume.Volume = 0
}
volume.Silent = setVolume <= -7.5
speaker.Unlock()
audioLock.Unlock()
setVolume(roundUnit(vol, 0.5))
go app.QueueUpdateDraw(updateStatus)
}

View File

@ -23,7 +23,7 @@ func readMetadata(f *os.File) *Metadata {
m, err := tag.ReadFrom(f)
if err != nil || m.Title() == "" {
metadata.Title = f.Name()
metadata.Title = path.Base(f.Name())
} else {
metadata.Title = m.Title()
metadata.Artist = m.Artist()