-
Notifications
You must be signed in to change notification settings - Fork 34
/
widget_cursor.go
192 lines (187 loc) Β· 5.33 KB
/
widget_cursor.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package main
import "fmt"
type CursorWidget int
func (widget CursorWidget) sizeForLayout(layout Layout) Size {
runeCount := 0
height := 2
if layout.show_date {
height = 4
}
if layout.pressure < 5 || layout.pressure == 6 {
for _, _ = range "Cursor: " {
runeCount++
}
}
if layout.pressure < 6 {
for _, _ = range "(t)ext (p)attern (i)nteger (f)loat" {
runeCount++
}
} else if layout.pressure < 8 {
for _, _ = range "(t)ext (p)attern" {
/* (i)nteger (f)loat
(e)ndian (u)nsigned */
runeCount++
}
if height < 3 {
height = 3
}
} else {
for _, _ = range "(u)nsigned" {
runeCount++
}
height = 6
}
return Size{runeCount, height}
}
func (widget CursorWidget) drawAtPoint(tab *DataTab, layout Layout, point Point, style Style) Size {
fg := style.default_fg
bg := style.default_bg
cursor := tab.cursor
x_pos := point.x
y_pos := point.y
max_x_pos := x_pos
pressure := layout.pressure
data := tab.bytes[cursor.pos : cursor.pos+cursor.length()]
if pressure < 5 || pressure == 6 {
x_pos += drawStringAtPoint("Cursor: ", x_pos, y_pos, fg, bg)
}
if cursor.mode == StringMode {
x_pos += drawStringAtPoint("(t)ext", x_pos, y_pos, fg, cursor.color(style))
} else {
x_pos += drawStringAtPoint("(t)ext", x_pos, y_pos, fg, bg)
}
if pressure < 6 {
x_pos++
} else if pressure < 8 {
x_pos += 4
} else {
x_pos = point.x
y_pos++
}
if cursor.mode == BitPatternMode {
x_pos += drawStringAtPoint("(p)attern", x_pos, y_pos, fg, cursor.color(style))
} else {
x_pos += drawStringAtPoint("(p)attern", x_pos, y_pos, fg, bg)
}
if pressure < 6 {
x_pos++
} else if pressure < 7 {
x_pos = point.x + 8
y_pos++
} else {
x_pos = point.x
y_pos++
}
if cursor.mode == IntegerMode {
x_pos += drawStringAtPoint("(i)nteger", x_pos, y_pos, fg, cursor.color(style))
} else {
x_pos += drawStringAtPoint("(i)nteger", x_pos, y_pos, fg, bg)
}
if pressure < 8 {
x_pos++
} else {
x_pos = point.x
y_pos++
}
if cursor.mode == FloatingPointMode {
x_pos += drawStringAtPoint("(f)loat", x_pos, y_pos, fg, cursor.color(style))
} else {
x_pos += drawStringAtPoint("(f)loat", x_pos, y_pos, fg, bg)
}
x_pos = point.x
y_pos++
if pressure < 5 || pressure == 6 {
if cursor.mode == IntegerMode || cursor.mode == FloatingPointMode {
x_pos += drawStringAtPoint("Toggle: ", x_pos, y_pos, fg, bg)
} else {
x_pos += drawStringAtPoint("Toggle: ", x_pos, y_pos, style.space_rune_fg, bg)
}
}
if pressure >= 8 {
x_pos = point.x
}
if cursor.mode == IntegerMode || cursor.mode == FloatingPointMode {
if cursor.big_endian {
x_pos += drawStringAtPoint("(E)ndian", x_pos, y_pos, fg, bg)
} else {
x_pos += drawStringAtPoint("(e)ndian", x_pos, y_pos, fg, bg)
}
x_pos++
} else if cursor.mode == BitPatternMode || cursor.mode == StringMode {
x_pos += drawStringAtPoint("(e)ndian", x_pos, y_pos, style.space_rune_fg, bg)
x_pos++
}
if pressure >= 8 {
x_pos = point.x
y_pos++
} else if pressure >= 6 {
x_pos++
}
if cursor.mode == IntegerMode {
if cursor.unsigned {
x_pos += drawStringAtPoint("(U)nsigned", x_pos, y_pos, fg, bg)
} else {
x_pos += drawStringAtPoint("(u)nsigned", x_pos, y_pos, fg, bg)
}
} else {
x_pos += drawStringAtPoint("(u)nsigned", x_pos, y_pos, style.space_rune_fg, bg)
}
if pressure < 6 {
x_pos += 4
if cursor.mode != StringMode {
x_pos += drawStringAtPoint("Size:", x_pos, y_pos, fg, bg)
if cursor.length() > cursor.minimumLength() {
x_pos += drawStringAtPoint(" βH", x_pos, y_pos, fg, bg)
} else {
x_pos += drawStringAtPoint(" βH", x_pos, y_pos, style.space_rune_fg, bg)
}
if cursor.length() < cursor.maximumLength() {
x_pos += drawStringAtPoint(" βL", x_pos, y_pos, fg, bg)
} else {
x_pos += drawStringAtPoint(" βL", x_pos, y_pos, style.space_rune_fg, bg)
}
} else {
x_pos += drawStringAtPoint("Size: βH βL", x_pos, y_pos, style.space_rune_fg, bg)
}
}
max_x_pos = x_pos
x_pos = point.x - 7
if layout.show_date {
y_pos++
if pressure < 6 {
y_pos++
}
date_fg := style.space_rune_fg
if cursor.mode == IntegerMode || cursor.mode == FloatingPointMode {
date_fg = fg
}
if pressure < 5 || pressure == 6 {
x_pos += drawStringAtPoint(fmt.Sprintf("%7s", "D(a)te:"), x_pos, y_pos, date_fg, bg)
x_pos++
}
x_pos += drawStringAtPoint(fmt.Sprintf("%10s", cursor.interpretBytesAsTime(data).Format("1/2/2006")), x_pos, y_pos, date_fg, bg)
x_pos++
x_pos += drawStringAtPoint(fmt.Sprintf("%8s", cursor.interpretBytesAsTime(data).Format("3:04 PM")), x_pos, y_pos, date_fg, bg)
if pressure < 6 {
x_pos += 2
if date_fg == fg && cursor.epoch_unit == SecondsSinceEpoch {
x_pos += drawStringAtPoint("(s)ecs", x_pos, y_pos, date_fg, style.selected_option_bg)
} else {
x_pos += drawStringAtPoint("(s)ecs", x_pos, y_pos, date_fg, bg)
}
x_pos++
if date_fg == fg && cursor.epoch_unit == MilliSecondsSinceEpoch {
x_pos += drawStringAtPoint("(m)sec", x_pos, y_pos, date_fg, style.selected_option_bg)
} else {
x_pos += drawStringAtPoint("(m)sec", x_pos, y_pos, date_fg, bg)
}
x_pos++
if date_fg == fg && cursor.epoch_unit == DaysSinceEpoch {
x_pos += drawStringAtPoint("(d)ays", x_pos, y_pos, date_fg, style.selected_option_bg)
} else {
x_pos += drawStringAtPoint("(d)ays", x_pos, y_pos, date_fg, bg)
}
}
}
return Size{max_x_pos - point.x, y_pos - point.y + 1}
}