main() { int i; char buf[1024]; STD_TERM *term; term = Init_Terminal(); Write_Char('-', 50); WRITE_STR("\r\n"); #ifdef WIN32 test(term, "text\010\010st\n"); //bs bs test(term, "test\001xxxx\n"); // home test(term, "test\001\005xxxx\n"); // home test(term, "\033[A\n"); // up arrow #endif do { WRITE_STR(">> "); i = Read_Line(term, buf, 1000); printf("len: %d %s\r\n", i, term->out); } while (i > 0); Quit_Terminal(term); }
*/ static int Read_Bytes(STD_TERM *term, char *buf, int len) /* ** Read the next "chunk" of data into the terminal buffer. ** ***********************************************************************/ { int end; // If we have leftovers: if (term->residue[0]) { end = strlen(term->residue); if (end < len) len = end; strncpy(buf, term->residue, len); // terminated below memmove(term->residue, term->residue+len, end-len); // remove term->residue[end-len] = 0; } else { // Read next few bytes. We don't know how many may be waiting. // We assume that escape-sequences are always complete in buf. // (No partial escapes.) If this is not true, then we will need // to add an additional "collection" loop here. if ((len = read(0, buf, len)) < 0) { WRITE_STR("\r\nI/O terminated\r\n"); Quit_Terminal(term); // something went wrong exit(100); } } buf[len] = 0; buf[len+1] = 0; DBG_INT("read len", len); return len; }
static void close_stdio(void) { #ifndef HAS_SMART_CONSOLE if (Term_IO) { Quit_Terminal(Term_IO); Term_IO = 0; } #endif if (Std_Echo) { fclose(Std_Echo); Std_Echo = 0; } }