-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathte_keys.c
145 lines (124 loc) · 3.08 KB
/
te_keys.c
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
/* te_keys.c
Text editor.
Key bindings.
Copyright (c) 2015-2021 Miguel Garcia / FloppySoftware
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
Changes:
22 Jan 2019 : Start.
23 Jan 2019 : Added GetKeyWhat().
29 Jan 2019 : Added K_CLRCLP.
26 Dec 2019 : Now K_INTRO is K_CR. Add GetKeyName().
04 Apr 2021 : Remove customized key names. Use key bindings from configuration.
11 May 2021 : Update keys purposes.
10 Jul 2021 : Remove SetKey().
*/
/* Return key name
---------------
*/
GetKeyName(key)
int key;
{
switch(key)
{
case K_CR: return cf_cr_name;
case K_ESC: return cf_esc_name;
}
return "?";
}
/* Return key purpose
------------------
*/
GetKeyWhat(key)
int key;
{
/* Max. length of 8 chars., see MenuHelp() */
switch(key)
{
case K_UP: return "Up";
case K_DOWN: return "Down";
case K_LEFT: return "Left";
case K_RIGHT: return "Right";
case K_BEGIN: return "Begin";
case K_END: return "End";
case K_TOP: return "Top";
case K_BOTTOM: return "Bottom";
case K_PGUP: return "PgUp";
case K_PGDOWN: return "PgDown";
case K_TAB: return "Indent";
case K_CR: return "NewLine";
case K_ESC: return "Escape";
case K_RDEL: return "DelRight";
case K_LDEL: return "DelLeft";
case K_CUT: return "Cut";
case K_COPY: return "Copy";
case K_PASTE: return "Paste";
case K_DELETE: return "Delete";
case K_CLRCLP: return "ClearClip";
#if OPT_FIND
case K_FIND: return "Find";
case K_NEXT: return "FindNext";
#endif
#if OPT_GOTO
case K_GOTO: return "GoLine";
#endif
#if OPT_LWORD
case K_LWORD: return "WordLeft";
#endif
#if OPT_RWORD
case K_RWORD: return "WordRight";
#endif
#if OPT_BLOCK
case K_BLK_START: return "BlockStart";
case K_BLK_END: return "BlockEnd";
case K_BLK_UNSET: return "BlockUnset";
#endif
#if OPT_MACRO
case K_MACRO: return "Macro";
#endif
}
return "?";
}
/* Return key from keyboard, according to key bindings
---------------------------------------------------
*/
GetKey()
{
int c, x, i, k;
c = CrtIn();
if(c > 31 && c != 127) {
return c;
}
for(i = 0; i < KEYS_MAX; ++i) {
if(cf_keys[i]) {
if(c == cf_keys[i]) {
if(cf_keys_ex[i]) {
x = toupper(CrtIn());
/* TODO: try to optimize the following */
for(k = i; k < KEYS_MAX; ++k) {
if(c == cf_keys[k]) {
if(x == cf_keys_ex[k]) {
return k + 1000;
}
}
}
break;
}
else {
return i + 1000;
}
}
}
}
return '?';
}