Commit 3ed0a1ee authored by Trevor Slocum's avatar Trevor Slocum

Add scrollbar to lists

Resolves #9.
parent 9b2116f5
Pipeline #113334839 passed with stages
in 2 minutes and 14 seconds
0.1.7:
- Add scrollbar to lists
0.1.6:
- Add mouse support to queue
......
......@@ -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'
```
......@@ -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
......
......@@ -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('░')
}
}
}
......
......@@ -107,6 +107,6 @@ func setDefaultKeyBinds() {
actionNextPage: {"PageDown"},
actionPreviousTrack: {"p"},
actionNextTrack: {"n"},
actionExit: {"Escape"},
actionExit: {"Alt+q"},
}
}
......@@ -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)
}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment