-
Notifications
You must be signed in to change notification settings - Fork 2
/
openwithlist.go
48 lines (38 loc) · 1.45 KB
/
openwithlist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
type OpenWithList struct {
*tview.Box
programs *[]string
descriptions *[]string
}
func NewOpenWithList(programs *[]string, descriptions *[]string) *OpenWithList {
if len(*programs) != len(*descriptions) {
panic("In NewOpenWithList: Length of programs and descriptions weren't the same")
}
return &OpenWithList{Box: tview.NewBox().SetBackgroundColor(tcell.ColorBlack), programs: programs, descriptions: descriptions}
}
func (openWithList *OpenWithList) Draw(screen tcell.Screen) {
if len(*openWithList.programs) != len(*openWithList.descriptions) {
panic("In openwithlist.go Draw(): Length of programs and descriptions weren't the same")
}
openWithList.Box.SetBackgroundColor(tcell.ColorBlack)
openWithList.Box.DrawForSubclass(screen, openWithList)
x, y, w, _ := openWithList.GetInnerRect()
for i, program := range *openWithList.programs {
color := tcell.ColorDefault
if i == 0 {
color = tcell.ColorAqua
}
description := (*openWithList.descriptions)[i]
_, descriptionWidth := tview.Print(screen, "[::d]"+tview.Escape(description), x-1, y+i, w, tview.AlignRight, color)
programName := program
programNameCutoff := w - descriptionWidth - 3
if len(programName) > programNameCutoff {
programName = programName[:max(0, programNameCutoff-3)] + "..."
}
tview.Print(screen, tview.Escape(programName), x+1, y+i, programNameCutoff, tview.AlignLeft, color)
}
}