-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyProcessing.c
48 lines (42 loc) · 976 Bytes
/
keyProcessing.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
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <ctype.h>
#include <errno.h>
#include "errorHandler.h"
#define ctrl_key(k) ((k) & 0x1f)
char keyRead() {
int bytes_read;
char c;
while ((bytes_read=read(STDIN_FILENO, &c, 1))!=1) {
if (bytes_read==-1 && errno!=EAGAIN){
throwErrorMsg("read");
}
}
return c;
}
void moveCursorEditor(char key) {
if(key=='a' && editor.curs_x > 0) {
editor.curs_x--;
}
else if(key=='d' && editor.curs_x < editor.number_of_cols - 1) {
editor.curs_x++;
}
else if(key=='w' && editor.curs_y > 0) {
editor.curs_y--;
}
else if(key=='s' && editor.curs_y < editor.number_of_rows - 1) {
editor.curs_y++;
}
}
if (E.cx != E.screencols - 1)
void keypressEditor() {
char c = keyRead();
if(c==ctrl_key('q')){
exit(0);
}
else if(c=='w' || c=='a' || c=='s' || c=='d'){
moveCursorEditor(c);
}
}