6 class Filter_console : public Console
18 GOT_CSI, ///< control sequence introducer
35 #include "delayloop.h"
39 int Filter_console::char_avail() const
48 return _o->char_avail();
55 PUBLIC inline explicit
56 Filter_console::Filter_console(Console *o, int to = 10)
57 : _o(o), csi_timeout(to), state(NORMAL), pos(0), arg(0)
66 Filter_console::write(char const *str, size_t len)
68 char const *start = str;
69 char const *stop = str;
72 char const *const home = "\033[H";
73 char const *const cel = "\033[K";
75 for (;stop < str + len; ++stop)
81 _o->write(start, stop-start);
87 _o->write(start, stop-start);
93 _o->write(start, stop-start);
94 if (stop + 2 < str+len)
96 snprintf(seq, sizeof(seq), "\033[%d;%dH", stop[1]+1,stop[2]+1);
97 _o->write(seq,strlen(seq));
106 _o->write(start, stop-start);
113 Filter_console::getchar_timeout(unsigned timeout)
116 while ((c= _o->getchar(false)) == -1 && timeout--)
124 Filter_console::getchar(bool b = true)
126 unsigned loop_count = 100;
130 if (state==UNKNOWN_ESC && pos)
133 memmove(ibuf,ibuf+1,--pos);
145 else if (!b && loop_count--)
160 int nc = getchar_timeout(csi_timeout);
168 if (pos < sizeof(ibuf))
170 if (nc=='[' || nc=='O')
173 memset(args,0,sizeof(args));
189 if (pos < sizeof(ibuf))
192 if (arg < (sizeof(args)/sizeof(int)))
193 args[arg] = args[arg]*10 + (ch-'0');
197 if (pos < sizeof(ibuf))
205 if (pos < sizeof(ibuf))
210 case 'A': pos = 0; return KEY_CURSOR_UP;
211 case 'B': pos = 0; return KEY_CURSOR_DOWN;
212 case 'C': pos = 0; return KEY_CURSOR_RIGHT;
213 case 'D': pos = 0; return KEY_CURSOR_LEFT;
214 case 'H': pos = 0; return KEY_CURSOR_HOME;
215 case 'F': pos = 0; return KEY_CURSOR_END;
221 case 1: return KEY_CURSOR_HOME;
222 case 2: return KEY_INSERT;
223 case 3: return KEY_DELETE;
225 case 4: return KEY_CURSOR_END;
226 case 5: return KEY_PAGE_UP;
227 case 6: return KEY_PAGE_DOWN;
228 case 11: return KEY_F1;
242 case 'P': return KEY_F1;
265 Filter_console::get_attributes() const
267 return _o->get_attributes();