-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen2.h
More file actions
57 lines (48 loc) · 1.51 KB
/
screen2.h
File metadata and controls
57 lines (48 loc) · 1.51 KB
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
void editText(char *buf, int len, int y, int x)
{
unsigned int charCount = 0;
unsigned int pos = 0;
ch = 0;
memset(buf, ' ', len);
while((ch != KEY_ENTER) || (charCount == 0)) {
switch (ch) {
default: // inser mode
if (isprint(ch)) buf[pos] = ch;
// prevent charCount from increasing if we modify a letter in the middle
if (pos == charCount) charCount++;
pos++;
break;
case KEY_BACKSPACE:
if (charCount > 0) {
charCount--;
pos--;
buf[pos] = ' ';
} break;
case KEY_LEFT: if(pos > 0) {pos--;} break;
case KEY_RIGHT: if(pos < charCount) {pos++;} break;
case KEY_UP: break;
case KEY_DOWN: break;
case KEY_ENTER: break;
case TERM_RESIZE: break;
case 0: break;
}
// Draw
for (unsigned int i = 0; i <= charCount; i++) {
mvprintw(y, x+i, "%c ", buf[i]);
}
if (pos == charCount) {
attron(A_BLINK);
mvprintw(y, x+pos, "_");
attroff(A_BLINK);
} else {
attron(A_REVERSE | A_BOLD);
mvprintw(y, x+pos, "%c", buf[pos]);
attroff(A_REVERSE | A_BOLD);
}
getCH();
}
// Erase cursor
mvprintw(y, x+pos, "%c", buf[pos]);
mvprintw(y, x+charCount, " ");
buf[charCount] = '\0';
}