-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkeyb.c
80 lines (71 loc) · 2.07 KB
/
keyb.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
/*
======================================================================
Module to control keyboard input.
@author : Velorek
@version : 1.0
LAST MODIFIED : 14/04/2019 Rename headers
======================================================================
*/
/*====================================================================*/
/* COMPILER DIRECTIVES AND INCLUDES */
/*====================================================================*/
#include <stdio.h>
#include "rterm.h"
#include "keyb.h"
/*====================================================================*/
/* FUNCTIONS - CODE */
/*====================================================================*/
/*----------------------------------*/
/* Read ESC-key char with its trail */
/*----------------------------------*/
int read_keytrail(char chartrail[5])
{
/*
New implementation: Trail of chars found in keyboard.c
If K_ESCAPE is captured read a trail up to 5 characters from the console.
This is to control the fact that some keys may change
according to the terminal and expand the editor's possibilities.
Eg: F2 can be either 27 79 81 or 27 91 91 82.
*/
char ch;
int i;
chartrail[0] = K_ESCAPE;
for (i = 1; i < 5; i++) {
if (kbhit(1) == 1) {
ch = readch();
chartrail[i] = ch;
} else {
chartrail[i] = 0;
}
}
resetch();
return 1;
}
/*----------------------------------*/
/* Read Accents and Special Chars */
/*----------------------------------*/
int read_accent(char *ch, char accentchar[2])
{
/*
Input Ref: ch, accentchar
@return : 1 - SET 1 | 2 - SET 2 | 0 - NO ACCENT CHAR
*/
int result;
result = 0;
//Accents and special chars
accentchar[0] = 0;
accentchar[1] = *ch;
if (*ch == SPECIAL_CHARS_SET1) {
accentchar[0] = SPECIAL_CHARS_SET1; //Accents and special chars SET1
accentchar[1] = readch();
result = 1;
resetch();
}
if (*ch == SPECIAL_CHARS_SET2) {
accentchar[0] = SPECIAL_CHARS_SET2; //Accents and special chars SET2
accentchar[1] = readch();
result = 2;
resetch();
}
return result;
}