-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
385 lines (341 loc) · 6.92 KB
/
common.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
package main
import (
"database/sql"
"strings"
)
type Position struct {
rowNum int
start int
end int
}
type Window interface {
drawText()
drawFrame()
drawStatusBar()
}
type dbConfig struct {
Postgres struct {
Host string `json:"host"`
Port string `json:"port"`
User string `json:"user"`
Password string `json:"password"`
DB string `json:"db"`
Test string `json:"test"`
} `json:"postgres"`
Sqlite3 struct {
DB string `json:"db"`
FTS_DB string `json:"fts_db"`
} `json:"sqlite3"`
Options struct {
Type string `json:"type"`
Title string `json:"title"`
} `json:"options"`
}
var z0 = struct{}{}
var Languages = map[string]string{
"golang": "go",
"go": "go",
"cpp": "cpp",
"c++": "cpp",
"python": "python",
}
var sortColumns = map[string]struct{}{
"added": z0,
"modified": z0,
"priority": z0,
}
var navKeys = map[int]struct{}{
ARROW_UP: z0,
ARROW_DOWN: z0,
ARROW_LEFT: z0,
ARROW_RIGHT: z0,
'j': z0,
'k': z0,
'h': z0,
'l': z0,
'g': z0,
'G': z0,
}
var Lsps = map[string]string{
"go": "gopls",
"cpp": "clangd",
"py": "python-language-server",
}
/*
var termcodes = map[int]string{
ARROW_UP: "\x80ku", // could also do with vimKey as <Right>, <Left>, <Up>, <Down>
ARROW_DOWN: "\x80kd",
ARROW_RIGHT: "\x80kr",
ARROW_LEFT: "\x80kl",
BACKSPACE: "\x80kb", //? also works "\x08"
HOME_KEY: "\x80kh",
DEL_KEY: "\x80kD",
PAGE_UP: "\x80kP",
PAGE_DOWN: "\x80kN",
}
*/
var termcodes = map[int]string{
ARROW_UP: "<up>", // could also do with vimKey as <Right>, <Left>, <Up>, <Down>
ARROW_DOWN: "<down>",
ARROW_RIGHT: "<right>",
ARROW_LEFT: "<left>",
BACKSPACE: "<bs>", //? also works "\x08"
HOME_KEY: "<home>",
DEL_KEY: "<del>",
PAGE_UP: "<pageup>",
PAGE_DOWN: "<pagedown>",
//0x6: "<c-f>",
//<end> <tab> <insert> <cr> or <enter> <f1> ... <f12>
}
type Mode int
const (
NORMAL Mode = iota
PENDING // only editor mode
INSERT
COMMAND_LINE // only in organizer mode
EX_COMMAND // only in editor mode
VISUAL_LINE // only editor mode
VISUAL
REPLACE // only explicit in organizer mode
FILE_DISPLAY // only organizer mode
NO_ROWS
VISUAL_BLOCK // only editor mode
SEARCH // only editor mode
FIND // only organizer mode
ADD_CHANGE_FILTER // only organizer mode
SYNC_LOG // only organizer mode
PREVIEW // only editor mode - for previewing markdown
VIEW_LOG // only in editor mode - for debug viewing of vim message hx
SPELLING // this mode recognizes 'z='
PREVIEW_SYNC_LOG // only in organizer mode
LINKS // only in organizer mode
VISUAL_MODE
)
var modeMap = map[int]Mode{
1: NORMAL,
2: VISUAL, //VISUAL_MODE,
4: PENDING,
8: SEARCH, // Also COMMAND
16: INSERT,
}
// v -> 118; V -> 86; ctrl-v -> 22
var visualModeMap = map[int]Mode{
22: VISUAL_BLOCK,
86: VISUAL_LINE,
118: VISUAL,
}
const (
TZ_OFFSET = 4
LINKED_NOTE_HEIGHT = 20
TOP_MARGIN = 1
MAX = 500
TIME_COL_WIDTH = 18
LEFT_MARGIN = 1
LEFT_MARGIN_OFFSET = 4
BASE_DATE string = "1970-01-01 00:00"
RESET string = "\x1b[0m"
BLACK string = "\x1b[30m"
RED string = "\x1b[31m"
GREEN string = "\x1b[32m"
YELLOW string = "\x1b[33m"
BLUE string = "\x1b[34m"
MAGENTA string = "\x1b[35m"
CYAN string = "\x1b[36m"
WHITE string = "\x1b[37m"
RED_BOLD string = "\x1b[1;31m"
GREEN_BOLD string = "\x1b[1;32m"
YELLOW_BOLD string = "\x1b[1;33m"
BLUE_BOLD string = "\x1b[1;34m"
MAGENTA_BOLD string = "\x1b[1;35m"
CYAN_BOLD string = "\x1b[1;36m"
WHITE_BOLD string = "\x1b[1;37m"
RED_BG string = "\x1b[41m"
GREEN_BG string = "\x1b[42m"
YELLOW_BG string = "\x1b[43m"
BLUE_BG string = "\x1b[44m"
MAGENTA_BG string = "\x1b[45m"
CYAN_BG string = "\x1b[46m"
WHITE_BG string = "\x1b[47m"
DEFAULT_BG string = "\x1b[49m"
// 8bit 256 color 48;5 => background
LIGHT_GRAY_BG string = "\x1b[48;5;242m"
DARK_GRAY_BG string = "\x1b[48;5;236m"
BOLD string = "\x1b[1m"
maxUint = ^uint(0)
maxInt = int(maxUint >> 1)
)
func ctrlKey(b byte) int { //rune
return int(b & 0x1f)
}
func truncate(s string, length int) string {
if len(s) > length {
return s[:length] + "..."
} else {
return s
}
}
func tc(s string, l int, b bool) string {
if len(s) > l {
e := ""
if b {
e = "..."
}
return s[:l] + e
} else {
return s
}
}
type Row struct {
id int
tid int
title string
ftsTitle string
star bool
deleted bool
archived bool
//modified string
sort string
// below not in db
dirty bool
marked bool
}
type AltRow struct {
id int
title string
star bool
}
// used in synchronize and getEntryInfo
type NewEntry struct {
id int
tid int
title string
folder_tid int
context_tid int
star bool
note sql.NullString //string
added string
archived bool
deleted bool
modified string
}
type Entry struct {
id int
tid int
title string
folder_tid int
context_tid int
star bool
note sql.NullString //string
added sql.NullString
completed sql.NullString
deleted bool
modified string
}
type serverEntry struct {
id int
title string
folder_id int
context_id int
star bool
note sql.NullString //string
added sql.NullString //string
completed sql.NullString //sql.NullTime since sqlite doesn't have datetime type
deleted bool
modified string
}
type Container struct {
id int
tid int
title string
star bool
deleted bool
modified string
count int
}
//type outlineKey int
const (
BACKSPACE = iota + 127
ARROW_LEFT = iota + 999 //would have to be < 127 to be chars
ARROW_RIGHT
ARROW_UP
ARROW_DOWN
DEL_KEY
HOME_KEY
END_KEY
PAGE_UP
PAGE_DOWN
NOP
SHIFT_TAB
)
func (m Mode) String() string {
return [...]string{
"NORMAL",
"PENDING",
"INSERT",
"COMMAND LINE",
"EX COMMAND",
"VISUAL LINE",
"VISUAL",
"REPLACE",
"FILE DISPLAY",
"NO ROWS",
"VISUAL BLOCK",
"SEARCH",
"FIND",
"ADD/CHANGE FILTER",
"SYNC LOG",
"PREVIEW",
"VIEW LOG",
"SPELLING",
"PREVIEW_SYNC_LOG",
"LINKS",
}[m]
}
type View int
const (
TASK View = iota
CONTEXT
FOLDER
KEYWORD
//SYNC_LOG_VIEW
)
func (v View) String() string {
return [...]string{
"task",
"context",
"folder",
"keyword",
}[v]
}
//type TaskView int
const (
BY_CONTEXT = iota
BY_FOLDER
BY_KEYWORD
BY_JOIN
BY_RECENT
BY_FIND
)
const leader = " "
func getStringInBetween(str string, start string, end string) string {
k, v, ok := strings.Cut(str, start)
if !ok {
return ""
}
k, v, ok = strings.Cut(v, start)
if !ok {
return ""
}
return k
}
/*
type BufLinesEvent struct {
Buffer nvim.Buffer
//Changetick int64
Changetick interface{} //int64
FirstLine interface{} //int64
LastLine interface{} //int64
LineData string
IsMultipart bool
}
*/