6 class Filter_console : public Console
10 Filter_console( Console *o, int to = 10 );
13 int write( char const *str, size_t len );
14 int getchar( bool blocking = true );
15 int char_avail() const;
23 GOT_CSI, ///< control sequence introducer
38 #include "delayloop.h"
42 int Filter_console::char_avail() const
51 return _o->char_avail();
60 Filter_console::Filter_console( Console *o, int to )
61 : _o(o), csi_timeout(to), state(NORMAL), pos(0), arg(0)
68 Filter_console::~Filter_console()
72 int Filter_console::write( char const *str, size_t len )
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 ) {
85 _o->write(start, stop-start);
91 _o->write(start, stop-start);
97 _o->write(start, stop-start);
98 if(stop + 2 < str+len) {
99 snprintf(seq, sizeof(seq), "\033[%d;%dH", stop[1]+1,stop[2]+1);
100 _o->write(seq,strlen(seq));
109 _o->write(start, stop-start);
115 int Filter_console::getchar_timeout( unsigned timeout )
118 while((c= _o->getchar(false)) == -1 && timeout--)
125 int Filter_console::getchar( bool b )
127 unsigned loop_count = 100;
131 if(state==UNKNOWN_ESC && pos)
134 memmove(ibuf,ibuf+1,--pos);
146 else if( !b && loop_count-- )
161 int nc = getchar_timeout(csi_timeout);
169 if(pos < sizeof(ibuf))
171 if(nc=='[' || nc=='O')
174 memset(args,0,sizeof(args));
190 if(pos < sizeof(ibuf))
193 if(arg < (sizeof(args)/sizeof(int)))
194 args[arg] = args[arg]*10 + (ch-'0');
198 if(pos < sizeof(ibuf))
206 if(pos < sizeof(ibuf))
211 case 'A': pos = 0; return KEY_CURSOR_UP;
212 case 'B': pos = 0; return KEY_CURSOR_DOWN;
213 case 'C': pos = 0; return KEY_CURSOR_RIGHT;
214 case 'D': pos = 0; return KEY_CURSOR_LEFT;
215 case 'H': pos = 0; return KEY_CURSOR_HOME;
216 case 'F': pos = 0; return KEY_CURSOR_END;
222 case 1: return KEY_CURSOR_HOME;
223 case 2: return KEY_INSERT;
224 case 3: return KEY_DELETE;
226 case 4: return KEY_CURSOR_END;
227 case 5: return KEY_PAGE_UP;
228 case 6: return KEY_PAGE_DOWN;
229 case 11: return KEY_F1;
243 case 'P': return KEY_F1;
267 Filter_console::get_attributes() const
269 return _o->get_attributes();