-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinput.fs
170 lines (147 loc) · 3.36 KB
/
input.fs
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
\ RilouwOS 0.1.0
\ Copyright (c) 2018 Jerome Martin
\ Released under the terms of the GNU GPL version 3
\ http://rilouw.eu/project/rilouwos
\ === Input ===
\ Handle the keyboard and read strings in buffers
\ Keyboard layout:
\ Back Up Ok
\ Call2 Left Enter Right Tone
\ Call1 Down Hang
\ 1 o_o 2 abc 3 def
\ 4 ghi 5 jkl 6 mno
\ 7 pqrs 8 tuv 9 wxyz
\ # 0 _ *
'b' constant KEY.BACK
'o' constant KEY.OK
'i' constant KEY.UP
'k' constant KEY.DOWN
'j' constant KEY.LEFT
'l' constant KEY.RIGHT
'e' constant KEY.ENTER
'c' constant KEY.CALL1
'v' constant KEY.CALL2
'h' constant KEY.HANG
't' constant KEY.TONE
'1' constant KEY.1REC
'2' constant KEY.2ABC
'3' constant KEY.3DEF
'4' constant KEY.4GHI
'5' constant KEY.5JKL
'6' constant KEY.6MNO
'7' constant KEY.7PQRS
'8' constant KEY.8TUV
'9' constant KEY.9WXYZ
'#' constant KEY.HASH
'0' constant KEY.0SP
'*' constant KEY.STAR
: input.numeric? '0' '9' between ;
: input.alpha? 'a' 'z' between ;
0 constant INPUT-NUM
1 constant INPUT-CLASSIC
2 constant INPUT-DICT
variable ALPHA-LAST-KEY
variable ALPHA-CURSOR
variable ALPHA-CAPS
here
KEY.1REC , ," 1111"
KEY.2ABC , ," abc2"
KEY.3DEF , ," def3"
KEY.4GHI , ," ghi4"
KEY.5JKL , ," jkl5"
KEY.6MNO , ," mno6"
KEY.7PQRS , ," pqrs7"
KEY.8TUV , ," tuv8"
KEY.9WXYZ , ," wxyz9"
KEY.0SP , ," ,.:?!0"
10 3 addr-array ALPHA-TABLE
: input.alpha.force-new ALPHA-LAST-KEY off ;
: input.alpha.toggle-caps ALPHA-CAPS toggle ;
: ?caps ( char -- char )
dup input.alpha?
ALPHA-CAPS @ and
if 32 - then
;
: input.alpha ( num-key -- char replace? )
dup ALPHA-TABLE array-find if abort then
1 idx
over ALPHA-LAST-KEY @ =
if ( key addr )
ALPHA-CURSOR @1+!
ALPHA-CURSOR @
over str.size <
if ALPHA-CURSOR @ +
else 0 ALPHA-CURSOR ! then
str.start c@ ?caps true
else
0 ALPHA-CURSOR !
str.start c@ ?caps false
then ( key char bool )
rot ALPHA-LAST-KEY !
;
:struct input
ubyte input-cursor
rptr input-string
;struct
: input.count ( input -- addr len )
dup s@ input-string 1+ swap
s@ input-cursor
;
: input.empty? ( input -- bool ) s@ input-cursor 0= ;
: input.reset ( input -- )
0 swap s! input-cursor
;
: input.cursor+ ( input -- )
dup s@ input-cursor 1+
swap s! input-cursor
;
: input.cursor- ( input -- )
dup s@ input-cursor 1- 0 max
swap s! input-cursor
;
: (input.can-append?) ( input -- bool )
dup s@ input-cursor
swap s@ input-string c@ <
;
: (input.append-char) ( char input -- )
dup dup s@ input-string 1+
swap s@ input-cursor +
rot swap c!
input.cursor+
;
: input.append { a-key an-input mode -- }
a-key input.numeric?
if
mode
case
INPUT-NUM of
an-input (input.can-append?)
if a-key an-input (input.append-char) then
endof
INPUT-CLASSIC of
a-key input.alpha ( char replace? )
if an-input input.cursor-
else
an-input (input.can-append?)
not if drop exit then
then
an-input (input.append-char)
endof
endcase
then
;
: input.erase ( input -- )
dup input.empty? not
if input.cursor- else drop then
;
: input.allot ( len input -- )
here rot dup c, allot align
swap s! input-string
;
: input.save ( dest input -- )
input.count ( dest orig len )
rot swap ( orig dest len )
2dup swap c!
swap 1+ swap
cmove>
;