forked from lmorg/readline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabgrid.go
131 lines (107 loc) · 2.18 KB
/
tabgrid.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
package readline
import (
"strconv"
)
func (rl *Instance) initTabGrid() {
width := GetTermWidth()
var suggestions []string
if rl.modeTabFind {
suggestions = rl.tfSuggestions
} else {
suggestions = rl.tcSuggestions
}
tcMaxLength := 1
for i := range suggestions {
if len(rl.tcPrefix+suggestions[i]) > tcMaxLength {
tcMaxLength = len([]rune(rl.tcPrefix + suggestions[i]))
}
}
rl.modeTabCompletion = true
rl.tcPosX = 1
rl.tcPosY = 1
rl.tcMaxX = width / (tcMaxLength + 2)
rl.tcOffset = 0
// avoid a divide by zero error
if rl.tcMaxX < 1 {
rl.tcMaxX = 1
}
rl.tcMaxY = rl.MaxTabCompleterRows
}
func (rl *Instance) moveTabGridHighlight(x, y int) {
var suggestions []string
if rl.modeTabFind {
suggestions = rl.tfSuggestions
} else {
suggestions = rl.tcSuggestions
}
rl.tcPosX += x
rl.tcPosY += y
if rl.tcPosX < 1 {
rl.tcPosX = rl.tcMaxX
rl.tcPosY--
}
if rl.tcPosX > rl.tcMaxX {
rl.tcPosX = 1
rl.tcPosY++
}
if rl.tcPosY < 1 {
rl.tcPosY = rl.tcUsedY
}
if rl.tcPosY > rl.tcUsedY {
rl.tcPosY = 1
}
if rl.tcPosY == rl.tcUsedY && (rl.tcMaxX*(rl.tcPosY-1))+rl.tcPosX > len(suggestions) {
if x < 0 {
rl.tcPosX = len(suggestions) - (rl.tcMaxX * (rl.tcPosY - 1))
}
if x > 0 {
rl.tcPosX = 1
rl.tcPosY = 1
}
if y < 0 {
rl.tcPosY--
}
if y > 0 {
rl.tcPosY = 1
}
}
/*if !rl.modeTabFind && len(suggestions) > 0 {
cell := (rl.tcMaxX * (rl.tcPosY - 1)) + rl.tcOffset + rl.tcPosX - 1
description := rl.tcDescriptions[suggestions[cell]]
if description != "" {
rl.hintText = []rune(description)
} else {
rl.getHintText()
}
}*/
}
func (rl *Instance) writeTabGrid() {
var suggestions []string
if rl.modeTabFind {
suggestions = rl.tfSuggestions
} else {
suggestions = rl.tcSuggestions
}
print(seqClearScreenBelow + "\r\n")
cellWidth := strconv.Itoa((GetTermWidth() / rl.tcMaxX) - 2)
x := 0
y := 1
for i := range suggestions {
x++
if x > rl.tcMaxX {
x = 1
y++
if y > rl.tcMaxY {
y--
break
} else {
print("\r\n")
}
}
if x == rl.tcPosX && y == rl.tcPosY {
print(seqBgWhite + seqFgBlack)
}
printf(" %-"+cellWidth+"s %s", rl.tcPrefix+suggestions[i], seqReset)
}
rl.tcUsedY = y
}