int mouse_test(fb_info fb) { int fd; int xx = 123, yy = 234; if((fd = mouse_open("/dev/input/mice")) < 0) { perror("mouse_open"); exit(1); } mevent_t mevent; u8_t buf[] = {0xf3,0xc8,0xf3,0x64,0xf3,0x50}; if(write(fd, buf, sizeof(buf)) < sizeof(buf)) { perror("mouse_write"); fprintf(stderr, "Error write to mice device\n"); } save_cursor(fb,xx,yy,cursor_save); while(1) { if(mouse_parse(fd, &mevent) == 0 && (mevent.x || mevent.y || mevent.z || mevent.button)) { restore_cursor(fb,xx,yy,cursor_save); xx += mevent.x; yy += mevent.y; if(xx > 1366) xx = 1366; if(xx < 0) xx = 0; if(yy > 721) yy = 721; if(yy < 0) yy = 0; if(mevent.button == 1 && xx < 420) { if(xx >= 300 && yy >=210 && yy <= 290) who = 2; else if(xx >= 300 && yy >= 510 && yy <= 590) who = 1; } if(mevent.button == 1 && xx >= 420 && yy <= 710 && xx <= 1320) { if(! check(xx,yy)) { draw_piece(fb,(xx + 15)/30 * 30,yy/30 * 30 + 15,13,(who - 1) ? 0x00000000 : 0xffffffff); chess_count(xx, yy); if(check_all(fb)) exit(0); printf("%d %d\n",(xx + 15 - 420) / 30, (yy) / 30); who = (who - 1) ? 1 : 2; } } save_cursor(fb,xx,yy,cursor_save); draw_cursor(fb,xx,yy,cursor_16_25); } usleep(100); } }
void mosedoing() { int fd; int mx = 512, my = 370; char buf[8]; //prin_cursor(mx, my); int dx, dy, dz, button; fd = open("/dev/input/mice",O_RDWR); while(1) { read(fd,buf,8); button = buf[0]&0x07; dx = buf[1]; dy = -buf[2]; report_cursor(mx,my); mx += dx; my += dy; mx = mx>0?mx:0; my = my>0?my:0; mx = mx<(fb_infor.w-C_WIDTH)?mx:(fb_infor.w-C_WIDTH); my = my<(fb_infor.h-C_HEIGH)?my:(fb_infor.h-C_HEIGH); save_cursor(mx,my); prin_cursor(mx, my); usleep(1000); } }
void region_scroll_up(int top, int bottom) { int i; if (top > bottom) { i = top; top = bottom; bottom = i; } if (top < 0 || bottom >= scr_lns) return; for (i = top; i < bottom; i++) big_picture[i] = big_picture[i + 1]; memset(big_picture + i, 0, sizeof(*big_picture)); memset(big_picture[i].data, ' ', scr_cols); save_cursor(); change_scroll_range(top, bottom); do_move(0, bottom); scroll_forward(); change_scroll_range(0, scr_lns - 1); restore_cursor(); refresh(); }
void doing() { save_cursor(300,200); prin_cursor(300,200); sleep(2); report_cursor(300,200); prin_cursor(500,500); }
void schedule() { int i=1; setBlueWhite(); save_cursor(); hide_cursor(); for(i=1;i<=100;i++) { recover_cursor(); printf("%d%s", i, "%"); fflush(stdout); usleep(100000); } default_cursor(); show_cursor(); }
/* * Remove everything currently in `inbuf' and stick it up on the * in-memory display. There's a big state machine in here to * process escape sequences... */ void term_out(void) { int c; int must_update = FALSE; while ( (c = inbuf_getc()) != -1) { #ifdef LOG { static FILE *fp = NULL; if (!fp) fp = fopen("putty.log", "wb"); if (fp) fputc (c, fp); } #endif switch (termstate) { case TOPLEVEL: do_toplevel: switch (c) { case '\005': /* terminal type query */ ldisc->send ("\033[?1;2c", 7); break; case '\007': beep(); disptop = scrtop; must_update = TRUE; break; case '\b': if (curs_x == 0 && curs_y > 0) curs_x = cols-1, curs_y--; else if (wrapnext) wrapnext = FALSE; else curs_x--; fix_cpos; disptop = scrtop; must_update = TRUE; break; case '\016': cset = 1; break; case '\017': cset = 0; break; case '\033': termstate = SEEN_ESC; break; case 0233: termstate = SEEN_CSI; esc_nargs = 1; esc_args[0] = ARG_DEFAULT; esc_query = FALSE; break; case 0235: termstate = SEEN_OSC; esc_args[0] = 0; break; case '\r': curs_x = 0; wrapnext = FALSE; fix_cpos; disptop = scrtop; must_update = TRUE; break; case '\013': case '\014': case '\n': if (curs_y == marg_b) scroll (marg_t, marg_b, 1, TRUE); else if (curs_y < rows-1) curs_y++; if (cfg.lfhascr) curs_x = 0; fix_cpos; wrapnext = FALSE; disptop = scrtop; nl_count++; break; case '\t': do { curs_x++; } while (curs_x < cols-1 && !tabs[curs_x]); if (curs_x >= cols) curs_x = cols-1; { unsigned long *old_cpos = cpos; fix_cpos; check_selection (old_cpos, cpos); } disptop = scrtop; must_update = TRUE; break; default: if (c >= ' ' && c != 0234) { if (wrapnext) { cpos[1] = ATTR_WRAPPED; if (curs_y == marg_b) scroll (marg_t, marg_b, 1, TRUE); else if (curs_y < rows-1) curs_y++; curs_x = 0; fix_cpos; wrapnext = FALSE; nl_count++; } if (insert) insch (1); check_selection (cpos, cpos+1); *cpos++ = xlat_tty2scr((unsigned char)c) | curr_attr | (c <= 0x7F ? cset_attr[cset] : ATTR_ASCII); curs_x++; if (curs_x == cols) { cpos--; curs_x--; wrapnext = wrap; } disptop = scrtop; } } break; case IGNORE_NEXT: termstate = TOPLEVEL; break; case OSC_MAYBE_ST: /* * This state is virtually identical to SEEN_ESC, with the * exception that we have an OSC sequence in the pipeline, * and _if_ we see a backslash, we process it. */ if (c == '\\') { do_osc(); termstate = TOPLEVEL; break; } /* else fall through */ case SEEN_ESC: termstate = TOPLEVEL; switch (c) { case '\005': case '\007': case '\b': case '\016': case '\017': case '\033': case 0233: case 0234: case 0235: case '\r': case '\013': case '\014': case '\n': case '\t': termstate = TOPLEVEL; goto do_toplevel; /* hack... */ case ' ': /* some weird sequence? */ termstate = IGNORE_NEXT; break; case '[': /* enter CSI mode */ termstate = SEEN_CSI; esc_nargs = 1; esc_args[0] = ARG_DEFAULT; esc_query = FALSE; break; case ']': /* xterm escape sequences */ termstate = SEEN_OSC; esc_args[0] = 0; break; case '(': /* should set GL */ termstate = SET_GL; break; case ')': /* should set GR */ termstate = SET_GR; break; case '7': /* save cursor */ save_cursor (TRUE); break; case '8': /* restore cursor */ save_cursor (FALSE); disptop = scrtop; must_update = TRUE; break; case '=': app_keypad_keys = TRUE; break; case '>': app_keypad_keys = FALSE; break; case 'D': /* exactly equivalent to LF */ if (curs_y == marg_b) scroll (marg_t, marg_b, 1, TRUE); else if (curs_y < rows-1) curs_y++; fix_cpos; wrapnext = FALSE; disptop = scrtop; nl_count++; break; case 'E': /* exactly equivalent to CR-LF */ curs_x = 0; wrapnext = FALSE; if (curs_y == marg_b) scroll (marg_t, marg_b, 1, TRUE); else if (curs_y < rows-1) curs_y++; fix_cpos; wrapnext = FALSE; nl_count++; disptop = scrtop; break; case 'M': /* reverse index - backwards LF */ if (curs_y == marg_t) scroll (marg_t, marg_b, -1, TRUE); else if (curs_y > 0) curs_y--; fix_cpos; wrapnext = FALSE; disptop = scrtop; must_update = TRUE; break; case 'Z': /* terminal type query */ ldisc->send ("\033[?6c", 5); break; case 'c': /* restore power-on settings */ power_on(); fix_cpos; disptop = scrtop; must_update = TRUE; break; case '#': /* ESC # 8 fills screen with Es :-) */ termstate = SEEN_ESCHASH; break; case 'H': /* set a tab */ tabs[curs_x] = TRUE; break; } break; case SEEN_CSI: termstate = TOPLEVEL; /* default */ switch (c) { case '\005': case '\007': case '\b': case '\016': case '\017': case '\033': case 0233: case 0234: case 0235: case '\r': case '\013': case '\014': case '\n': case '\t': termstate = TOPLEVEL; goto do_toplevel; /* hack... */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (esc_nargs <= ARGS_MAX) { if (esc_args[esc_nargs-1] == ARG_DEFAULT) esc_args[esc_nargs-1] = 0; esc_args[esc_nargs-1] = 10 * esc_args[esc_nargs-1] + c - '0'; } termstate = SEEN_CSI; break; case ';': if (++esc_nargs <= ARGS_MAX) esc_args[esc_nargs-1] = ARG_DEFAULT; termstate = SEEN_CSI; break; case '?': esc_query = TRUE; termstate = SEEN_CSI; break; case 'A': /* move up N lines */ move (curs_x, curs_y - def(esc_args[0], 1), 1); disptop = scrtop; must_update = TRUE; break; case 'B': case 'e': /* move down N lines */ move (curs_x, curs_y + def(esc_args[0], 1), 1); disptop = scrtop; must_update = TRUE; break; case 'C': case 'a': /* move right N cols */ move (curs_x + def(esc_args[0], 1), curs_y, 1); disptop = scrtop; must_update = TRUE; break; case 'D': /* move left N cols */ move (curs_x - def(esc_args[0], 1), curs_y, 1); disptop = scrtop; must_update = TRUE; break; case 'E': /* move down N lines and CR */ move (0, curs_y + def(esc_args[0], 1), 1); disptop = scrtop; must_update = TRUE; break; case 'F': /* move up N lines and CR */ move (0, curs_y - def(esc_args[0], 1), 1); disptop = scrtop; must_update = TRUE; break; case 'G': case '`': /* set horizontal posn */ move (def(esc_args[0], 1) - 1, curs_y, 0); disptop = scrtop; must_update = TRUE; break; case 'd': /* set vertical posn */ move (curs_x, (dec_om ? marg_t : 0) + def(esc_args[0], 1) - 1, (dec_om ? 2 : 0)); disptop = scrtop; must_update = TRUE; break; case 'H': case 'f': /* set horz and vert posns at once */ if (esc_nargs < 2) esc_args[1] = ARG_DEFAULT; move (def(esc_args[1], 1) - 1, (dec_om ? marg_t : 0) + def(esc_args[0], 1) - 1, (dec_om ? 2 : 0)); disptop = scrtop; must_update = TRUE; break; case 'J': /* erase screen or parts of it */ { unsigned int i = def(esc_args[0], 0) + 1; if (i > 3) i = 0; erase_lots(FALSE, !!(i & 2), !!(i & 1)); } disptop = scrtop; must_update = TRUE; break; case 'K': /* erase line or parts of it */ { unsigned int i = def(esc_args[0], 0) + 1; if (i > 3) i = 0; erase_lots(TRUE, !!(i & 2), !!(i & 1)); } disptop = scrtop; must_update = TRUE; break; case 'L': /* insert lines */ if (curs_y <= marg_b) scroll (curs_y, marg_b, -def(esc_args[0], 1), FALSE); disptop = scrtop; must_update = TRUE; break; case 'M': /* delete lines */ if (curs_y <= marg_b) scroll (curs_y, marg_b, def(esc_args[0], 1), FALSE); disptop = scrtop; must_update = TRUE; break; case '@': /* insert chars */ insch (def(esc_args[0], 1)); disptop = scrtop; must_update = TRUE; break; case 'P': /* delete chars */ insch (-def(esc_args[0], 1)); disptop = scrtop; must_update = TRUE; break; case 'c': /* terminal type query */ ldisc->send ("\033[?6c", 5); break; case 'n': /* cursor position query */ if (esc_args[0] == 6) { char buf[32]; sprintf (buf, "\033[%d;%dR", curs_y + 1, curs_x + 1); ldisc->send (buf, strlen(buf)); } break; case 'h': /* toggle a mode to high */ toggle_mode (esc_args[0], esc_query, TRUE); break; case 'l': /* toggle a mode to low */ toggle_mode (esc_args[0], esc_query, FALSE); break; case 'g': /* clear tabs */ if (esc_nargs == 1) { if (esc_args[0] == 0) { tabs[curs_x] = FALSE; } else if (esc_args[0] == 3) { int i; for (i = 0; i < cols; i++) tabs[i] = FALSE; } } break; case 'r': /* set scroll margins */ if (!esc_query && esc_nargs <= 2) { int top, bot; top = def(esc_args[0], 1) - 1; if (top < 0) top = 0; bot = (esc_nargs <= 1 || esc_args[1] == 0 ? rows : def(esc_args[1], rows)) - 1; if (bot >= rows) bot = rows-1; if (top <= bot) { marg_t = top; marg_b = bot; curs_x = 0; /* * I used to think the cursor should be * placed at the top of the newly marginned * area. Apparently not: VMS TPU falls over * if so. */ curs_y = 0; fix_cpos; disptop = scrtop; must_update = TRUE; } } break; case 'm': /* set graphics rendition */ { int i; for (i=0; i<esc_nargs; i++) { switch (def(esc_args[i], 0)) { case 0: /* restore defaults */ curr_attr = ATTR_DEFAULT; break; case 1: /* enable bold */ curr_attr |= ATTR_BOLD; break; case 4: /* enable underline */ case 21: /* (enable double underline) */ curr_attr |= ATTR_UNDER; break; case 7: /* enable reverse video */ curr_attr |= ATTR_REVERSE; break; case 22: /* disable bold */ curr_attr &= ~ATTR_BOLD; break; case 24: /* disable underline */ curr_attr &= ~ATTR_UNDER; break; case 27: /* disable reverse video */ curr_attr &= ~ATTR_REVERSE; break; case 30: case 31: case 32: case 33: case 34: case 35: case 36: case 37: /* foreground */ curr_attr &= ~ATTR_FGMASK; curr_attr |= (esc_args[i] - 30) << ATTR_FGSHIFT; break; case 39: /* default-foreground */ curr_attr &= ~ATTR_FGMASK; curr_attr |= ATTR_DEFFG; break; case 40: case 41: case 42: case 43: case 44: case 45: case 46: case 47: /* background */ curr_attr &= ~ATTR_BGMASK; curr_attr |= (esc_args[i] - 40) << ATTR_BGSHIFT; break; case 49: /* default-background */ curr_attr &= ~ATTR_BGMASK; curr_attr |= ATTR_DEFBG; break; } } } break; case 's': /* save cursor */ save_cursor (TRUE); break; case 'u': /* restore cursor */ save_cursor (FALSE); disptop = scrtop; must_update = TRUE; break; case 't': /* set page size - ie window height */ request_resize (cols, def(esc_args[0], 24)); deselect(); break; case 'X': /* write N spaces w/o moving cursor */ { int n = def(esc_args[0], 1); unsigned long *p = cpos; if (n > cols - curs_x) n = cols - curs_x; check_selection (cpos, cpos+n); while (n--) *p++ = ERASE_CHAR; disptop = scrtop; must_update = TRUE; } break; case 'x': /* report terminal characteristics */ { char buf[32]; int i = def(esc_args[0], 0); if (i == 0 || i == 1) { strcpy (buf, "\033[2;1;1;112;112;1;0x"); buf[2] += i; ldisc->send (buf, 20); } } break; } break; case SET_GL: case SET_GR: switch (c) { case 'A': cset_attr[termstate == SET_GL ? 0 : 1] = ATTR_GBCHR; break; case '0': cset_attr[termstate == SET_GL ? 0 : 1] = ATTR_LINEDRW; break; default: /* specifically, 'B' */ cset_attr[termstate == SET_GL ? 0 : 1] = ATTR_ASCII; break; } termstate = TOPLEVEL; break; case SEEN_OSC: osc_w = FALSE; switch (c) { case '\005': case '\007': case '\b': case '\016': case '\017': case '\033': case 0233: case 0234: case 0235: case '\r': case '\013': case '\014': case '\n': case '\t': termstate = TOPLEVEL; goto do_toplevel; /* hack... */ case 'P': /* Linux palette sequence */ termstate = SEEN_OSC_P; osc_strlen = 0; break; case 'R': /* Linux palette reset */ palette_reset(); term_invalidate(); termstate = TOPLEVEL; break; case 'W': /* word-set */ termstate = SEEN_OSC_W; osc_w = TRUE; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': esc_args[0] = 10 * esc_args[0] + c - '0'; break; case 'L': /* * Grotty hack to support xterm and DECterm title * sequences concurrently. */ if (esc_args[0] == 2) { esc_args[0] = 1; break; } /* else fall through */ default: termstate = OSC_STRING; osc_strlen = 0; } break; case OSC_STRING: if (c == 0234 || c == '\007') { /* * These characters terminate the string; ST and BEL * terminate the sequence and trigger instant * processing of it, whereas ESC goes back to SEEN_ESC * mode unless it is followed by \, in which case it is * synonymous with ST in the first place. */ do_osc(); termstate = TOPLEVEL; } else if (c == '\033') termstate = OSC_MAYBE_ST; else if (osc_strlen < OSC_STR_MAX) osc_string[osc_strlen++] = c; break; case SEEN_OSC_P: { int max = (osc_strlen == 0 ? 21 : 16); int val; if (c >= '0' && c <= '9') val = c - '0'; else if (c >= 'A' && c <= 'A'+max-10) val = c - 'A' + 10; else if (c >= 'a' && c <= 'a'+max-10) val = c - 'a' + 10; else termstate = TOPLEVEL; osc_string[osc_strlen++] = val; if (osc_strlen >= 7) { palette_set (osc_string[0], osc_string[1] * 16 + osc_string[2], osc_string[3] * 16 + osc_string[4], osc_string[5] * 16 + osc_string[6]); term_invalidate(); termstate = TOPLEVEL; } } break; case SEEN_OSC_W: switch (c) { case '\005': case '\007': case '\b': case '\016': case '\017': case '\033': case 0233: case 0234: case 0235: case '\r': case '\013': case '\014': case '\n': case '\t': termstate = TOPLEVEL; goto do_toplevel; /* hack... */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': esc_args[0] = 10 * esc_args[0] + c - '0'; break; default: termstate = OSC_STRING; osc_strlen = 0; } break; case SEEN_ESCHASH: if (c == '8') { unsigned long *p = scrtop; int n = rows * (cols+1); while (n--) *p++ = ATTR_DEFAULT | 'E'; disptop = scrtop; must_update = TRUE; check_selection (scrtop, scrtop + rows * (cols+1)); } termstate = TOPLEVEL; break; } check_selection (cpos, cpos+1); } if (must_update || nl_count > MAXNL) term_update(); }
static void change_private_mode(int mode, int set) { switch (mode) { case 1: /* DECCKM */ console->cursor_key_mode = set; break; case 3: if (set) /* 132 column mode */ console_set_size(132, 24); else /* 80 column mode */ console_set_size(80, 24); /* Clear window content and reset scrolling regions */ erase_screen(2); set_pos(0, 0); break; case 6: console->origin_mode = set; break; case 7: console->wraparound_mode = set; break; case 47: if (set) switch_to_alternate_buffer(); else switch_to_normal_buffer(); break; case 1047: if (set) { if (console->out == console->normal_buffer) { switch_to_alternate_buffer(); erase_screen(ERASE_SCREEN_BEGIN_TO_END); } } else { if (console->out == console->alternate_buffer) { switch_to_normal_buffer(); erase_screen(ERASE_SCREEN_BEGIN_TO_END); } } break; case 1048: if (set) save_cursor(); else restore_cursor(); break; case 1049: if (set) { save_cursor(); if (console->out == console->normal_buffer) { switch_to_alternate_buffer(); erase_screen(ERASE_SCREEN_BEGIN_TO_END); } } else { if (console->out == console->alternate_buffer) { switch_to_normal_buffer(); erase_screen(ERASE_SCREEN_BEGIN_TO_END); } restore_cursor(); } break; default: log_error("change_private_mode(): private mode %d not supported.\n", mode); } }
void console_init() { log_info("Initializing console shared memory region.\n"); /* TODO: mm_mmap() does not support MAP_SHARED yet */ HANDLE section; LARGE_INTEGER section_size; section_size.QuadPart = sizeof(struct console_data); OBJECT_ATTRIBUTES obj_attr; obj_attr.Length = sizeof(OBJECT_ATTRIBUTES); obj_attr.RootDirectory = NULL; obj_attr.ObjectName = NULL; obj_attr.Attributes = OBJ_INHERIT; obj_attr.SecurityDescriptor = NULL; obj_attr.SecurityQualityOfService = NULL; NTSTATUS status; status = NtCreateSection(§ion, SECTION_MAP_READ | SECTION_MAP_WRITE, &obj_attr, §ion_size, PAGE_READWRITE, SEC_COMMIT, NULL); if (!NT_SUCCESS(status)) { log_error("NtCreateSection() failed, status: %x\n", status); return; } PVOID base_addr = NULL; SIZE_T view_size = sizeof(struct console_data); status = NtMapViewOfSection(section, NtCurrentProcess(), &base_addr, 0, sizeof(struct console_data), NULL, &view_size, ViewUnmap, MEM_TOP_DOWN, PAGE_READWRITE); if (!NT_SUCCESS(status)) { log_error("NtMapViewOfSection() failed, status: %x\n", status); return; } console = (struct console_data *)base_addr; SECURITY_ATTRIBUTES attr; attr.nLength = sizeof(SECURITY_ATTRIBUTES); attr.lpSecurityDescriptor = NULL; attr.bInheritHandle = TRUE; HANDLE mutex = CreateMutexW(&attr, FALSE, NULL); if (mutex == NULL) { log_error("CreateMutexW() failed, error code: %d\n", GetLastError()); return; } HANDLE in = CreateFileA("CONIN$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &attr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (in == INVALID_HANDLE_VALUE) { log_error("CreateFile(\"CONIN$\") failed, error code: %d\n", GetLastError()); return; } HANDLE out = CreateFileA("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &attr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (out == INVALID_HANDLE_VALUE) { log_error("CreateFile(\"CONOUT$\") failed, error code: %d\n", GetLastError()); return; } console->section = section; console->mutex = mutex; console->in = in; console->out = out; console->normal_buffer = out; console->alternate_buffer = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &attr, CONSOLE_TEXTMODE_BUFFER, NULL); console->termios.c_iflag = INLCR | ICRNL; console->termios.c_oflag = ONLCR | OPOST; console->termios.c_cflag = CREAD | CSIZE | B38400; console->termios.c_lflag = ICANON | ECHO | ECHOCTL; memset(console->termios.c_cc, 0, sizeof(console->termios.c_cc)); console->termios.c_cc[VINTR] = 3; console->termios.c_cc[VERASE] = 8; console->termios.c_cc[VEOF] = 4; console->termios.c_cc[VSUSP] = 26; console->bright = 0; console->reverse = 0; console->foreground = 7; console->background = 0; console->g0_charset = console->g1_charset = default_charset; console->charset = 0; console->insert_mode = 0; console->cursor_key_mode = 0; console->origin_mode = 0; console->wraparound_mode = 1; /* Only essential values are initialized here, others are automatically set to the correct value in console_retrieve_state() */ console->at_right_margin = 0; console->top = 0; console->scroll_full_screen = 1; console->utf8_buf_size = 0; save_cursor(); console->input_buffer_head = console->input_buffer_tail = 0; console->processor = NULL; SetConsoleMode(in, ENABLE_PROCESSED_INPUT | ENABLE_WINDOW_INPUT); SetConsoleMode(out, ENABLE_PROCESSED_OUTPUT); SetConsoleCtrlHandler(console_ctrlc_handler, TRUE); log_info("Console shared memory region successfully initialized.\n"); }
static void control_escape(char ch) { switch (ch) { case '[': for (int i = 0; i < CONSOLE_MAX_PARAMS; i++) console->params[i] = 0; console->param_count = 0; console->csi_prefix = 0; console->processor = control_escape_csi; break; case ']': console->params[0] = 0; console->string_len = -1; console->processor = control_escape_osc; break; case 'D': /* IND */ nl(); console->processor = NULL; break; case 'E': /* NEL */ crnl(); console->processor = NULL; break; case 'M': /* RI */ if (console->y == console->scroll_top) scroll_down(1); else set_pos(console->x, console->y - 1); console->processor = NULL; break; case '(': console->processor = control_escape_set_default_character_set; break; case ')': console->processor = control_escape_set_alternate_character_set; break; case '#': console->processor = control_escape_sharp; break; case '7': /* DECSC */ save_cursor(); console->processor = NULL; break; case '8': /* DECRC */ restore_cursor(); console->processor = NULL; break; default: log_error("control_escape(): Unhandled character %c\n", ch); console->processor = NULL; } }
int main(int argc, char **argv) { char c; guint i; struct termios tcattr; GByteArray *bytes; gboolean done = FALSE, saved = FALSE; struct timeval tv; fd_set readset; /* Start up: save the cursor location and put the terminal in * raw mode. */ bytes = g_byte_array_new(); save_cursor(); if (tcgetattr(STDIN_FILENO, &tcattr) != 0) { perror("tcgetattr"); return 1; } original = tcattr; signal(SIGINT, sigint_handler); /* Here we approximate what cfmakeraw() would do, for the benefit * of systems which don't actually provide the function. */ tcattr.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); tcattr.c_oflag &= ~(OPOST); tcattr.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); tcattr.c_cflag &= ~(CSIZE | PARENB); tcattr.c_cflag |= CS8; #ifdef HAVE_CFMAKERAW cfmakeraw(&tcattr); #endif if (tcsetattr(STDIN_FILENO, TCSANOW, &tcattr) != 0) { perror("tcsetattr"); return 1; } /* Switch to the alternate screen, clear it, and reset the keyboard. */ decset(MODE_ALTERNATE_SCREEN, TRUE); clear(); reset(); /* Main processing loop. */ while (!done) { print_help(); set_scrolling_region(); if (saved) { restore_cursor(); } /* Read a single byte. */ if (read(STDIN_FILENO, &c, 1) != 1) { done = TRUE; } switch (c) { case 'A': case 'a': keypad_mode = 1 - keypad_mode; if (keypad_mode == normal) { g_print(MODE_NORMAL_KEYPAD); } else { g_print(MODE_APPLICATION_KEYPAD); } break; case 'B': case 'b': cursor_mode = 1 - cursor_mode; decset(MODE_APPLICATION_CURSOR_KEYS, cursor_mode == application); break; case 'C': case 'c': sun_fkeys = !sun_fkeys; decset(MODE_SUN_FUNCTION_KEYS, sun_fkeys); break; case 'D': case 'd': hp_fkeys = !hp_fkeys; decset(MODE_HP_FUNCTION_KEYS, hp_fkeys); break; case 'E': case 'e': xterm_fkeys = !xterm_fkeys; decset(MODE_XTERM_FUNCTION_KEYS, xterm_fkeys); break; case 'F': case 'f': vt220_fkeys = !vt220_fkeys; decset(MODE_VT220_FUNCTION_KEYS, vt220_fkeys); break; case 'R': case 'r': keypad_mode = cursor_mode = normal; sun_fkeys = hp_fkeys = xterm_fkeys = vt220_fkeys = FALSE; reset(); break; case 'Q': case 'q': done = TRUE; break; case 0x0c: /* ^L */ clear(); if (saved) { restore_cursor(); saved = FALSE; } break; default: /* We get here if it's not one of the keys we care * about, so it might be a sequence. */ if (saved) { restore_cursor(); } g_byte_array_append(bytes, &c, 1); /* Wait for up to just under 1/50 second. */ tv.tv_sec = 0; tv.tv_usec = 1000000 / 50; FD_ZERO(&readset); FD_SET(STDIN_FILENO, &readset); while (select(STDIN_FILENO + 1, &readset, NULL, NULL, &tv) == 1) { if (read(STDIN_FILENO, &c, 1) == 1) { g_byte_array_append(bytes, &c, 1); } else { break; } tv.tv_sec = 0; tv.tv_usec = 1000000 / 50; FD_ZERO(&readset); FD_SET(STDIN_FILENO, &readset); } /* Clear this line, and print the sequence. */ g_print(ESC "[K"); for (i = 0; i < bytes->len; i++) { if (bytes->data[i] == 27) { g_print("<ESC> "); } else if ((((guint8)bytes->data[i]) < 32) || (((guint8)bytes->data[i]) > 126)) { g_print("<0x%02x> ", bytes->data[i]); } else { g_print("`%c' ", bytes->data[i]); } } g_print("\r\n"); g_byte_array_set_size(bytes, 0); save_cursor(); saved = TRUE; break; } reset_scrolling_region(); } decset(MODE_ALTERNATE_SCREEN, FALSE); if (tcsetattr(STDIN_FILENO, TCSANOW, &original) != 0) { perror("tcsetattr"); return 1; } g_byte_array_free(bytes, TRUE); reset(); return 0; }
static void do_talk_char(struct talk_win *twin, int ch) { extern int dumb_term; extern screenline* big_picture; screenline* line; int i; char ch0, buf[81]; if (isprint2(ch)) { ch0 = big_picture[twin->curln].data[twin->curcol]; if (big_picture[twin->curln].len < 79) move(twin->curln, twin->curcol); else do_talk_nextline(twin); outc(ch); ++(twin->curcol); line = big_picture + twin->curln; if (twin->curcol < line->len) { /* insert */ ++(line->len); memcpy(buf, line->data + twin->curcol, 80); save_cursor(); do_move(twin->curcol, twin->curln); ochar(line->data[twin->curcol] = ch0); for (i = twin->curcol + 1; i < line->len; i++) ochar(line->data[i] = buf[i - twin->curcol - 1]); restore_cursor(); } line->data[line->len] = 0; return; } switch (ch) { case Ctrl('H'): case '\177': if (twin->curcol == 0) { return; } line = big_picture + twin->curln; --(twin->curcol); if (twin->curcol < line->len) { --(line->len); save_cursor(); do_move(twin->curcol, twin->curln); for (i = twin->curcol; i < line->len; i++) ochar(line->data[i] = line->data[i + 1]); line->data[i] = 0; ochar(' '); restore_cursor(); } move(twin->curln, twin->curcol); return; case Ctrl('D'): line = big_picture + twin->curln; if (twin->curcol < line->len) { --(line->len); save_cursor(); do_move(twin->curcol, twin->curln); for (i = twin->curcol; i < line->len; i++) ochar(line->data[i] = line->data[i + 1]); line->data[i] = 0; ochar(' '); restore_cursor(); } return; case Ctrl('G'): bell(); return; case Ctrl('B'): if (twin->curcol > 0) { --(twin->curcol); move(twin->curln, twin->curcol); } return; case Ctrl('F'): if (twin->curcol < 79) { ++(twin->curcol); move(twin->curln, twin->curcol); } return; case Ctrl('A'): twin->curcol = 0; move(twin->curln, twin->curcol); return; case Ctrl('K'): clrtoeol(); return; case Ctrl('Y'): twin->curcol = 0; move(twin->curln, twin->curcol); clrtoeol(); return; case Ctrl('E'): twin->curcol = big_picture[twin->curln].len; move(twin->curln, twin->curcol); return; case Ctrl('M'): case Ctrl('J'): line = big_picture + twin->curln; strncpy(buf, line->data, line->len); buf[line->len] = 0; if (dumb_term) outc('\n'); do_talk_nextline(twin); break; case Ctrl('P'): line = big_picture + twin->curln; strncpy(buf, line->data, line->len); buf[line->len] = 0; if (twin->curln > twin->sline) { --(twin->curln); move(twin->curln, twin->curcol); } break; case Ctrl('N'): line = big_picture + twin->curln; strncpy(buf, line->data, line->len); buf[line->len] = 0; if (twin->curln < twin->eline) { ++(twin->curln); move(twin->curln, twin->curcol); } break; } str_trim(buf); if (*buf) fprintf(flog, "%s%s: %s%s\n", (twin->eline == b_lines - 1) ? "[1;33m" : "", (twin->eline == b_lines - 1) ? getuserid(currutmp->destuid) : cuser.userid, buf, (ch == Ctrl('P')) ? "[37;45m(Up)[m" : "[m"); }