-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfontsize_adjuster.go
91 lines (74 loc) · 1.83 KB
/
fontsize_adjuster.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package ui
import (
"fmt"
"strconv"
"github.com/solidiquis/alacpretty/internal/yamlconf"
ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
)
type FontsizeAdjuster struct {
// public
Widget *widgets.List
// private
x1, y1, x2, y2 int
yamlConfig *string
}
func NewFontsizeAdjuster(x1, y1, x2, y2 int) *FontsizeAdjuster {
return &FontsizeAdjuster{
Widget: widgets.NewList(),
x1: x1,
y1: y1,
x2: x2,
y2: y2,
}
}
func (fa *FontsizeAdjuster) GetWidget() ui.Drawable {
var widget ui.Drawable = fa.Widget
return widget
}
func (fa *FontsizeAdjuster) ToggleActive() {
if fgColor := fa.Widget.BorderStyle.Fg; fgColor == ui.ColorYellow {
fa.Widget.BorderStyle.Fg = ui.ColorWhite
} else {
fa.Widget.BorderStyle.Fg = ui.ColorYellow
}
ui.Render(fa.Widget)
}
func (fa *FontsizeAdjuster) InitWidget(fileContent *string) {
fa.yamlConfig = fileContent
rows := make([]string, 27)
for i := 6; i < 33; i++ {
rows[i-6] = fmt.Sprintf("%d", i)
}
fa.Widget.Title = "Size"
fa.Widget.Rows = rows
fa.Widget.TextStyle = ui.NewStyle(ui.ColorYellow)
fa.Widget.WrapText = false
fa.Widget.SetRect(fa.x1, fa.y1, fa.x2, fa.y2)
fa.Widget.BorderStyle.Fg = ui.ColorWhite
currentFS := yamlconf.CurrentFontSize(fileContent)
for i, fontSize := range fa.Widget.Rows {
fs, _ := strconv.Atoi(fontSize)
if currentFS == fs {
fa.Widget.SelectedRow = i
}
}
}
func (fa *FontsizeAdjuster) SetState() string {
for {
uiEvents := ui.PollEvents()
e := <-uiEvents
switch e.ID {
case "<C-c>", "q", "H", "J", "K", "L":
return e.ID
case "j", "<Down>":
fa.Widget.ScrollDown()
case "k", "<Up>":
fa.Widget.ScrollUp()
}
newFS, _ := strconv.Atoi(fa.Widget.Rows[fa.Widget.SelectedRow])
yamlconf.ChangeFontSize(fa.yamlConfig, newFS)
yamlconf.ApplyChanges(*(fa.yamlConfig))
ui.Render(fa.Widget)
}
}