44#include  < thread> 
55#include  " private/platform.hpp" 
66
7- int  Term::read_key () {
8-     int  key{};
9-     while  ((key = read_key0 ()) == 0 ) {
7+ bool  Term::is_ASCII (const  Term::Key& key) {
8+     if  (key >= 0  && key <= 127 )
9+         return  true ;
10+     else 
11+         return  false ;
12+ }
13+ 
14+ bool  Term::is_extended_ASCII (const  Term::Key& key) {
15+     if  (key >= 0  && key <= 255 )
16+         return  true ;
17+     else 
18+         return  false ;
19+ }
20+ 
21+ bool  Term::is_CTRL (const  Term::Key& key) {
22+     //  Need to supress the TAB etc...
23+     if  (key > 0  && key <= 31  && key != Key::BACKSPACE && key != Key::TAB &&
24+         key != ESC && /*  the two mapped to ENTER */ 
25+         return  true ;
26+     else 
27+         return  false ;
28+ }
29+ 
30+ bool  Term::is_ALT (const  Term::Key& key) {
31+     if  ((key & Key::ALT) == Key::ALT)
32+         return  true ;
33+     else 
34+         return  false ;
35+ }
36+ 
37+ std::int32_t  Term::read_key () {
38+     std::int32_t  key{Key::NO_KEY};
39+     while  ((key = read_key0 ()) == Key::NO_KEY) {
1040        std::this_thread::sleep_for (std::chrono::milliseconds (10 ));
1141    }
1242    return  key;
1343}
1444
15- int  Term::read_key0 () {
16-     char  c{};
45+ std:: int32_t  Term::read_key0 () {
46+     char  c{' \0 ' 
1747    if  (!Private::read_raw (&c))
18-         return  0 ;
19- 
20-     if  (c == ' \x1b ' 
21-         char  seq[4 ];
48+         return  Key::NO_KEY;
49+     if  (is_CTRL (static_cast <Term::Key>(c))) {
50+         return  c;
51+     } else  if  (c == Key::ESC) {
52+         char  seq[4 ]{' \0 ' ' \0 ' ' \0 ' ' \0 ' 
2253
2354        if  (!Private::read_raw (&seq[0 ]))
2455            return  Key::ESC;
@@ -152,13 +183,11 @@ int Term::read_key0() {
152183        return  -4 ;
153184    } else  {
154185        switch  (c) {
155-             case  ' \x09 ' //  TAB
156-                 return  Key::TAB;
157-             case  ' \x0a ' //  LF; falls-through
158-             case  ' \x0d ' //  CR
159-                 return  Key::ENTER;
160-             case  ' \x7f ' //  DEL
186+             case  Key::DEL:
161187                return  Key::BACKSPACE;
188+             case  Key::LF:
189+             case  Key::CR:
190+                 return  Key::ENTER;
162191        }
163192        if  (c == ' \xc3 ' 
164193            if  (!Private::read_raw (&c)) {
@@ -202,4 +231,4 @@ std::string Term::read_stdin_alone() {
202231    //  temporarily enable raw mode
203232    Term::Terminal term (false , true , false , false );
204233    return  Term::read_stdin ();
205- }
234+ }
0 commit comments