-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestkey.nim
232 lines (167 loc) · 4.92 KB
/
testkey.nim
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
import termkey
import strformat
import std/math
initTerm(20,80,"Test KEYBOARD")
#initTerm()
setBackgroundColor(bgBlue)
eraseTerm()
var cX,cY:Natural
var scrollX,scrollY,scrollP,scrollI,scrollL,scrollM,scrollN,scrollR:Natural
var bScroll : bool = false
# table
type records = ref object
CID : int64
NOM : string
var enrg : seq[records] = @[]
defCursor(cBlink)
onCursor()
gotoXY(1,1)
onMouse()
while true:
var (key, chr) = getTKey()
#gotoXY(1,1)
#stdout.write(fmt" ")
case key
of TKey.Escape: closeTerm()
of TKey.F1 : onMouse()
of TKey.F2 : offMouse()
of TKey.F3 :
offCursor()
for i in 2..20:
gotoXY(i,1)
stdout.write(fmt"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
scrollP = 10 # nbr line /page
scrollI = 6 # init posx
scrollM = scrollP + scrollI - 1 # max line
scrollY = 10 # cursorY
scrollX = scrollI - 1 # posX line
scrollN = 0 # text n° line
scrollR = 0 # max n° Line
scrollL = 0 # last n° Line
bScroll = onScroll(scrollI,scrollM) # 6 = start ligne nbr ligne par page = 10
gotoXY(scrollX,scrollY)
of TKey.F4 :
# origine
resizeTerm(42,132)
titleTerm("VTE-TERM3270")
eraseTerm()
of TKey.F5:
if bScroll :
if ( scrollX < scrollM ) :
inc(scrollX)
scrollL = 0
enrg.add(records(CID:scrollR+1,NOM:fmt" num {scrollR+1}"))
gotoXY(scrollX,scrollY)
stdout.write(fmt"{enrg[scrollR].CID} {enrg[scrollR].NOM}")
inc(scrollR)
scrollN = scrollR
of TKey.PageUp:
if bScroll :
clearScrool(scrollP) # clear page
if scrolln > 0 :
scrollL = 0
if scrollN >= scrollP : scrollX = scrollM
var p = floordiv(scrollN,scrollP)
var r = floormod(scrollN,scrollP)
if p == 0:
for i in 1..scrollP:
if scrollN == 1 : break
dec(scrollN)
if p >= 1 and r > 0 :
for i in 1..scrollP + r - 1:
if scrollN == 1 : break
dec(scrollN)
elif p >= 1 and r == 0 :
for i in 1..scrollP * 2:
if scrollN == 1 : break
dec(scrollN)
scrollL = scrollN
for i in scrollI..scrollM:
gotoXY(i,scrollY)
stdout.write(fmt"{enrg[scrollL-1].CID} {enrg[scrollL-1].NOM}")
scrollX = i
if scrollL == scrollR : break
inc(scrollL)
of TKey.PageDown:
if bScroll :
clearScrool(scrollP) #clear page
if scrollN < scrollR and scrollL > 0 : scrollN = scrollL
if scrollN <= scrollR :
scrollL = 0
for i in scrollI..scrollM:
gotoXY(i,scrollY)
stdout.write(fmt"{enrg[scrollN-1].CID} {enrg[scrollN-1].NOM}") # simulation file display
scrollX = i
if scrollN == scrollR : break
inc(scrollN)
# /.../ F5 manuel ;)
of TKey.F6 :
bScroll = offScroll()
bScroll = false
scrollX = 1
scrollY = 1
onCursor()
of TKey.F7 :
var mask : string
for u in 1..132 :
mask = mask & "."
for i in 1..50 :
gotoXY(i , 1)
stdout.write(mask)
gotoXY(i , 1)
stdout.write(fmt"{i} ")
gotoXY(1 , 1)
of TKey.F8: offCursor()
of TKey.F9: onCursor()
of TKey.F10:
resizeTerm(20,80)
of TKey.F11:
titleTerm("Test KEYBOARD")
of TKey.F12 :
getCursor(cX , cY)
stdout.write(fmt"CursX > {cX} CursY > {cY}")
gotoXY(cX , cY)
of TKey.Up:
cursorUp()
of TKey.Down:
cursorDown()
of TKey.Left:
cursorBackward()
of TKey.Right:
cursorForward()
of TKey.Mouse :
let mi = getMouse()
if mi.action == MouseButtonAction.mbaPressed:
# work this first /.../ bla bla
case mi.button
of mbLeft:
gotoXY(mi.x,mi.y)
of mbMiddle:
gotoXY(mi.x,mi.y)
of mbRight:
gotoXY(mi.x,mi.y)
else: discard
#elif mi.action == MouseButtonAction.mbaReleased:
#gotoXY(mi.x,mi.y)
case mi.scrollDir :
of sdDown : gotoXY(1,30)
of sdUp : gotoXY(1,30)
else: discard
stdout.write fmt"CursX > {mi.x} CursY > {mi.y}" # attention scrollDir
gotoXY(mi.x,mi.y)
key = getMouseBtn()
let zkey = getFunc(true)
of TKey.Char:
gotoXPos(1)
stdout.write(fmt"char :{chr} ")
if chr == $Tcar.Expo2 :
gotoXPos(1)
stdout.write(fmt"char :{chr} Tcar.Expo2")
else : discard
if not bScroll :
gotoXY(1,1)
stdout.write(fmt" ")
gotoXY(1,1)
stdout.write(fmt"key :{key} {'\n'}")
stdout.flushFile
stdin.flushFile