/
screen_about.go
146 lines (135 loc) · 4.44 KB
/
screen_about.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main
import (
"fmt"
termboxUtil "github.com/br0xen/termbox-util"
"github.com/nsf/termbox-go"
)
/*
Command is a struct for associating descriptions to keys
*/
type Command struct {
key string
description string
}
/*
AboutScreen is just a basic 'int' type that we can extend to make this screen
*/
type AboutScreen int
func drawCommandAtPoint(cmd Command, xPos int, yPos int, style Style) {
termboxUtil.DrawStringAtPoint(fmt.Sprintf("%6s", cmd.key), xPos, yPos, style.defaultFg, style.defaultBg)
termboxUtil.DrawStringAtPoint(cmd.description, xPos+8, yPos, style.defaultFg, style.defaultBg)
}
func (screen *AboutScreen) handleKeyEvent(event termbox.Event) int {
return BrowserScreenIndex
}
func (screen *AboutScreen) performLayout() {}
func (screen *AboutScreen) drawScreen(style Style) {
defaultFg := style.defaultFg
defaultBg := style.defaultBg
width, height := termbox.Size()
template := [...]string{
" _______ _______ ___ _______ _______ ______ _______ _ _ _______ _______ ______ ",
"| _ || || | | || _ || _ | | || | _ | || || || _ | ",
"| |_| || _ || | |_ _|| |_| || | || | _ || || || || _____|| ___|| | || ",
"| || | | || | | | | || |_||_ | | | || || |_____ | |___ | |_||_ ",
"| _ | | |_| || |___ | | | _ | | __ || |_| || ||_____ || ___|| __ |",
"| |_| || || || | | |_| || | | || || _ | _____| || |___ | | | |",
"|_______||_______||_______||___| |_______||___| |_||_______||__| |__||_______||_______||___| |_|",
}
if width < 100 {
template = [...]string{
" ____ ____ _ _____ ____ ____ ____ _ _ ____ ___ ____ ",
"| _ || || | | || _ || _ | | || | _ | || || || _ | ",
"| |_||| _ || | |_ _|| |_||| | || | _ || || || || ___|| _|| | || ",
"| ||| | || | | | | || |_|| || | || |||___ | |_ | |_||_ ",
"| _ |||_| || |___| | | _ || _ |||_| || ||__ || _|| __ |",
"| |_||| || | | | |_||| | | || || _ | __| || |_ | | | |",
"|____||____||_____|_| |____||_| |_||____||__| |__||____||___||_| |_|",
}
}
firstLine := template[0]
startX := (width - len(firstLine)) / 2
//startX := (width - len(firstLine)) / 2
startY := ((height - 2*len(template)) / 2) - 2
xPos := startX
yPos := startY
if height <= 20 {
title := "BoltBrowser"
startY = 0
yPos = 0
termboxUtil.DrawStringAtPoint(title, (width-len(title))/2, startY, style.titleFg, style.titleBg)
} else {
if height < 25 {
startY = 0
yPos = 0
}
for _, line := range template {
xPos = startX
for _, runeValue := range line {
bg := defaultBg
displayRune := ' '
if runeValue != ' ' {
//bg = termbox.Attribute(125)
displayRune = runeValue
termbox.SetCell(xPos, yPos, displayRune, defaultFg, bg)
}
xPos++
}
yPos++
}
}
yPos++
versionString := fmt.Sprintf("Version: %0.1f", VersionNum)
termboxUtil.DrawStringAtPoint(versionString, (width-len(versionString))/2, yPos, style.defaultFg, style.defaultBg)
commands1 := []Command{
{"h,←", "close parent"},
{"j,↓", "down"},
{"k,↑", "up"},
{"l,→", "open item"},
{"J", "scroll right pane down"},
{"K", "scroll right pane up"},
{"", ""},
{"g", "goto top"},
{"G", "goto bottom"},
{"", ""},
{"ctrl+f", "jump down"},
{"ctrl+b", "jump up"},
}
commands2 := []Command{
{"p,P", "create pair/at parent"},
{"b,B", "create bucket/at parent"},
{"e", "edit value of pair"},
{"r", "rename pair/bucket"},
{"", ""},
{"D", "delete item"},
{"x,X", "export as string/json to file"},
{"i", "import file to value of pair"},
{"", ""},
{"?", "this screen"},
{"q", "quit program"},
}
var maxCmd1 int
for k := range commands1 {
tst := len(commands1[k].key) + 1 + len(commands1[k].description)
if tst > maxCmd1 {
maxCmd1 = tst
}
}
var maxCmd2 int
for k := range commands2 {
tst := len(commands2[k].key) + 1 + len(commands2[k].description)
if tst > maxCmd2 {
maxCmd2 = tst
}
}
xPos = (width / 2) - ((maxCmd1 + maxCmd2) / 2)
yPos++
for k := range commands1 {
drawCommandAtPoint(commands1[k], xPos, yPos+1+k, style)
}
for k := range commands2 {
drawCommandAtPoint(commands2[k], xPos+40, yPos+1+k, style)
}
exitTxt := "Press any key to return to browser"
termboxUtil.DrawStringAtPoint(exitTxt, (width-len(exitTxt))/2, height-1, style.titleFg, style.titleBg)
}