-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.cpp
54 lines (38 loc) · 1.23 KB
/
example.cpp
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
#include <iostream>
#include "include/termiospp"
std::string get_input() {
std::string str; char ch;
while((ch = getchar())) {
if(ch != '\n') {
// escape sequence
if(ch == 27) {
ch = getchar();
ch = getchar(); continue;
}
// backspace
if(ch == 0x7f) {
if(str.length() >= 1) {
std::cout << "\b \b";
str.pop_back() ;
}
continue;
}
std::cout << ch << std::flush;
str.push_back(ch);
continue;
}
break;
}
return str;
}
int main() noexcept {
Termios new_termio, old_termio;
TermiosFlag local_flag ;
term::get_attribute (0, &old_termio); new_termio = old_termio;
new_termio.set_local_flag(local_flag &= ~TERMIOS_I_CANON);
new_termio.set_local_flag(local_flag &= ~TERMIOS_ECHO );
term::set_attribute (0, TERMIOS_SA_NOW, &new_termio );
std::cout << "(?) > " << std::flush; std::string str = get_input(); std::cout << '\n';
std::cout << "output: " << str << '\n';
term::set_attribute(0, TERMIOS_SA_NOW, &old_termio);
}