6 class Filter_console : public Console
18 GOT_CSI, ///< control sequence introducer
35 #include "delayloop.h"
39 int Filter_console::char_avail() const
41 if (!(_o->state() & INENABLED))
51 return _o->char_avail();
58 PUBLIC inline explicit
59 Filter_console::Filter_console(Console *o, int to = 10)
60 : Console(ENABLED), _o(o), csi_timeout(to), state(NORMAL), pos(0), arg(0)
69 Filter_console::write(char const *str, size_t len)
71 if (!(_o->state() & OUTENABLED))
74 char const *start = str;
75 char const *stop = str;
78 char const *const home = "\033[H";
79 char const *const cel = "\033[K";
81 for (;stop < str + len; ++stop)
87 _o->write(start, stop-start);
93 _o->write(start, stop-start);
99 _o->write(start, stop-start);
100 if (stop + 2 < str+len)
102 snprintf(seq, sizeof(seq), "\033[%d;%dH", stop[1]+1,stop[2]+1);
103 _o->write(seq,strlen(seq));
112 _o->write(start, stop-start);
119 Filter_console::getchar_timeout(unsigned timeout)
121 if (!(_o->state() & INENABLED))
125 while ((c= _o->getchar(false)) == -1 && timeout--)
133 Filter_console::getchar(bool b = true)
135 if (!(_o->state() & INENABLED))
138 unsigned loop_count = 100;
142 if (state == UNKNOWN_ESC && pos)
145 memmove(ibuf, ibuf + 1, --pos);
157 else if (!b && loop_count--)
172 int nc = getchar_timeout(csi_timeout);
180 if (pos < sizeof(ibuf))
182 if (nc=='[' || nc == 'O')
185 memset(args, 0, sizeof(args));
201 if (pos < sizeof(ibuf))
204 if (arg < (sizeof(args)/sizeof(int)))
205 args[arg] = args[arg]*10 + (ch-'0');
209 if (pos < sizeof(ibuf))
217 if (pos < sizeof(ibuf))
222 case 'A': pos = 0; return KEY_CURSOR_UP;
223 case 'B': pos = 0; return KEY_CURSOR_DOWN;
224 case 'C': pos = 0; return KEY_CURSOR_RIGHT;
225 case 'D': pos = 0; return KEY_CURSOR_LEFT;
226 case 'H': pos = 0; return KEY_CURSOR_HOME;
227 case 'F': pos = 0; return KEY_CURSOR_END;
233 case 1: return KEY_CURSOR_HOME;
234 case 2: return KEY_INSERT;
235 case 3: return KEY_DELETE;
237 case 4: return KEY_CURSOR_END;
238 case 5: return KEY_PAGE_UP;
239 case 6: return KEY_PAGE_DOWN;
240 case 11: return KEY_F1;
254 case 'P': return KEY_F1;
277 Filter_console::get_attributes() const
279 return _o->get_attributes();