int cursor_movement(int key, int cursor, char *to_edit) { int move; move = 0; if (key == LEFT && cursor >= PROMPT_LEN - 1) cursor = cursor - 1; else if (key == RIGHT) cursor = cursor + 1; else if (key == END || key == CTRL_E) cursor = ft_strlen(to_edit); else if (key == HOME || key == CTRL_A) cursor = 0; else if (key == SHIFT_RIGHT) { move = size_until_next_word(to_edit, cursor); while (--move > 0) cursor = move_cursor_right(cursor, to_edit); } else if (key == SHIFT_LEFT) { move = size_until_prev_word(to_edit, cursor); while (move-- > 0) if (cursor != 0) cursor = move_cursor_left(cursor, to_edit); } else if (key == PAGE_UP) { cursor = move_cursor_up(cursor, to_edit); } else if (key == PAGE_DOWN) cursor = move_cursor_down(cursor, to_edit); return (cursor); }
void Select_Screen_Logic() { if (is_down_key_pressed()) { if (smcursor != Max_downspace) { move_cursor_down(); } reset_down_key(); } if (is_up_key_pressed()) { if (smcursor != Max_upspace) { move_cursor_up(); } reset_up_key(); } if (is_enter_key_pressed()) { if (smcursor == Single_Player_Y) { is_Single_Player = true; main_menu_mode=GAME_SCREEN; game_mode=CHARACTER_SELECT; if (sound) engine->sound_system->play_music(0,"charsel.mp3",-1); // cpu = new CPU(); } if (smcursor == VS_Player_Y) { is_Single_Player = false; main_menu_mode=GAME_SCREEN; game_mode=CHARACTER_SELECT; if (music) engine->sound_system->play_music(0,"charsel.mp3",-1); } if (smcursor == Opt_Y) { main_menu_mode=OPITION_SCREEN; } reset_enter_key(); } mainbgx-=2; if (mainbgx <= -800) { mainbgx=0; } }
static char * test_cursor_down_end_of_page() { struct display_t *display; struct search_t *search; int terminal_line_nb; char text[] = "this is the first line\n this is the second line\n this is the third line\n this is the fourth line \n "; const char *pattern = "line"; display = create_display(); search = create_search(); terminal_line_nb = 3; parse_text(search, "fake_file", strlen(text), text, pattern); move_cursor_down(display, search, terminal_line_nb); move_cursor_down(display, search, terminal_line_nb); mu_assert("test_cursor_down_end_of_page failed", display->cursor == 0); free_search(search); free_display(display); return 0; }
/** * @brief Handles an input event in this phase. * @param event the event */ void SelectionMenuOptions::notify_event(InputEvent &event) { if (event.is_direction_pressed()) { int direction = event.get_direction(); if (!modifying) { if (direction == 2) { // up move_cursor_up(); } else if (direction == 6) { // down move_cursor_down(); } } else { if (direction == 0) { // right set_option_next_value(); } else if (direction == 4) { // left set_option_previous_value(); } } } else if (event.is_keyboard_key_pressed(validation_keys) || event.is_joypad_button_pressed()) { if (cursor_position < nb_options) { // set an option if (!modifying) { menu->play_ok_sound(); left_arrow_sprite->restart_animation(); right_arrow_sprite->restart_animation(); label_texts[cursor_position]->set_text_color(Color::get_white()); value_texts[cursor_position]->set_text_color(Color::get_yellow()); menu->set_title_text("selection_menu.phase.options.changing"); modifying = true; } else { menu->play_letter_sound(); label_texts[cursor_position]->set_text_color(Color::get_yellow()); value_texts[cursor_position]->set_text_color(Color::get_white()); menu->set_title_text("selection_menu.phase.options"); modifying = false; } } else if (cursor_position == nb_options) { // back menu->play_ok_sound(); menu->set_next_phase(new SelectionMenuSelectFile(menu, 5)); } } }
/** * \brief Tell that a joystick button has been pressed. * \param button The code of the button. * \param joy_index The index of the joytick. */ bool ptb::frame::process_button_press ( bear::input::joystick::joy_code button, unsigned int joy_index ) { switch( button ) { case bear::input::joystick::jc_axis_left: move_cursor_left(); break; case bear::input::joystick::jc_axis_right: move_cursor_right(); break; case bear::input::joystick::jc_axis_up: move_cursor_up(); break; case bear::input::joystick::jc_axis_down: move_cursor_down(); break; } return false; } // frame::process_button_press()
/** * \brief Tell that a key has been pressed. * \param key The code of the key. */ bool ptb::frame::process_key_press( const bear::input::key_info& key ) { if ( key.is_left() ) move_cursor_left(); else if ( key.is_right() ) move_cursor_right(); else if ( key.is_up() ) move_cursor_up(); else if ( key.is_down() ) move_cursor_down(); return false; } // frame::process_key_press()
static char * test_cursor_down_skip_file() { struct display_t *display; struct search_t *search; int terminal_line_nb; char text[] = "this is a the first line\n"; char text2[] = "this is a the first line\n"; const char *pattern = "line"; display = create_display(); search = create_search(); terminal_line_nb = 10; parse_text(search, "fake_file", strlen(text), text, pattern); parse_text(search, "fake_file2", strlen(text), text, pattern); move_cursor_down(display, search, terminal_line_nb); mu_assert("test_cursor_down_skip_file failed", display->cursor == 3); free_search(search); free_display(display); return 0; }
// Wait for input from user, quit if recieved 'q' keypress void Menu::get_keyboard_input() { while (! dying) { // Check if we need to resize window display if (is_term_resized(screen_lines, screen_cols)) { reframe_resized_window(); } // Check if we need to update content (i.e. been longer than 5 seconds) std::chrono::steady_clock::time_point current_time = std::chrono::steady_clock::now(); if (current_time > (last_update + std::chrono::seconds(5))) { get_lines(); } // Update window display after each key press print_window(); // This is blocking ch = getch(); switch(ch) { case KEY_UP: case 'k': move_cursor_up(); break; case KEY_DOWN: case 'j': move_cursor_down(); break; case KEY_LEFT: case 'h': move_cursor_left(); break; case KEY_RIGHT: case 'l': move_cursor_right(); break; case 'q': endwin(); dying = true; break; case KEY_PPAGE: handle_page_up(); break; case KEY_NPAGE: handle_page_down(); break; case KEY_HOME: handle_home(); break; case KEY_END: handle_end(); break; case KEY_ENTER: case 10: case 13: handle_enter_key(); break; default: // Uncoded key, ignore break; } } }
void move_cursor_down_and_refresh(struct display_t *display, struct search_t *search) { int terminal_line_nb = LINES; move_cursor_down(display, search, terminal_line_nb); display_results(display, search, terminal_line_nb); }
/* Many execution paths may lead to this code so it needs to take appropriate * precausions to stuff like doc_view and doc_view->vs being NULL. */ enum frame_event_status do_action(struct session *ses, enum main_action action_id, int verbose) { enum frame_event_status status = FRAME_EVENT_OK; struct terminal *term = ses->tab->term; struct document_view *doc_view = current_frame(ses); struct link *link = NULL; if (action_id == -1) goto unknown_action; if (doc_view && doc_view->vs) { if (action_prefix_is_link_number(KEYMAP_MAIN, action_id) && !try_jump_to_link_number(ses, doc_view)) goto ignore_action; link = get_current_link(doc_view); } else if (action_requires_view_state(KEYMAP_MAIN, action_id)) { goto ignore_action; } if (action_requires_location(KEYMAP_MAIN, action_id) && !have_location(ses)) return FRAME_EVENT_OK; if (action_requires_link(KEYMAP_MAIN, action_id) && !link) goto ignore_action; if (action_requires_form(KEYMAP_MAIN, action_id) && (!link || !link_is_form(link))) goto ignore_action; if (!action_is_anonymous_safe(KEYMAP_MAIN, action_id) && get_cmd_opt_bool("anonymous")) goto ignore_action; /* Please keep in alphabetical order for now. Later we can sort by most * used or something. */ switch (action_id) { case ACT_MAIN_ABORT_CONNECTION: abort_loading(ses, 1); print_screen_status(ses); break; case ACT_MAIN_ADD_BOOKMARK: #ifdef CONFIG_BOOKMARKS launch_bm_add_doc_dialog(term, NULL, ses); #endif break; case ACT_MAIN_ADD_BOOKMARK_LINK: #ifdef CONFIG_BOOKMARKS launch_bm_add_link_dialog(term, NULL, ses); #endif break; case ACT_MAIN_ADD_BOOKMARK_TABS: #ifdef CONFIG_BOOKMARKS bookmark_terminal_tabs_dialog(term); #endif break; case ACT_MAIN_AUTH_MANAGER: auth_manager(ses); break; case ACT_MAIN_BACKSPACE_PREFIX: if (!ses->kbdprefix.repeat_count) break; set_kbd_repeat_count(ses, ses->kbdprefix.repeat_count / 10); /* Keep send_event from resetting repeat_count. */ status = FRAME_EVENT_SESSION_DESTROYED; break; case ACT_MAIN_BOOKMARK_MANAGER: #ifdef CONFIG_BOOKMARKS bookmark_manager(ses); #endif break; case ACT_MAIN_CACHE_MANAGER: cache_manager(ses); break; case ACT_MAIN_CACHE_MINIMIZE: shrink_memory(1); break; case ACT_MAIN_COOKIES_LOAD: #ifdef CONFIG_COOKIES if (!get_opt_bool("cookies.save", NULL)) break; load_cookies(); #endif break; case ACT_MAIN_COOKIE_MANAGER: #ifdef CONFIG_COOKIES cookie_manager(ses); #endif break; case ACT_MAIN_COPY_CLIPBOARD: status = copy_current_link_to_clipboard(ses, doc_view, 0); break; case ACT_MAIN_DOCUMENT_INFO: document_info_dialog(ses); break; case ACT_MAIN_DOWNLOAD_MANAGER: download_manager(ses); break; case ACT_MAIN_EXMODE: #ifdef CONFIG_EXMODE exmode_start(ses); #endif break; case ACT_MAIN_FILE_MENU: activate_bfu_technology(ses, 0); break; case ACT_MAIN_FIND_NEXT: status = find_next(ses, doc_view, 1); break; case ACT_MAIN_FIND_NEXT_BACK: status = find_next(ses, doc_view, -1); break; case ACT_MAIN_FORGET_CREDENTIALS: free_auth(); shrink_memory(1); /* flush caches */ break; case ACT_MAIN_FORMHIST_MANAGER: #ifdef CONFIG_FORMHIST formhist_manager(ses); #endif break; case ACT_MAIN_FRAME_EXTERNAL_COMMAND: status = pass_uri_to_command(ses, doc_view, PASS_URI_FRAME); break; case ACT_MAIN_FRAME_NEXT: next_frame(ses, 1); draw_formatted(ses, 0); break; case ACT_MAIN_FRAME_MAXIMIZE: status = set_frame(ses, doc_view, 0); break; case ACT_MAIN_FRAME_PREV: next_frame(ses, -1); draw_formatted(ses, 0); break; case ACT_MAIN_GOTO_URL: goto_url_action(ses, NULL); break; case ACT_MAIN_GOTO_URL_CURRENT: goto_url_action(ses, get_current_url); break; case ACT_MAIN_GOTO_URL_CURRENT_LINK: goto_url_action(ses, get_current_link_url); break; case ACT_MAIN_GOTO_URL_HOME: goto_url_home(ses); break; case ACT_MAIN_HEADER_INFO: protocol_header_dialog(ses); break; case ACT_MAIN_HISTORY_MANAGER: #ifdef CONFIG_GLOBHIST history_manager(ses); #endif break; case ACT_MAIN_HISTORY_MOVE_BACK: { int count = int_max(1, eat_kbd_repeat_count(ses)); go_history_by_n(ses, -count); break; } case ACT_MAIN_HISTORY_MOVE_FORWARD: { int count = int_max(1, eat_kbd_repeat_count(ses)); go_history_by_n(ses, count); break; } case ACT_MAIN_JUMP_TO_LINK: break; case ACT_MAIN_KEYBINDING_MANAGER: keybinding_manager(ses); break; case ACT_MAIN_KILL_BACKGROUNDED_CONNECTIONS: abort_background_connections(); break; case ACT_MAIN_LINK_DIALOG: open_link_dialog(ses); break; case ACT_MAIN_LINK_DOWNLOAD: case ACT_MAIN_LINK_DOWNLOAD_IMAGE: case ACT_MAIN_LINK_DOWNLOAD_RESUME: status = download_link(ses, doc_view, action_id); break; case ACT_MAIN_LINK_EXTERNAL_COMMAND: status = pass_uri_to_command(ses, doc_view, PASS_URI_LINK); break; case ACT_MAIN_LINK_FOLLOW: status = enter(ses, doc_view, 0); break; case ACT_MAIN_LINK_FOLLOW_RELOAD: status = enter(ses, doc_view, 1); break; case ACT_MAIN_LINK_INFO: link_info_dialog(ses); break; case ACT_MAIN_LINK_MENU: link_menu(term, NULL, ses); break; case ACT_MAIN_LINK_FORM_MENU: link_form_menu(ses); break; case ACT_MAIN_LUA_CONSOLE: #ifdef CONFIG_SCRIPTING_LUA trigger_event_name("dialog-lua-console", ses); #endif break; case ACT_MAIN_MARK_SET: #ifdef CONFIG_MARKS ses->kbdprefix.mark = KP_MARK_SET; status = FRAME_EVENT_REFRESH; #endif break; case ACT_MAIN_MARK_GOTO: #ifdef CONFIG_MARKS /* TODO: Show promptly a menu (or even listbox?) * with all the marks. But the next letter must * still choose a mark directly! --pasky */ ses->kbdprefix.mark = KP_MARK_GOTO; status = FRAME_EVENT_REFRESH; #endif break; case ACT_MAIN_MENU: activate_bfu_technology(ses, -1); break; case ACT_MAIN_MOVE_CURRENT_TOP: status = move_current_top(ses, doc_view); break; case ACT_MAIN_MOVE_CURSOR_UP: status = move_cursor_up(ses, doc_view); break; case ACT_MAIN_MOVE_CURSOR_DOWN: status = move_cursor_down(ses, doc_view); break; case ACT_MAIN_MOVE_CURSOR_LEFT: status = move_cursor_left(ses, doc_view); break; case ACT_MAIN_MOVE_CURSOR_RIGHT: status = move_cursor_right(ses, doc_view); break; case ACT_MAIN_MOVE_CURSOR_LINE_START: status = move_cursor_line_start(ses, doc_view); break; case ACT_MAIN_MOVE_HALF_PAGE_DOWN: status = move_half_page_down(ses, doc_view); break; case ACT_MAIN_MOVE_HALF_PAGE_UP: status = move_half_page_up(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_DOWN: status = move_link_down(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_DOWN_LINE: status = move_link_down_line(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_LEFT: status = move_link_left(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_LEFT_LINE: status = move_link_prev_line(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_NEXT: status = move_link_next(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_PREV: status = move_link_prev(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_RIGHT: status = move_link_right(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_RIGHT_LINE: status = move_link_next_line(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_UP: status = move_link_up(ses, doc_view); break; case ACT_MAIN_MOVE_LINK_UP_LINE: status = move_link_up_line(ses, doc_view); break; case ACT_MAIN_MOVE_PAGE_DOWN: status = move_page_down(ses, doc_view); break; case ACT_MAIN_MOVE_PAGE_UP: status = move_page_up(ses, doc_view); break; case ACT_MAIN_MOVE_DOCUMENT_START: status = move_document_start(ses, doc_view); break; case ACT_MAIN_MOVE_DOCUMENT_END: status = move_document_end(ses, doc_view); break; case ACT_MAIN_OPEN_LINK_IN_NEW_TAB: open_current_link_in_new_tab(ses, 0); break; case ACT_MAIN_OPEN_LINK_IN_NEW_TAB_IN_BACKGROUND: open_current_link_in_new_tab(ses, 1); break; case ACT_MAIN_OPEN_LINK_IN_NEW_WINDOW: open_in_new_window(term, send_open_in_new_window, ses); break; case ACT_MAIN_OPEN_NEW_TAB: open_uri_in_new_tab(ses, NULL, 0, 1); break; case ACT_MAIN_OPEN_NEW_TAB_IN_BACKGROUND: open_uri_in_new_tab(ses, NULL, 1, 1); break; case ACT_MAIN_OPEN_NEW_WINDOW: open_in_new_window(term, send_open_new_window, ses); break; case ACT_MAIN_OPEN_OS_SHELL: exec_shell(term); break; case ACT_MAIN_OPTIONS_MANAGER: options_manager(ses); break; case ACT_MAIN_QUIT: exit_prog(ses, 1); break; case ACT_MAIN_REALLY_QUIT: exit_prog(ses, 0); break; case ACT_MAIN_REDRAW: redraw_terminal_cls(term); break; case ACT_MAIN_RELOAD: reload(ses, CACHE_MODE_INCREMENT); break; case ACT_MAIN_RERENDER: draw_formatted(ses, 2); break; case ACT_MAIN_RESET_FORM: status = reset_form(ses, doc_view, 0); break; case ACT_MAIN_RESOURCE_INFO: resource_info(term); break; case ACT_MAIN_SAVE_AS: status = save_as(ses, doc_view, 0); break; case ACT_MAIN_SAVE_FORMATTED: status = save_formatted_dlg(ses, doc_view, 0); break; case ACT_MAIN_SAVE_OPTIONS: write_config(term); break; case ACT_MAIN_SAVE_URL_AS: save_url_as(ses); break; case ACT_MAIN_SCROLL_DOWN: status = scroll_down(ses, doc_view); break; case ACT_MAIN_SCROLL_LEFT: status = scroll_left(ses, doc_view); break; case ACT_MAIN_SCROLL_RIGHT: status = scroll_right(ses, doc_view); break; case ACT_MAIN_SCROLL_UP: status = scroll_up(ses, doc_view); break; case ACT_MAIN_SEARCH: status = search_dlg(ses, doc_view, 1); break; case ACT_MAIN_SEARCH_BACK: status = search_dlg(ses, doc_view, -1); break; case ACT_MAIN_SEARCH_TYPEAHEAD: case ACT_MAIN_SEARCH_TYPEAHEAD_LINK: case ACT_MAIN_SEARCH_TYPEAHEAD_TEXT: case ACT_MAIN_SEARCH_TYPEAHEAD_TEXT_BACK: status = search_typeahead(ses, doc_view, action_id); break; case ACT_MAIN_SHOW_TERM_OPTIONS: terminal_options(term, NULL, ses); break; case ACT_MAIN_SUBMIT_FORM: status = submit_form(ses, doc_view, 0); break; case ACT_MAIN_SUBMIT_FORM_RELOAD: status = submit_form(ses, doc_view, 1); break; case ACT_MAIN_TAB_CLOSE: close_tab(term, ses); status = FRAME_EVENT_SESSION_DESTROYED; break; case ACT_MAIN_TAB_CLOSE_ALL_BUT_CURRENT: close_all_tabs_but_current(ses); break; case ACT_MAIN_TAB_EXTERNAL_COMMAND: status = pass_uri_to_command(ses, doc_view, PASS_URI_TAB); break; case ACT_MAIN_TAB_MOVE_LEFT: move_current_tab(ses, -1); break; case ACT_MAIN_TAB_MOVE_RIGHT: move_current_tab(ses, 1); break; case ACT_MAIN_TAB_MENU: assert(ses->tab == get_current_tab(term)); if (ses->status.show_tabs_bar) tab_menu(ses, ses->tab->xpos, term->height - 1 - ses->status.show_status_bar, 1); else tab_menu(ses, 0, 0, 0); break; case ACT_MAIN_TAB_NEXT: switch_current_tab(ses, 1); break; case ACT_MAIN_TAB_PREV: switch_current_tab(ses, -1); break; case ACT_MAIN_TERMINAL_RESIZE: resize_terminal_dialog(term); break; case ACT_MAIN_TOGGLE_CSS: #ifdef CONFIG_CSS toggle_document_option(ses, "document.css.enable"); #endif break; case ACT_MAIN_TOGGLE_DISPLAY_IMAGES: toggle_document_option(ses, "document.browse.images.show_as_links"); break; case ACT_MAIN_TOGGLE_DISPLAY_TABLES: toggle_document_option(ses, "document.html.display_tables"); break; case ACT_MAIN_TOGGLE_DOCUMENT_COLORS: toggle_document_option(ses, "document.colors.use_document_colors"); break; case ACT_MAIN_TOGGLE_HTML_PLAIN: toggle_plain_html(ses, ses->doc_view, 0); break; case ACT_MAIN_TOGGLE_MOUSE: #ifdef CONFIG_MOUSE toggle_mouse(); #endif break; case ACT_MAIN_TOGGLE_NUMBERED_LINKS: toggle_document_option(ses, "document.browse.links.numbering"); break; case ACT_MAIN_TOGGLE_PLAIN_COMPRESS_EMPTY_LINES: toggle_document_option(ses, "document.plain.compress_empty_lines"); break; case ACT_MAIN_TOGGLE_WRAP_TEXT: toggle_wrap_text(ses, ses->doc_view, 0); break; case ACT_MAIN_VIEW_IMAGE: status = view_image(ses, doc_view, 0); break; case ACT_MAIN_SCRIPTING_FUNCTION: case ACT_MAIN_NONE: case MAIN_ACTIONS: default: unknown_action: if (verbose) { INTERNAL("No action handling defined for '%s'.", get_action_name(KEYMAP_MAIN, action_id)); } status = FRAME_EVENT_IGNORED; } ignore_action: /* XXX: At this point the session may have been destroyed */ if (status != FRAME_EVENT_SESSION_DESTROYED && ses->insert_mode == INSERT_MODE_ON && link != get_current_link(doc_view)) ses->insert_mode = INSERT_MODE_OFF; if (status == FRAME_EVENT_REFRESH && doc_view) refresh_view(ses, doc_view, 0); return status; }
void dialog(XEvent *event, KeySym keysym, char *buffer) { InputItem *item; item = gWindow->page->current_item; if (item == 0) { if (!((keysym >= XK_Shift_L) && (keysym <= XK_Hyper_R))) /** if something other than a modifier key was hit **/ BeepAtTheUser(); return; } /* * First check if the user had hit an enter key */ if ((keysym == XK_Return) || (keysym == XK_KP_Enter)) enter_new_line(item); /* * Else did the user actual type a character I can understand */ else if (((keysym >= XK_KP_Space) && (keysym <= XK_KP_9)) || ((keysym >= XK_space) && (keysym <= XK_asciitilde))) { /* only handle normal keys */ if (event->xkey.state & UnsupportedModMask) BeepAtTheUser(); else add_buffer_to_sym(buffer, item); } else if ((keysym >= XK_Shift_L) && (keysym <= XK_Hyper_R)) ; /* * do nothing, a modifier was hit */ else if ((keysym >= XK_F2) && (keysym <= XK_F35)) { /* * A function key was hit */ if (strlen(buffer) == 0) BeepAtTheUser(); else /* If I got characters then add it to the buffer */ add_buffer_to_sym(buffer, item); } else switch (keysym) { case XK_Escape: if (event->xkey.state & ModifiersMask) BeepAtTheUser(); else { move_cursor_home(item); delete_rest_of_line(item); } break; case XK_F1: if (event->xkey.state & ModifiersMask) BeepAtTheUser(); else { gWindow->page->helppage = alloc_string(InputAreaHelpPage); helpForHyperDoc(); } break; case XK_Up: if (event->xkey.state & ModifiersMask) BeepAtTheUser(); else move_cursor_up(item); break; case XK_Down: if (event->xkey.state & ModifiersMask) BeepAtTheUser(); else move_cursor_down(item); break; case XK_Delete: if (event->xkey.state & ModifiersMask) BeepAtTheUser(); else delete_char(item); break; case XK_BackSpace: if (event->xkey.state & ModifiersMask) BeepAtTheUser(); else back_over_char(item); break; case XK_Left: if (event->xkey.state & ModifiersMask) BeepAtTheUser(); else move_cursor_backward(item); break; case XK_Right: if (event->xkey.state & ModifiersMask) BeepAtTheUser(); else move_cursor_forward(item); break; case XK_Insert: if (event->xkey.state & ModifiersMask) BeepAtTheUser(); else { gInInsertMode = ((gInInsertMode) ? (0) : (1)); item->curr_line->changed = 1; update_inputsymbol(item); } break; case XK_Home: if (event->xkey.state & ModifiersMask) BeepAtTheUser(); else move_cursor_home(item); break; case XK_End: if (event->xkey.state & ControlMask) /* delete from here to the end of the line */ delete_rest_of_line(item); else if (event->xkey.state & ModifiersMask) BeepAtTheUser(); else move_cursor_end(item); break; default: BeepAtTheUser(); break; } }
void bsod_frame() { static const char *HEX_Digits = "0123456789ABCDEF"; struct event e; e=event_get(); while (e.type != no_event) { switch(e.type) { case evt_keyboard_press: switch (e.kbd.key) { case 0x52: move_cursor_up(); break; case 0x51: move_cursor_down(); break; case 0x50: move_cursor_left(); break; case 0x4F: move_cursor_right(); break; default: if (e.kbd.key < 100) { if (e.kbd.key == 42) // backspace { move_cursor_left(); vram[cursor.y][cursor.x] = 32; } else if (e.kbd.key == 40) // enter { //move_cursor_return(); // special behavior here... } else { vram[cursor.y][cursor.x] = e.kbd.sym; move_cursor_right(); } } message("pressed %d with mod %d\n", e.kbd.key, e.kbd.mod); print_at(31,18,"KB pressed "); vram[18][45]=HEX_Digits[(e.kbd.key>>4) & 0xF]; vram[18][46]=HEX_Digits[e.kbd.key&0xf]; } break; case evt_keyboard_release: print_at(31,18,"KB released "); vram[18][45]=HEX_Digits[(e.kbd.key>>4) & 0xF]; vram[18][46]=HEX_Digits[e.kbd.key&0xf]; break; case evt_device_change: // It seems the disconnect event is not sent currently... if (e.device.type == device_unconnected) print_at(31, 18, "dev. unconnected"); else if (e.device.type == device_keyboard) print_at(31, 18, "keyboard found! "); break; case evt_user: print_at(31, 18, "user event "); break; default: print_at(31, 18, "UNHANDLED "); } e=event_get(); } }
int main(int argc, char *argv[]) { char puzzle[82]; sudoku_hint hints[81]; sudoku_hint *hint; int hint_cells[9]; int ch; /* getch */ int i, t; /* temp */ int r, c, n; /* more temp */ int cr = 1; /* cursor position */ int cc = 1; /* cursor position */ int flags = 0; boardy = 1; boardx = 1; cellh = 3; cellw = 7; initscr(); noecho(); cbreak(); keypad(stdscr, TRUE); getmaxyx(stdscr, winh, winw); init_msg_area(); init_panels(); /* set up and draw board */ init_board(&board); nc_init_board(&ncboard, stdscr, &board, boardy, boardx, cellh, cellw); draw_board(&ncboard); print_title_area("%s", str_entry_mode); update_panels(); doupdate(); move_cursor(&ncboard, cr, cc); while ((ch = getch()) != 'q') { if (flags & ERROR_BIT) { clear_msg(); flags ^= ERROR_BIT; } switch (ch) { case 0xC: /* ^L form feed FF clear screen */ unhighlight_all(&ncboard); draw_board(&ncboard); touchwin(curscr); wrefresh(curscr); break; case '?': /* show help */ print_msg("%s", str_help); break; case 'h': move_cursor_left(&ncboard, &cr, &cc); break; case 'j': move_cursor_down(&ncboard, &cr, &cc); break; case 'k': move_cursor_up(&ncboard, &cr, &cc); break; case 'l': move_cursor_right(&ncboard, &cr, &cc); break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': set_value(&board, cr, cc, ch); draw_cell(&ncboard, cr, cc); break; case ' ': case 'd': case 0x08: /* ^H */ case KEY_BACKSPACE: set_value(&board, cr, cc, ' '); /* erase */ draw_cell(&ncboard, cr, cc); break; case 'c': unhighlight_all(&ncboard); clear_board(&board); draw_board(&ncboard); break; case 'f': toggle_fix_mode(&board); /* if entering fixed mode, validate and solve puzzle */ if (get_givens(&board, puzzle) != NULL) { /* if puzzle invalid */ if (!sudoku_solve_hints(puzzle, hints)) { toggle_fix_mode(&board); print_msg("Error: %s", str_invalid_puzzle); flags |= ERROR_BIT; } else { /* puzzle valid, but check uniqueness */ print_title_area("%s", str_solve_mode); if (sudoku_nsolve(puzzle, NULL, 2) > 1) { print_msg("%s", str_not_unique); flags |= ERROR_BIT; flags |= HINTS_DISABLED; } } } else { print_title_area("%s", str_entry_mode); flags &= ~ HINTS_DISABLED; } /* toggle_fix_mode (un)bolds every char so refresh needed */ draw_board(&ncboard); break; case 'u': t = undo_board(&board); /* only works in fixed mode */ if (t >= 0) { cr = t / 9 + 1; cc = t % 9 + 1; draw_cell(&ncboard, cr, cc); } break; case 's': /* solve puzzle if in fixed mode */ if (!is_fixed(&board)) { print_msg("%s: %s", str_not_fixed, "press 'f' to fix the givens first."); flags |= ERROR_BIT; break; } /* else */ for (i = 0; i < 81; i++) { hint2rcn(hints + i, &cr, &cc, &t); set_value(&board, cr, cc, t % 10 + '0'); } draw_board(&ncboard); break; case 'H': /* give hint, if in fixed mode */ if (!is_fixed(&board)) { print_msg("%s: %s", str_not_fixed, "Hints are only given in solver mode."); flags |= ERROR_BIT; break; } if (flags & HINTS_DISABLED) break; unhighlight_all(&ncboard); get_values(&board, puzzle); hint = next_hint(hints, puzzle); if (hint - hints == 81) break; t = hint2cells(hint, hint_cells); for (i = 0; i < t; i++) { c = hint_cells[i]; r = c / 9 + 1; c = c % 9 + 1; highlight_cell(&ncboard, r, c); } if (t > 1) { hint2rcn(hint, &r, &c, &n); print_msg("Hint: try a %d in the highlighted cells", n); } draw_board(&ncboard); break; } update_panels(); doupdate(); move_cursor(&ncboard, cr, cc); } endwin(); return 0; }