-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput_Field.cpp
More file actions
55 lines (48 loc) · 1.06 KB
/
Copy pathInput_Field.cpp
File metadata and controls
55 lines (48 loc) · 1.06 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
#include "Input_Field.h"
void Input_Field::make_window() { win = newwin(3, size, start_y, start_x); }
void Input_Field::clear_window() {
wclear(win);
box(win, 0, 0);
mvwprintw(win, 0, 41, "Console");
wrefresh(win);
}
string Input_Field::get_input(string placeholder) {
mvwprintw(win, 1, 1, placeholder.data());
refresh();
wrefresh(win);
int index = 1;
string input = "";
int ch;
int once;
while ((ch = getch()) != '\n') {
if (once) {
clear_window();
wmove(win, 1, 1);
once = 0;
}
if (ch == KEY_BACKSPACE || ch == KEY_DC || ch == 127) {
if (index > 1) {
index--;
mvwaddch(win, 1, index, ' ');
wmove(win, 1, index);
wrefresh(win);
input.pop_back();
}
} else if (index >= 49) {
continue;
} else {
waddch(win, ch);
wrefresh(win);
input.push_back((char)ch);
index++;
}
}
clear_window();
return input;
}
void Input_Field::print_log(string log) {
clear_window();
mvwprintw(win, 1, 1, log.data());
refresh();
wrefresh(win);
}