/* Multi line low level line refresh. * * Rewrite the currently edited line accordingly to the buffer content, * cursor position, and number of columns of the terminal. */ static void refreshMultiLine(struct linenoiseState *l) { int plen = wcslen(l->prompt); int rows = (plen+l->len+l->cols-1)/l->cols; /* rows used by current buf. */ int rpos = (plen+l->oldpos+l->cols)/l->cols; /* cursor relative row. */ int rpos2; /* rpos after refresh. */ int old_rows = l->maxrows; int j; /* Update maxrows if needed. */ if (rows > (int)l->maxrows) l->maxrows = rows; /* First step: clear all the lines used before. To do so start by * going to the last row. */ if (old_rows-rpos > 0) { console_move_down(old_rows - rpos); } /* Now for every row clear it, go up. */ for (j = 0; j < old_rows-1; j++) { console_move_to_column(0); console_erase_to_end_of_line(); console_move_up(1); } /* Clean the top line. */ console_move_to_column(0); console_erase_to_end_of_line(); /* Write the prompt and the current buffer content */ console_write_wchar_string(l->prompt, plen); console_write_wchar_string(l->buf, l->len); /* If we are at the very end of the screen with our prompt, we need to * emit a newline and move the prompt to the first column. */ if (l->pos && l->pos == l->len && (l->pos+plen) % l->cols == 0) { console_scroll_up(1); console_move_to_column(0); rows++; if (rows > (int)l->maxrows) l->maxrows = rows; } /* Move cursor to right position. */ rpos2 = (plen+l->pos+l->cols)/l->cols; /* current cursor relative row. */ /* Go up till we reach the expected positon. */ if (rows-rpos2 > 0) { console_move_up(rows - rpos2); } /* Set column. */ console_move_to_column(((plen+(int)l->pos) % (int)l->cols)); // console_move_down(1); l->oldpos = l->pos; }
void loop () { active_flag = true; timer = SDL_GetTicks (); update_count = 0; draw_count = 0; before_update_time = timer; after_update_time = before_update_time; before_draw_time = before_update_time; after_draw_time = before_update_time; initialized_flag = true; while (1) { SDL_Event e; // bg_set_backdrop_color(before_update_time); if (SDL_PollEvent(&e)) { if (console_flag && (e.type == SDL_KEYDOWN || e.type == SDL_TEXTINPUT)) { do_console_event(e); continue; } switch(e.type) { case SDL_QUIT: break; case SDL_KEYDOWN: printf("%u %u %d %d %d %d %d %s\n", e.key.timestamp, e.key.windowID, (int)e.key.state, (int)e.key.repeat, (int)e.key.keysym.sym, e.key.keysym.scancode, e.key.keysym.mod, SDL_GetKeyName(e.key.keysym.sym)); if (e.key.keysym.sym == SDLK_RETURN) { console_move_to_column(0); console_move_down(1); } break; case SDL_TEXTEDITING: printf("textedit %s\n", e.edit.text); break; case SDL_TEXTINPUT: printf("textinput %s\n", e.text.text); console_write_utf8_string(e.text.text); break; default: on_idle(); break; } } else on_idle(); SDL_Delay(10); } }
void console_move_page_down() { int max_lines; int i; max_lines=(window_height-hud_y)/18-3; for(i=0;i<max_lines;i++) { console_move_down(); } }
static void do_console_event (SDL_Event e) { switch(e.type) { case SDL_QUIT: break; case SDL_KEYDOWN: if (autocomplete_flag) { ; } else { // Here we process non-textual keys // backspace -> 8 42 0 if (e.key.keysym.sym == SDLK_BACKSPACE) lineedit_backspace(); if (e.key.keysym.sym == SDLK_TAB) lineedit_autocomplete(); if (e.key.keysym.mod == KMOD_LCTRL || e.key.keysym.mod == KMOD_RCTRL) { // ctrl-a -> 97 4 64 if (e.key.keysym.sym == SDLK_a) lineedit_move_home(); // ctrl-b -> 98 5 64 if (e.key.keysym.sym == SDLK_b) lineedit_move_left(); // ctrl-c -> 99 6 64 if (e.key.keysym.sym == SDLK_c) lineedit_ctrl_c(); // ctrl-d -> 100 7 64 if (e.key.keysym.sym == SDLK_d) lineedit_delete_or_eof(); // ctrl-e -> 101 8 64 if (e.key.keysym.sym == SDLK_e) lineedit_move_end(); // ctrl-f -> 102 9 64 if (e.key.keysym.sym == SDLK_f) lineedit_move_right(); // ctrl-h -> 104 11 64 if (e.key.keysym.sym == SDLK_h) lineedit_backspace(); // ctrl-k -> 107 14 64 if (e.key.keysym.sym == SDLK_k) lineedit_delete_to_end(); // ctrl-l -> 108 15 64 if (e.key.keysym.sym == SDLK_l) lineedit_clear_screen(); // ctrl-n -> 110 17 64 if (e.key.keysym.sym == SDLK_n) lineedit_history_next(); // ctrl-p -> 112 19 64 if (e.key.keysym.sym == SDLK_p) lineedit_history_prev(); // ctrl-t -> 116 23 64 if (e.key.keysym.sym == SDLK_t) lineedit_swap_chars(); // ctrl-u -> 117 24 64 if (e.key.keysym.sym == SDLK_u) lineedit_delete_line(); // ctrl-w -> 119 26 64 if (e.key.keysym.sym == SDLK_w) lineedit_delete_word_prev(); } // delete -> 127 76 0 if (e.key.keysym.scancode == SDL_SCANCODE_DELETE) lineedit_delete(); // down -> 1073741905 81 0 if (e.key.keysym.scancode == SDL_SCANCODE_DOWN) lineedit_history_next(); // end -> 1073741901 77 0 if (e.key.keysym.scancode == SDL_SCANCODE_END) lineedit_move_end(); // enter -> 13 40 // home -> 1073741898 74 0 if (e.key.keysym.scancode == SDL_SCANCODE_HOME) lineedit_move_home(); // left -> 1073741904 80 0 if (e.key.keysym.scancode == SDL_SCANCODE_LEFT) lineedit_move_left(); // right -> 1073741903 79 0 if (e.key.keysym.scancode == SDL_SCANCODE_RIGHT) lineedit_move_right(); // up -> 1073741906 82 0 if (e.key.keysym.scancode == SDL_SCANCODE_UP) lineedit_history_prev(); // KP_down -> 1073741914 90 0 // KP_end -> 1073741913 89 0 // KP_enter -> 1073741912 88 // KP_home -> 1073741919 95 0 // KP_left -> 1073741916 92 0 // KP_right -> 1073741918 94 0 // KP_up -> 1073741920 96 0 else if (e.key.keysym.sym == SDLK_TAB) ; else if (e.key.keysym.sym == SDLK_CLEAR) ; else if (e.key.keysym.sym == SDLK_RETURN) ; else if (e.key.keysym.sym == SDLK_PAUSE) ; else if (e.key.keysym.sym == SDLK_DELETE) { } /* printf("%u %u %d %d %d %d %d\n", e.key.timestamp, e.key.windowID, */ /* (int)e.key.state, (int)e.key.repeat, */ /* e.key.keysym.sym, e.key.keysym.scancode, e.key.keysym.mod); */ if (e.key.keysym.scancode == SDL_SCANCODE_RETURN) { // End this lineedit session // Act on the string // Maybe add the string to the history lineedit_stop(); console_move_to_column(0); console_move_down(1); { char *script = lineedit_get_text(); if (strlen(script) > 0) { js_do_console_command(script); } } lineedit_start(buf, 200, L"->"); } } break; case SDL_TEXTEDITING: // printf("textedit %s\n", e.edit.text); break; case SDL_TEXTINPUT: // printf("textinput %s\n", e.text.text); // SDL text is always UTF-8. Convert to wchar_t. do { wchar_t *input = utf8_to_wcs_alloc (e.text.text); if (input != NULL) { if (autocomplete_flag) lineedit_autocomplete_text_input(input); else lineedit_text_input(input); free(input); } } while (0); break; default: on_idle(); break; } }