Browse Source

Add scrollbar to lists

Resolves #9.
master
Trevor Slocum 3 years ago
parent
commit
3ed0a1ee85
  1. 3
      CHANGELOG
  2. 4
      CONFIGURATION.md
  3. 2
      README.md
  4. 2
      go.sum
  5. 91
      gui.go
  6. 2
      gui_key.go
  7. 46
      gui_list.go
  8. 12
      library.go

3
CHANGELOG

@ -1,3 +1,6 @@
0.1.7:
- Add scrollbar to lists
0.1.6:
- Add mouse support to queue

4
CONFIGURATION.md

@ -24,7 +24,7 @@ configuration options and their defaults.
* **Refresh** R
* **Toggle hidden folder visibility** .
* **Browse parent folder and focus last** Backspace
* **Exit** Escape
* **Exit** Ctrl+C or Alt+Q
# Default ~/.config/ditty/config.yaml
@ -69,5 +69,5 @@ input:
next-track:
- 'n'
exit:
- 'Escape'
- 'Alt+q'
```

2
README.md

@ -7,7 +7,7 @@ Audio player
## Screenshot
[![](https://ditty.rocketnine.space/static/screenshot1.png)](https://ditty.rocketnine.space/static/screenshot1.png)
[![](https://ditty.rocketnine.space/static/screenshot2.png)](https://ditty.rocketnine.space/static/screenshot2.png)
## Demo

2
go.sum

@ -44,6 +44,8 @@ github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp
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/mattn/go-runewidth v0.0.9-0.20200125155203-588506649b41 h1:AkInqmD1OrueaAKIWH0RWU+irX4nL1oqScB++w2CAlU=
github.com/mattn/go-runewidth v0.0.9-0.20200125155203-588506649b41/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mewkiz/flac v1.0.5/go.mod h1:EHZNU32dMF6alpurYyKHDLYpW1lYpBZ5WrXi/VuNIGs=
github.com/mewkiz/flac v1.0.6 h1:OnMwCWZPAnjDndjEzLynOZ71Y2U+/QYHoVI4JEKgKkk=
github.com/mewkiz/flac v1.0.6/go.mod h1:yU74UH277dBUpqxPouHSQIar3G1X/QIclVbFahSd1pU=

91
gui.go

@ -214,9 +214,11 @@ func updateMain() {
}
mainBuffer.WriteString(statusMessage)
mainbuf.SetTitle(" " + runewidth.Truncate(mainBuffer.String(), screenWidth-4, "...") + " ")
mainbuf.SetTitle(" " + cview.Escape(runewidth.Truncate(mainBuffer.String(), screenWidth-4, "...")) + " ")
mainBuffer.Reset()
l := len(mainBufferFiles) + 1
var printed int
var line string
if mainBufferOrigin == 0 {
@ -227,17 +229,11 @@ func updateMain() {
} else {
line = "../"
}
lineWidth := runewidth.StringWidth(line)
line = cview.Escape(line)
mainBuffer.WriteString(line)
if queueFocused {
writeListItemSuffix(&mainBuffer, !queueFocused, mainBufferCursor, 0)
}
for i := len(line); i < screenWidth-2; i++ {
mainBuffer.WriteRune(' ')
}
if !queueFocused {
writeListItemSuffix(&mainBuffer, !queueFocused, mainBufferCursor, 0)
}
writeListItemSuffix(&mainBuffer, !queueFocused, mainBufferCursor, 0, 0, l, lineWidth, mainBufHeight-2)
printed++
}
@ -253,28 +249,31 @@ func updateMain() {
writeListItemPrefix(&mainBuffer, !queueFocused, mainBufferCursor-1, i)
if entry.File.IsDir() {
line = entry.File.Name() + "/"
line = strings.TrimSpace(entry.File.Name()) + "/"
} else {
line = entry.String()
}
lineWidth := runewidth.StringWidth(line)
line = cview.Escape(line)
mainBuffer.WriteString(line)
if queueFocused {
writeListItemSuffix(&mainBuffer, !queueFocused, mainBufferCursor-1, i)
}
writeListItemSuffix(&mainBuffer, !queueFocused, mainBufferCursor, printed, i+1, l, lineWidth, mainBufHeight-2)
for i := runewidth.StringWidth(line); i < screenWidth-2; i++ {
mainBuffer.WriteRune(' ')
printed++
if printed == mainBufHeight-2 {
break
}
}
if !queueFocused {
writeListItemSuffix(&mainBuffer, !queueFocused, mainBufferCursor-1, i)
remaining := (mainBufHeight - 2) - printed
for i := 0; i < remaining; i++ {
if printed > 0 {
mainBuffer.WriteRune('\n')
}
writeListItemSuffix(&mainBuffer, !queueFocused, mainBufferCursor, printed, remaining-printed, l, 0, mainBufHeight-2)
printed++
if printed == mainBufHeight-2 {
break
}
}
mainbuf.SetText(mainBuffer.String())
@ -286,6 +285,8 @@ func updateQueue() {
queueBuffer.Reset()
l := len(queueFiles)
var printed int
var line string
for i, entry := range queueFiles {
@ -300,18 +301,12 @@ func updateQueue() {
writeListItemPrefix(&queueBuffer, queueFocused, queueCursor, i)
line = entry.String()
lineWidth := runewidth.StringWidth(line)
line = cview.Escape(line)
queueBuffer.WriteString(line)
if !queueFocused {
writeListItemSuffix(&queueBuffer, queueFocused, queueCursor, i)
}
for i := runewidth.StringWidth(line); i < screenWidth-2; i++ {
queueBuffer.WriteRune(' ')
}
if queueFocused {
writeListItemSuffix(&queueBuffer, queueFocused, queueCursor, i)
}
writeListItemSuffix(&queueBuffer, queueFocused, queueCursor, printed, i, l, lineWidth, queueHeight-2)
printed++
if printed == queueHeight-2 {
@ -319,6 +314,17 @@ func updateQueue() {
}
}
remaining := (queueHeight - 2) - printed
for i := 0; i < remaining; i++ {
if printed > 0 {
queueBuffer.WriteRune('\n')
}
writeListItemSuffix(&queueBuffer, queueFocused, queueCursor, printed, remaining-printed, l, 0, queueHeight-2)
printed++
}
queuebuf.SetText(queueBuffer.String())
}
@ -334,14 +340,31 @@ func writeListItemPrefix(buffer *bytes.Buffer, focused bool, cursor int, i int)
}
}
func writeListItemSuffix(buffer *bytes.Buffer, focused bool, cursor int, i int) {
func writeListItemSuffix(buffer *bytes.Buffer, focused bool, cursor int, printed int, i int, count int, lineWidth int, height int) {
if !focused && i == cursor {
buffer.WriteString("[-:-:-]")
}
for i := lineWidth; i < screenWidth-3; i++ {
buffer.WriteRune(' ')
}
if focused && i == cursor {
buffer.WriteString("[-:-:-]")
}
scrollBlockPos := int(float64(height-1) * (float64(cursor) / float64(count-1)))
if focused {
if i == cursor {
if printed == scrollBlockPos {
buffer.WriteString("[::r]")
buffer.WriteRune(' ')
buffer.WriteString("[-:-:-]")
} else {
buffer.WriteRune('▒')
}
} else {
if i == cursor {
buffer.WriteString("[-:-:-]")
if printed == scrollBlockPos {
buffer.WriteRune('▓')
} else {
buffer.WriteRune('░')
}
}
}

2
gui_key.go

@ -107,6 +107,6 @@ func setDefaultKeyBinds() {
actionNextPage: {"PageDown"},
actionPreviousTrack: {"p"},
actionNextTrack: {"n"},
actionExit: {"Escape"},
actionExit: {"Alt+q"},
}
}

46
gui_list.go

@ -6,42 +6,32 @@ import (
)
func listPrevious() {
if !queueFocused {
if mainBufferOrigin > 0 && mainBufferCursor == mainBufferOrigin {
mainBufferOrigin--
}
if mainBufferCursor > 0 {
mainBufferCursor--
}
} else {
if queueOrigin > 0 && queueCursor == queueOrigin {
queueOrigin--
}
if queueCursor > 0 {
queueCursor--
}
if queueFocused {
queuePrevious()
return
}
if mainBufferOrigin > 0 && mainBufferCursor == mainBufferOrigin {
mainBufferOrigin--
}
if mainBufferCursor > 0 {
mainBufferCursor--
}
go app.QueueUpdateDraw(updateLists)
}
func listNext() {
if !queueFocused {
if mainBufferCursor < len(mainBufferFiles) {
mainBufferCursor++
if mainBufferCursor-mainBufferOrigin > mainBufHeight-3 {
mainBufferOrigin++
}
}
} else {
if queueCursor < len(queueFiles)-1 {
queueCursor++
if queueCursor-queueOrigin > queueHeight-3 {
queueOrigin++
}
}
if queueFocused {
queueNext()
return
}
if mainBufferCursor < len(mainBufferFiles) {
mainBufferCursor++
if mainBufferCursor-mainBufferOrigin > mainBufHeight-3 {
mainBufferOrigin++
}
}
go app.QueueUpdateDraw(updateLists)
}

12
library.go

@ -23,11 +23,11 @@ func readMetadata(f *os.File) *metadata {
m, err := tag.ReadFrom(f)
if err != nil || m.Title() == "" {
metadata.Title = path.Base(f.Name())
metadata.Title = strings.TrimSpace(path.Base(f.Name()))
} else {
metadata.Title = m.Title()
metadata.Artist = m.Artist()
metadata.Album = m.Album()
metadata.Title = strings.TrimSpace(m.Title())
metadata.Artist = strings.TrimSpace(m.Artist())
metadata.Album = strings.TrimSpace(m.Album())
metadata.Track, _ = m.Track()
}
@ -49,7 +49,7 @@ func (e *libraryEntry) String() string {
return e.Metadata.Title
}
return e.File.Name()
return strings.TrimSpace(e.File.Name())
}
func scanFolder(scanPath string) []*libraryEntry {
@ -65,7 +65,7 @@ func scanFolder(scanPath string) []*libraryEntry {
b := path.Base(fileInfo.Name())
if fileInfo.IsDir() {
if b != "" && (b[0] != '.' || showHiddenFolders) {
entries = append(entries, &libraryEntry{File: fileInfo, Path: p, Metadata: &metadata{Title: fileInfo.Name()}})
entries = append(entries, &libraryEntry{File: fileInfo, Path: p, Metadata: &metadata{Title: strings.TrimSpace(fileInfo.Name())}})
}
continue

Loading…
Cancel
Save