Ejemplo n.º 1
0
void			movements_delete(int a)
{
	int h[2];

	tputs(tgetstr("cd", NULL), 0, tputs_putchar);
	h[0] = ft_putstr_i(g_shell.shell_line, g_cursor.position_line);
	h[1] = h[0];
	while (h[0] - 1 > 0)
	{
		move_cursor_right(g_cursor, g_shell);
		h[0]--;
	}
	if ((g_cursor.position_x_rel == g_shell.shell_win_size - 1) && \
			g_cursor.position_line != g_shell.length_line)
	{
		ft_putstr(" ");
		tputs(tgetstr("le", NULL), 0, tputs_putchar);
	}
	move_cursor_right(g_cursor, g_shell);
	while (h[1] - a > 0)
	{
		go_left(g_cursor, g_shell);
		move_cursor_left(g_cursor, g_shell);
		h[1]--;
	}
}
Ejemplo n.º 2
0
int 	move_cursor_left(int col, int num_cols)
{
	/* -------------------------------------------------------
	 *  moves cursor left by num_cols columns.  if col is leftmost,
	 *  then it goes back to the end of the previous line
	 *  returns 0 if success, != 0 if error
	 * -------------------------------------------------------
	 */
	int	fildes = ((d_tt_struct *)((io_curr_device.in)->dev_sp))->fildes;
	int	ret;

	if (0 == num_cols)
		ret = 0;
	else if (0 > num_cols)
		ret = move_cursor_right(col, -num_cols);
	else if (0 < col)
	{
		ret = write_loop(fildes, (unsigned char *)CURSOR_LEFT, MIN(col, num_cols));
		num_cols -= MIN(col, num_cols);
		if (num_cols)
		{
			DOWRITERC(fildes, CURSOR_UP, strlen(CURSOR_UP), ret);
			if (0 > ret)
				return -1;
			ret = write_loop(fildes, (unsigned char *)CURSOR_RIGHT, io_curr_device.in->width - num_cols);
		}
	} else
	{
		DOWRITERC(fildes, CURSOR_UP, strlen(CURSOR_UP), ret);
		if (0 > ret)
			return -1;
		ret = write_loop(fildes, (unsigned char *)CURSOR_RIGHT, io_curr_device.in->width - num_cols);
	}
	return ret;
}
Ejemplo n.º 3
0
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);
}
Ejemplo n.º 4
0
static int	parse_key_five(size_t key, t_cmds **cmd, t_shell *shell)
{
	if ((*cmd)->cp > -1)
	{
		(*cmd)->cp = -1;
		edit_cmd_cp(*cmd);
	}
	else if (key == 9)
		tab_search(cmd, shell);
	else if (key == 4)
		return (quest_close(cmd, shell));
	else if (key == 190 && (*cmd)->pointer > 0 && !(*cmd)->line)
	{
		move_cursor_left((*cmd)->pointer, (*cmd)->pointer);
		(*cmd)->pointer = 0;
	}
	else if (key == 188 && (*cmd)->pointer < (int)ft_strlen((*cmd)->cmd) && !(*cmd)->line)
	{
		move_cursor_right((*cmd)->pointer, ft_strlen((*cmd)->cmd) - (*cmd)->pointer);
		(*cmd)->pointer = ft_strlen((*cmd)->cmd);
	}
	else
		return (0);
	return (1);
}
void		move_cursor_word_right(t_edited_line *line)
{
	char	c;

	c = *(char*)line->data->curr->content;
	if (!is_space(c) && !is_correct_word_char(c))
		move_cursor_right(line);
	else
	{
		while (line->data->curr
			&& is_space(*(char*)line->data->curr->content))
			move_cursor_right(line);
		while (line->data->curr
			&& is_correct_word_char(*(char*)line->data->curr->content))
			move_cursor_right(line);
	}
}
Ejemplo n.º 6
0
void			press_right_key(void)
{
	if (g_cursor.position_line < g_shell.length_line)
	{
		if (g_shell.backslash_index != -1)
			g_shell.backslash_index++;
		go_right(g_cursor, g_shell);
		move_cursor_right(g_cursor, g_shell);
	}
}
Ejemplo n.º 7
0
void edit_in_escape_mode()
{
	char ch;
	editor_mode = ESCAPE_MODE;
	ch = getch();
	switch(ch)
	{
		case 'i':
			edit_in_insert_mode();
		break;
		case ':':
			edit_in_colon_mode();
		break;
		case 'd':
			 if(getch() == 'd')
			 {
				 delete_current_line();
				 flush_on_screen();
			 }
			 else
			 {
				 //invalid option..
			 }
		break;
		case 'x':
				 delete_current_character();
				 flush_on_screen();
		break;
		case 'k':
			//up arrow
			/*if(cursor_position.y == TOPMOST_DISPLAY_LINE_NUMBER)
				move_displayed_data_one_line_down();
			else
				move_cursor_up();*/
		break;
		case 'j':
			//down arrow
			/*if(cursor_position.y == BOTTOMMOST_DISPLAY_LINE_NUMBER)
				move_displayed_data_one_line_up();
			else
				move_cursor_down();*/
		break;
		case 'h':
			//left arrow
			move_cursor_left();
		break;
		case 'l':
			//right arrow
			move_cursor_right();
		break;
	}
}
Ejemplo n.º 8
0
/**
 * \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()
Ejemplo n.º 9
0
/**
 * \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()
Ejemplo n.º 10
0
void			press_end_key(void)
{
	int			h;

	h = g_cursor.position_line;
	while (h < g_shell.length_line)
	{
		if (g_shell.backslash_index != -1)
			g_shell.backslash_index++;
		go_right(g_cursor, g_shell);
		move_cursor_right(g_cursor, g_shell);
		h++;
	}
}
Ejemplo n.º 11
0
void	refresh_stdout(char *g_cmd)
{
	int old_pos;

	old_pos = g_cursor_pos;
	save_cursor_pos();
	while (g_cursor_pos >= 1 && (g_cmd[g_cursor_pos]
		|| g_cmd[g_cursor_pos - 1]))
		move_cursor_left();
	delete_x_characters(ft_strlen(g_cmd));
	write(1, " ", 1);
	write(1, g_cmd, ft_strlen(g_cmd));
	g_cursor_pos = old_pos - 1;
	set_saved_cursor();
	move_cursor_right();
}
Ejemplo n.º 12
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;
        }
    }
}
Ejemplo n.º 13
0
/* 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;
}
Ejemplo n.º 14
0
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();
    }
}
Ejemplo n.º 15
0
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;
}