void tty_update_mode(struct tty *tty, int mode) { int changed; if (tty->flags & TTY_NOCURSOR) mode &= ~MODE_CURSOR; changed = mode ^ tty->mode; if (changed & MODE_CURSOR) { if (mode & MODE_CURSOR) tty_putcode(tty, TTYC_CNORM); else tty_putcode(tty, TTYC_CIVIS); } if (changed & MODE_MOUSE) { if (mode & MODE_MOUSE) tty_puts(tty, "\033[?1000h"); else tty_puts(tty, "\033[?1000l"); } if (changed & MODE_KKEYPAD) { if (mode & MODE_KKEYPAD) tty_putcode(tty, TTYC_SMKX); else tty_putcode(tty, TTYC_RMKX); } tty->mode = mode; }
/* ** Print an array of words in columns. */ void el_print_columns(int ac, char **av) { char *p; int i; int j; int k; int len; int skip; int longest; int cols; /* Find longest name, determine column count from that. */ for (longest = 0, i = 0; i < ac; i++) if ((j = strlen((char *)av[i])) > longest) longest = j; cols = tty_cols / (longest + 3); tty_puts(NEWLINE); for (skip = ac / cols + 1, i = 0; i < skip; i++) { for (j = i; j < ac; j += skip) { for (p = av[j], len = strlen((char *)p), k = len; --k >= 0; p++) tty_put(*p); if (j + skip < ac) while (++len < longest + 3) tty_put(' '); } tty_puts(NEWLINE); } }
static el_status_t h_search(void) { static int Searching; const char *old_prompt; const char *(*move)(void); const char *p; if (Searching) return el_ring_bell(); Searching = 1; clear_line(); old_prompt = rl_prompt; rl_prompt = "Search: "; tty_puts(rl_prompt); move = Repeat == NO_ARG ? prev_hist : next_hist; p = editinput(); rl_prompt = old_prompt; Searching = 0; tty_puts(rl_prompt); if (p == NULL && el_intr_pending > 0) { el_intr_pending = 0; clear_line(); return redisplay(); } p = search_hist(p, move); clear_line(); if (p == NULL) { el_ring_bell(); return redisplay(); } return do_insert_hist(p); }
void tty_start_tty(struct tty *tty) { tty_init_termios(tty->fd, &tty->tio, tty->event); tty_putcode(tty, TTYC_SMCUP); tty_putcode(tty, TTYC_SGR0); memcpy(&tty->cell, &grid_default_cell, sizeof tty->cell); tty_putcode(tty, TTYC_RMKX); if (tty_use_acs(tty)) tty_putcode(tty, TTYC_ENACS); tty_putcode(tty, TTYC_CLEAR); tty_putcode(tty, TTYC_CNORM); if (tty_term_has(tty->term, TTYC_KMOUS)) tty_puts(tty, "\033[?1000l"); if (tty_term_has(tty->term, TTYC_XT)) tty_puts(tty, "\033[>c"); tty->cx = UINT_MAX; tty->cy = UINT_MAX; tty->rlower = UINT_MAX; tty->rupper = UINT_MAX; tty->mode = MODE_CURSOR; tty->flags |= TTY_STARTED; tty_force_cursor_colour(tty, ""); }
static el_status_t redisplay(void) { tty_puts(NEWLINE); /* XXX: Use "\r\e[K" to get really neat effect on ANSI capable terminals. */ tty_puts(rl_prompt); tty_string(rl_line_buffer); return CSmove; }
void loop_states(void) { char c; for(;;) { for(;robot_state == CONNECTED;) { //wait for commands if(!bt_rx_empty()) { c = bt_get_block(); if (is_endchar(c)) { char buffer[128]; if (bt_get_command(buffer)) { // interpret command if (interpret_command(buffer) && robot_state == CONNECTED) { tty_puts("COMMAND: "); tty_puts(buffer); tty_puts("\r\n"); } } } } } for(;robot_state == DISCONNECTED;) { //loopback BLUETOOTH <--> UART1 interface (ttyUSB) if (!tty_rx_empty()) { c = tty_get_noblock(); bt_put(c); } if(!bt_rx_empty()) { c = bt_get_noblock(); tty_put(c); //still check for commands as connected disconnected if (is_endchar(c)) { char buffer[128]; if (bt_get_command(buffer)) { interpret_command(buffer); } } } } } }
void tty_set_title(struct tty *tty, const char *title) { if (strstr(tty->termname, "xterm") == NULL && strstr(tty->termname, "rxvt") == NULL && strcmp(tty->termname, "screen") != 0) return; tty_puts(tty, "\033]0;"); tty_puts(tty, title); tty_putc(tty, '\007'); }
int state_disconnect(char *cmd_parameter) { if(cmd_parameter[0] == '\'' && cmd_parameter[15] == '\'' && cmd_parameter[5] == '-' && cmd_parameter[8] == '-') { robot_state = DISCONNECTED; tty_puts("\r\n **** disconnected from "); tty_puts(cmd_parameter); tty_puts("\r\n\r\n"); return 1; } return 0; }
void tty_putcode2(struct tty *tty, enum tty_code_code code, int a, int b) { if (a < 0 || b < 0) return; tty_puts(tty, tty_term_string2(tty->term, code, a, b)); }
/* * retrace steps on map, optionally walk them back */ void map_retrace(int steps, int walk_back) { char cmd[2]; cmd[1] = '\0'; if (!steps && !walk_back) mapend = mapstart; else { if (!steps) steps = -1; if (walk_back && opt_echo) { status(1); tty_putc('['); } while (mapstart != mapend && steps--) { mapend = MAPINDEX(mapend - 1); if (walk_back) { cmd[0] = reverse_dir(mappath[mapend]); if (opt_echo) tty_putc(cmd[0]); tcp_write(tcp_fd, cmd); } } if (walk_back && opt_echo) tty_puts("]\n"); } }
void tty_attributes_bg(struct tty *tty, const struct grid_cell *gc) { u_char bg; bg = gc->bg; if (gc->flags & GRID_FLAG_BG256) { if (tty_try_256(tty, bg, "48") == 0) return; if (tty_try_88(tty, bg, "48") == 0) return; bg = colour_256to16(bg); if (bg & 8) bg &= 7; } if (bg == 8 && !(tty->term->flags & TERM_HASDEFAULTS) && !(tty->term_flags & TERM_HASDEFAULTS)) bg = 0; if (bg == 8) tty_puts(tty, "\033[49m"); else tty_putcode1(tty, TTYC_SETAB, bg); }
void tty_attributes_fg(struct tty *tty, const struct grid_cell *gc) { u_char fg; fg = gc->fg; if (gc->flags & GRID_FLAG_FG256) { if (tty_try_256(tty, fg, "38") == 0) return; if (tty_try_88(tty, fg, "38") == 0) return; fg = colour_256to16(fg); if (fg & 8) { fg &= 7; tty_putcode(tty, TTYC_BOLD); tty->cell.attr |= GRID_ATTR_BRIGHT; } else if (tty->cell.attr & GRID_ATTR_BRIGHT) tty_reset(tty); } if (fg == 8 && !(tty->term->flags & TERM_HASDEFAULTS) && !(tty->term_flags & TERM_HASDEFAULTS)) fg = 7; if (fg == 8) tty_puts(tty, "\033[39m"); else tty_putcode1(tty, TTYC_SETAF, fg); }
void tty_putcode1(struct tty *tty, enum tty_code_code code, int a) { if (a < 0) return; tty_puts(tty, tty_term_string1(tty->term, code, a)); }
void tty_colours_fg(struct tty *tty, const struct grid_cell *gc) { struct grid_cell *tc = &tty->cell; u_char fg = gc->fg; char s[32]; /* Is this a 256-colour colour? */ if (gc->flags & GRID_FLAG_FG256) { /* Try as 256 colours or translating to 88. */ if (tty_try_256(tty, fg, "38") == 0) goto save_fg; if (tty_try_88(tty, fg, "38") == 0) goto save_fg; /* Else already handled by tty_check_fg. */ return; } /* Is this an aixterm bright colour? */ if (fg >= 90 && fg <= 97) { xsnprintf(s, sizeof s, "\033[%dm", fg); tty_puts(tty, s); goto save_fg; } /* Otherwise set the foreground colour. */ tty_putcode1(tty, TTYC_SETAF, fg); save_fg: /* Save the new values in the terminal current cell. */ tc->fg = fg; tc->flags &= ~GRID_FLAG_FG256; tc->flags |= gc->flags & GRID_FLAG_FG256; }
void tty_update_mode(struct tty *tty, int mode, struct screen *s) { int changed; if (strcmp(s->ccolour, tty->ccolour)) tty_force_cursor_colour(tty, s->ccolour); if (tty->flags & TTY_NOCURSOR) mode &= ~MODE_CURSOR; changed = mode ^ tty->mode; if (changed & MODE_CURSOR) { if (mode & MODE_CURSOR) tty_putcode(tty, TTYC_CNORM); else tty_putcode(tty, TTYC_CIVIS); } if (tty->cstyle != s->cstyle) { if (tty_term_has(tty->term, TTYC_CS1)) { if (s->cstyle == 0 && tty_term_has(tty->term, TTYC_CSR1)) tty_putcode(tty, TTYC_CSR1); else tty_putcode1(tty, TTYC_CS1, s->cstyle); } tty->cstyle = s->cstyle; } if (changed & ALL_MOUSE_MODES) { if (mode & ALL_MOUSE_MODES) { if (mode & MODE_MOUSE_UTF8) tty_puts(tty, "\033[?1005h"); if (mode & MODE_MOUSE_ANY) tty_puts(tty, "\033[?1003h"); else if (mode & MODE_MOUSE_BUTTON) tty_puts(tty, "\033[?1002h"); else if (mode & MODE_MOUSE_STANDARD) tty_puts(tty, "\033[?1000h"); } else { if (tty->mode & MODE_MOUSE_ANY) tty_puts(tty, "\033[?1003l"); else if (tty->mode & MODE_MOUSE_BUTTON) tty_puts(tty, "\033[?1002l"); else if (tty->mode & MODE_MOUSE_STANDARD) tty_puts(tty, "\033[?1000l"); if (tty->mode & MODE_MOUSE_UTF8) tty_puts(tty, "\033[?1005l"); } } if (changed & MODE_KKEYPAD) { if (mode & MODE_KKEYPAD) tty_putcode(tty, TTYC_SMKX); else tty_putcode(tty, TTYC_RMKX); } tty->mode = mode; }
static void reposition(void) { int i; tty_put('\r'); tty_puts(rl_prompt); for (i = 0; i < rl_point; i++) tty_show(rl_line_buffer[i]); }
static void write_message __P1 (char *,s) { clear_input_line(opt_compact); if (!opt_compact) { tty_putc('\n'); status(1); } tty_puts(s); }
void tty_start_tty(struct tty *tty) { tty_init_termios(tty->fd, &tty->tio, tty->event); tty_putcode(tty, TTYC_SMCUP); tty_putcode(tty, TTYC_SGR0); memcpy(&tty->cell, &grid_default_cell, sizeof tty->cell); tty_putcode(tty, TTYC_RMKX); if (tty_use_acs(tty)) tty_putcode(tty, TTYC_ENACS); tty_putcode(tty, TTYC_CLEAR); tty_putcode(tty, TTYC_CNORM); if (tty_term_has(tty->term, TTYC_KMOUS)) tty_puts(tty, "\033[?1000l\033[?1002l\033[?1006l\033[?1005l"); if (tty_term_has(tty->term, TTYC_XT)) { if (options_get_number(&global_options, "focus-events")) { tty->flags |= TTY_FOCUS; tty_puts(tty, "\033[?1004h"); } tty_puts(tty, "\033[c"); } tty->cx = UINT_MAX; tty->cy = UINT_MAX; tty->rlower = UINT_MAX; tty->rupper = UINT_MAX; tty->mode = MODE_CURSOR; tty->flags |= TTY_STARTED; tty_force_cursor_colour(tty, ""); tty->mouse_drag_flag = 0; tty->mouse_drag_update = NULL; tty->mouse_drag_release = NULL; }
void run_test(void) { tty_puts("\nSDRAM test started\n"); #ifdef TEST_RANDOM tty_puts("Random data\n"); while(1) random_longs(DRAM_START, DRAM_END); #endif #ifdef TEST_PARALLEL parallel_longs(DRAM_START, (unsigned long *)DRAM_START, (unsigned long *)(DRAM_START+((DRAM_END-DRAM_START)/2)), (unsigned long *)DRAM_END, inc_addr); parallel_longs(0x00000000, (unsigned long *)DRAM_START, (unsigned long *)(DRAM_START+((DRAM_END-DRAM_START)/2)), (unsigned long *)DRAM_END, nop); #endif #ifdef TEST_LONG tty_puts("*** Testing LONG\n"); test_longs("ZERO: ", 0x00000000, (unsigned long *)DRAM_START, (unsigned long *)DRAM_END, nop, 1, 1); test_longs("ONES: ", 0xFFFFFFFF, (unsigned long *)DRAM_START, (unsigned long *)DRAM_END, nop, 1, 1); test_longs("ALTS: ", 0x55AA55AA, (unsigned long *)DRAM_START, (unsigned long *)DRAM_END, toggle, 1, 1); test_longs("ADDR: ", DRAM_START, (unsigned long *)DRAM_START, (unsigned long *)DRAM_END, inc_addr, 1, 1); #endif #ifdef TEST_SHORTS tty_puts("*** Testing SHORT\n"); test_shorts("ZERO: ", 0x0000, (unsigned short *)DRAM_START, (unsigned short *)DRAM_END, nop, 1, 1); test_shorts("ONES: ", 0xFFFF, (unsigned short *)DRAM_START, (unsigned short *)DRAM_END, nop, 1, 1); test_shorts("ALTS: ", 0x55AA, (unsigned short *)DRAM_START, (unsigned short *)DRAM_END, toggle, 1, 1); test_shorts("ADDR: ", 0, (unsigned short *)DRAM_START, (unsigned short *)DRAM_END, inc_addr, 1, 1); #endif #ifdef TEST_BYTES tty_puts("*** Testing BYTE\n"); test_bytes("ZERO: ", 0x00, (unsigned char *)DRAM_START, (unsigned char *)DRAM_END, nop, 1, 1); test_bytes("ONES: ", 0xFF, (unsigned char *)DRAM_START, (unsigned char *)DRAM_END, nop, 1, 1); test_bytes("ALTS: ", 0xAA, (unsigned char *)DRAM_START, (unsigned char *)DRAM_END, toggle, 1, 1); test_bytes("ADDR: ", 0, (unsigned char *)DRAM_START, (unsigned char *)DRAM_END, inc_addr, 1, 1); #endif #ifdef TEST_REFRESH tty_puts("*** Testing REFRESH\n"); test_longs("LONG: ", DRAM_START, (unsigned long *)DRAM_START, (unsigned long *)DRAM_END, inc_addr, 32, 32); test_shorts("SHORT: ", 0, (unsigned short *)DRAM_START, (unsigned short *)DRAM_END, inc_addr, 32, 32); test_bytes("BYTE: ", 0, (unsigned char *)DRAM_START, (unsigned char *)DRAM_END, inc_addr, 32, 32); #endif // Done tty_puts("Done\n"); }
void tty_set_title(struct tty *tty, const char *title) { if (!tty_term_has(tty->term, TTYC_TSL) || !tty_term_has(tty->term, TTYC_FSL)) return; tty_putcode(tty, TTYC_TSL); tty_puts(tty, title); tty_putcode(tty, TTYC_FSL); }
void tty_start_tty(struct tty *tty) { struct termios tio; #ifdef TIOCFLUSH int what; #endif #if 0 tty_detect_utf8(tty); #endif if (tcgetattr(tty->fd, &tty->tio) != 0) fatal("tcgetattr failed"); memcpy(&tio, &tty->tio, sizeof tio); tio.c_iflag &= ~(IXON|IXOFF|ICRNL|INLCR|IGNCR|IMAXBEL|ISTRIP); tio.c_iflag |= IGNBRK; tio.c_oflag &= ~(OPOST|ONLCR|OCRNL|ONLRET); tio.c_lflag &= ~(IEXTEN|ICANON|ECHO|ECHOE|ECHONL|ECHOCTL| ECHOPRT|ECHOKE|ECHOCTL|ISIG); tio.c_cc[VMIN] = 1; tio.c_cc[VTIME] = 0; if (tcsetattr(tty->fd, TCSANOW, &tio) != 0) fatal("tcsetattr failed"); #ifdef TIOCFLUSH what = 0; if (ioctl(tty->fd, TIOCFLUSH, &what) != 0) fatal("ioctl(TIOCFLUSH)"); #endif tty_putcode(tty, TTYC_IS1); tty_putcode(tty, TTYC_IS2); tty_putcode(tty, TTYC_IS3); tty_putcode(tty, TTYC_SMCUP); tty_putcode(tty, TTYC_SMKX); tty_putcode(tty, TTYC_ENACS); tty_putcode(tty, TTYC_CLEAR); tty_putcode(tty, TTYC_CNORM); if (tty_term_has(tty->term, TTYC_KMOUS)) tty_puts(tty, "\033[?1000l"); memcpy(&tty->cell, &grid_default_cell, sizeof tty->cell); tty->cx = UINT_MAX; tty->cy = UINT_MAX; tty->rlower = UINT_MAX; tty->rupper = UINT_MAX; tty->mode = MODE_CURSOR; }
void SystemCall(u32 id, void *param, void *result) { int i; struct dirent *node; switch (id) { case SYS_PUTS: tty_puts((char*)param); break; case SYS_EXEC: LoadProcess((char*)param); break; case 2: if (kbd_event) { kbd_event = false; *(bool*)result = true; } else { *(bool*)result = false; } break; case 3: *(int*)result = inb(*(int*)param); break; case 4: outb(*(int*)param, *(int*)result); break; case 5: // read dir i = *(int *)param; node = fs_readdir(ird_root, i); if (!node) { *(int *) result = 0; } else { *(char *)result = node->name; } break; case 6: tty_attr((int)param); break; case 7: *(int*)result = timer_ticks; break; default: break; } }
void tty_start_tty(struct tty *tty) { struct termios tio; int mode; if (tty->fd == -1) return; if ((mode = fcntl(tty->fd, F_GETFL)) == -1) fatal("fcntl failed"); if (fcntl(tty->fd, F_SETFL, mode|O_NONBLOCK) == -1) fatal("fcntl failed"); bufferevent_enable(tty->event, EV_READ|EV_WRITE); if (tcgetattr(tty->fd, &tty->tio) != 0) fatal("tcgetattr failed"); memcpy(&tio, &tty->tio, sizeof tio); tio.c_iflag &= ~(IXON|IXOFF|ICRNL|INLCR|IGNCR|IMAXBEL|ISTRIP); tio.c_iflag |= IGNBRK; tio.c_oflag &= ~(OPOST|ONLCR|OCRNL|ONLRET); tio.c_lflag &= ~(IEXTEN|ICANON|ECHO|ECHOE|ECHONL|ECHOCTL| ECHOPRT|ECHOKE|ECHOCTL|ISIG); tio.c_cc[VMIN] = 1; tio.c_cc[VTIME] = 0; if (tcsetattr(tty->fd, TCSANOW, &tio) != 0) fatal("tcsetattr failed"); tcflush(tty->fd, TCIOFLUSH); tty_putcode(tty, TTYC_SMCUP); tty_putcode(tty, TTYC_SGR0); memcpy(&tty->cell, &grid_default_cell, sizeof tty->cell); tty_putcode(tty, TTYC_RMKX); tty_putcode(tty, TTYC_ENACS); tty_putcode(tty, TTYC_CLEAR); tty_putcode(tty, TTYC_CNORM); if (tty_term_has(tty->term, TTYC_KMOUS)) tty_puts(tty, "\033[?1000l"); tty->cx = UINT_MAX; tty->cy = UINT_MAX; tty->rlower = UINT_MAX; tty->rupper = UINT_MAX; tty->mode = MODE_CURSOR; tty->flags |= TTY_STARTED; }
int tty_try_256(struct tty *tty, u_char colour, const char *type) { char s[32]; if (!(tty->term->flags & TERM_256COLOURS) && !(tty->term_flags & TERM_256COLOURS)) return (-1); xsnprintf(s, sizeof s, "\033[%s;5;%hhum", type, colour); tty_puts(tty, s); return (0); }
// // Read a character from a TTY port // static char _tty_getc(volatile struct uart *uart) { do { #if 0 if ((uart->status & 0xF0) != 0) { tty_puts("\nErr = "); tty_puthex(uart->TxRx, 2); } #endif } while ((uart->status & SSR_RxFull) == 0); return uart->TxRx; }
void tty_era_pane(struct tty *tty, const struct tty_ctx *ctx, u_int t, u_int l, u_int b, u_int r) { char tmp[64]; snprintf(tmp, sizeof tmp, "\033[%u;%u;%u;%u$z", ctx->yoff + t + 1, ctx->xoff + l + 1, ctx->yoff + b + 1, ctx->xoff + r + 1); tty_puts(tty, tmp); }
void tty_start_tty(struct tty *tty) { struct termios tio; if (tty->fd == -1 || tcgetattr(tty->fd, &tty->tio) != 0) return; setblocking(tty->fd, 0); bufferevent_enable(tty->event, EV_READ|EV_WRITE); memcpy(&tio, &tty->tio, sizeof tio); tio.c_iflag &= ~(IXON|IXOFF|ICRNL|INLCR|IGNCR|IMAXBEL|ISTRIP); tio.c_iflag |= IGNBRK; tio.c_oflag &= ~(OPOST|ONLCR|OCRNL|ONLRET); tio.c_lflag &= ~(IEXTEN|ICANON|ECHO|ECHOE|ECHONL|ECHOCTL| ECHOPRT|ECHOKE|ECHOCTL|ISIG); tio.c_cc[VMIN] = 1; tio.c_cc[VTIME] = 0; if (tcsetattr(tty->fd, TCSANOW, &tio) == 0) tcflush(tty->fd, TCIOFLUSH); tty_putcode(tty, TTYC_SMCUP); tty_putcode(tty, TTYC_SGR0); memcpy(&tty->cell, &grid_default_cell, sizeof tty->cell); tty_putcode(tty, TTYC_RMKX); if (tty_use_acs(tty)) tty_putcode(tty, TTYC_ENACS); tty_putcode(tty, TTYC_CLEAR); tty_putcode(tty, TTYC_CNORM); if (tty_term_has(tty->term, TTYC_KMOUS)) tty_puts(tty, "\033[?1000l"); tty->cx = UINT_MAX; tty->cy = UINT_MAX; tty->rlower = UINT_MAX; tty->rupper = UINT_MAX; tty->mode = MODE_CURSOR; tty->flags |= TTY_STARTED; tty_force_cursor_colour(tty, ""); }
void random_longs(unsigned long *start, unsigned long end) { unsigned long *dp, *random, *random_end; unsigned long v1, v2; int errs, tries, total; random_end = (unsigned long *)((unsigned long)pseudo_random_data + sizeof(pseudo_random_data)); dp = start; random = pseudo_random_data; tty_putc('\r'); tries = 0; while (dp != end) { *dp++ = *random++; if (random == random_end) { random = pseudo_random_data; if (++tries == 0x100) { tty_putc('.'); tries = 0; idle(); } } } tty_putc('\r'); dp = start; random = pseudo_random_data; errs = 0; while (dp != end) { if ((v1 = *dp++) != (v2 = *random++)) { if (++errs < MAX_ERRS) { tty_puts("\nFailed at "); tty_puthex(dp-1); tty_puts(", v1: "); tty_puthex(v1); tty_puts(", v2: "); tty_puthex(v2); total = 0; for (tries = 0; tries < 1024; tries++) { dp -= 2; random -= 2; if ((v1 = *dp++) != (v2 = *random++)) total++; if ((v1 = *dp++) != (v2 = *random++)) total++; } tty_puts(", times: "); tty_puthex(total); } } if (random == random_end) { random = pseudo_random_data; } } if (errs) { tty_puts("\nTotal errors: "); tty_puthex(errs); tty_puts("\n"); } }
static void syscall_int_handler(const struct thread_context *const context) { printf("\nreceived syscall %d\n", context->eax); switch (context->eax) { case 1: { char *str = (char *)context->ecx; tty_puts(str, true); } break; default: break; } }
// // Display a number in hex // void tty_puthex(int chan, unsigned long val, int length) { char hex[] = "0123456789ABCDEF"; char str[16]; char *s = &str[length+3]; int i; *--s = '\0'; for (i = 0; i < length; i++) { *--s = hex[(val & 0x0F)]; val >>= 4; } *--s = 'x'; *--s = '0'; tty_puts(chan, s); }