Exemplo n.º 1
0
static void move_up()
{
	if( history_up() )
	{
		set_string_from_history();
	}
}
Exemplo n.º 2
0
static int
key_action_history_up (GtkWidget * wid, GdkEventKey * ent, char *d1, char *d2,
							  struct session *sess)
{
	char *new_line;

	new_line = history_up (&sess->history, SPELL_ENTRY_GET_TEXT (wid));
	if (new_line)
	{
		SPELL_ENTRY_SET_TEXT (wid, new_line);
		SPELL_ENTRY_SET_POS (wid, -1);
	}

	return 2;
}
Exemplo n.º 3
0
static void text_entry_history_up(GtkEntry *entry)
{
        TextEntry *text_entry;
        char *new_line;

        text_entry = TEXT_ENTRY(entry);
        if (text_entry->priv->session == NULL) {
                return;
        }

        new_line =
            history_up(&(text_entry->priv->session->history), (char *)gtk_entry_get_text(entry));
        if (new_line) {
                gtk_entry_set_text(entry, new_line);
                gtk_editable_set_position(GTK_EDITABLE(entry), -1);
        }
}
Exemplo n.º 4
0
static int process_escape(t_tokenline *tl)
{
	if (tl->escape_len == 4) {
		if (!strncmp(tl->escape, "\x1b\x5b\x33\x7e", 4)) {
			/* Delete */
			line_delete_char(tl);
		} else if (!strncmp(tl->escape, "\x1b\x5b\x31\x7e", 4)) {
			/* Home */
			line_home(tl);
		} else if (!strncmp(tl->escape, "\x1b\x5b\x34\x7e", 4)) {
			/* End */
			line_end(tl);
		}
	} else if (tl->escape_len == 3) {
		if (!strncmp(tl->escape, "\x1b\x5b\x41", 3)) {
			/* Up arrow */
			history_up(tl);
		} else if (!strncmp(tl->escape, "\x1b\x5b\x42", 3)) {
			/* Down arrow */
			history_down(tl);
		} else if (!strncmp(tl->escape, "\x1b\x5b\x44", 3)) {
			/* Left arrow */
			if (tl->pos > 0) {
				tl->pos--;
				tl->print(tl->user, "\x1b\x5b\x31\x44");
			}
		} else if (!strncmp(tl->escape, "\x1b\x5b\x43", 3)) {
			/* Right arrow */
			if (tl->pos < tl->buf_len) {
				tl->pos++;
				tl->print(tl->user, "\x1b\x5b\x31\x43");
			}
		} else if (!strncmp(tl->escape, "\x1b\x4f\x48", 3)) {
			/* Home */
			line_home(tl);
		} else if (!strncmp(tl->escape, "\x1b\x4f\x46", 3)) {
			/* End */
			line_end(tl);
		} else
			return FALSE;
	} else
		return FALSE;

	return TRUE;
}
Exemplo n.º 5
0
void ttext_box::handle_key_default(bool& handled,
								   SDLKey key,
								   SDLMod modifier,
								   const utf8::string& unicode)
{
	if(key == SDLK_TAB && (modifier & KMOD_CTRL)) {
		if(!(modifier & KMOD_SHIFT)) {
			handled = history_up();
		} else {
			handled = history_down();
		}
	}

	if(!handled) {
		// Inherited.
		ttext_::handle_key_default(handled, key, modifier, unicode);
	}
}
Exemplo n.º 6
0
void			edition(t_termcap *term, t_history **history,
				struct winsize *mysizewin, int count)
{
  if (term->buff == CTRL_K)
    term->tmp = ctrl_k(term->str, &term->data, &term->x);
  else if (term->buff == CTRL_Y)
    {
      if (term->tmp != NULL)
	term->str = ctrl_y(term->str, term->tmp, &term->x, &term->data);
    }
  else if (term->buff == CTRL_L)
    ctrl_l(term->str, &term->data);
  else if (term->buff == DOWN)
    term->str = history_down(history, term, mysizewin);
  else if (term->buff == UP)
    term->str = history_up(history, term, mysizewin);
  else if (count == 0)
    term->str = write_normally(term->str, term->buff, &term->x, &term->data);
}
Exemplo n.º 7
0
void		mvcursor(char *buff, char **ptr, t_history *history)
{
    char inputs[3];

    read(0, inputs, 3);
    if (inputs[1] == 'A' && history)
        history_up(buff, ptr, history);
    else if (inputs[1] == 'D' && buff < (*ptr))
    {
        mvcleft(1);
        (*ptr)--;
    }
    else if (inputs[1] == 'B' && history)
        history_down(buff, ptr, history);
    else if (inputs[1] == 'C' && *(*ptr))
    {
        mvcright(1);
        (*ptr)++;
    }
    else
        splitted_mvcursor(inputs, buff, ptr);
}
Exemplo n.º 8
0
void telnet_console_connection::process_input(int len) {
	input_is_updated = false;

	int last = -1;

	int i, min_was = inputbuf.size();
	int was_input = inputbuf.size();

	for (i = 0; i < len; i++) {
		if (pmode == 0) {
			if ((buffer[i] == '\n' || buffer[i] == 0) && last == '\r') {
				if (!process_line(inputbuf.c_str())) {
					shutdown();
					delete this;
					return;
				}
				inputbuf = ""; // eh.. g++ 2.95's libstdc++ doesn't have string::clear()
			} else if (buffer[i] == '\r') {
			} else if (buffer[i] == 4) { // Ctrl-D
				console->release_connection(this);
				return;
			} else if (buffer[i] == IAC) {
				pmode = 1;
			} else if (buffer[i] == 127 || buffer[i] == 8) {
				if (!inputbuf.empty()) {
					inputbuf.resize(inputbuf.size() - 1);
					if ((int)inputbuf.size() < min_was)
						min_was = inputbuf.size();
				}
			} else {
				bool eat = false;
				if (authenticate_state == GotAllData) {
					if (buffer[i] == '\t') {
						if (tabcomplete())
							redisplay_input();
					} else if (buffer[i] == '?') {
						std::string wki = inputbuf;
						wki += '?';
						writeclient("?\r\n");
						dump_partial(wki.c_str());
						redisplay_input();
					} else if (isprint(buffer[i])) {
						eat = true;
					} else if (buffer[i] == 21) {
						/* Control-U */

						inputbuf.clear();
						clearline();
						redisplay_input();
					} else if (buffer[i] == 23) {
						/* Control-W */

						int i = inputbuf.size();
						for (; i > 0 && isspace(inputbuf[i-1]); i--);
						for (; i > 0 && !isspace(inputbuf[i-1]); i--);
						inputbuf.resize(i);
						clearline();
						redisplay_input();
					} else if (buffer[i] == '\033') {
						/* <ESC> */

						/* VT100 command */
						if ((len - i) >= 3) {
							if (buffer[i+1] == '[') {
								if (buffer[i+2] == 'A') {
									/* Up */
									history_up();
								} else if (buffer[i+2] == 'B') {
									/* Down */
									history_down();
								}
							}

							i += 2;
						}
					}
				} else {
					eat = true;
				}
				if (eat)
					inputbuf.push_back(buffer[i]);
			}
		} else if (pmode == 1) {
			ctlbuf.push_back(buffer[i]);
			if (process_cmd() && ctlbuf.empty())
				pmode = 0;
		}
		last = buffer[i];
	}

	// Ugly code ahead.
	if (should_echo && !input_is_updated) {
		std::string buf;
		for (i = min_was; i < was_input; i++) {
			buf.push_back('\b');
		}
		int len = inputbuf.size();
		if (len >= was_input) {
			for (i = min_was; i < len; i++) {
				buf.push_back(inputbuf[i]);
			}
		} else {
			for (i = len; i < was_input; i++) {
				buf.push_back(' ');
			}
			for (i = len; i < was_input; i++) {
				buf.push_back('\b');
			}
		}
		writeclient(buf.c_str());
	}
}
Exemplo n.º 9
0
int tl_input(t_tokenline *tl, uint8_t c)
{
	int ret, i;

	if (tl->escape_len) {
		tl->escape[tl->escape_len++] = c;
		if (process_escape(tl))
			tl->escape_len = 0;
		else if (tl->escape_len == TL_MAX_ESCAPE_LEN)
			/* Not a valid escape sequence, and buffer full. */
			tl->escape_len = 0;
		return TRUE;
	}

	ret = TRUE;
	switch (c) {
	case 0x1b:
		/* Start of escape sequence. */
		tl->escape[tl->escape_len++] = c;
		break;
	case '\r':
	case '\n':
		process_line(tl);
		break;
	case '\t':
		if (tl->buf_len == tl->pos)
			complete(tl);
		break;
	case 0x7f:
		/* Backspace */
		if (tl->pos)
			line_backspace(tl);
		break;
	case 0x01:
		/* Ctrl-a */
		while (tl->pos) {
			tl->pos--;
			tl->print(tl->user, "\x1b\x5b\x44");
		}
		break;
	case 0x03:
		/* Ctrl-c */
		tl->print(tl->user, "^C");
		tl->buf_len = 0;
		process_line(tl);
		break;
	case 0x04:
		/* Ctrl-d */
		if (tl->buf_len)
			line_delete_char(tl);
		else
			/* Ctrl-d on empty line exits. */
			ret = FALSE;
		break;
	case 0x05:
		/* Ctrl-e */
		while (tl->pos < tl->buf_len) {
			tl->pos++;
			tl->print(tl->user, "\x1b\x5b\x43");
		}
		break;
	case 0x0b:
		/* Ctrl-k */
		if (tl->buf_len > tl->pos) {
			for (i = 0; i < tl->buf_len - tl->pos; i++)
				tl->print(tl->user, " ");
			for (i = 0; i < tl->buf_len - tl->pos; i++)
				tl->print(tl->user, "\x1b\x5b\x44");
			tl->buf_len = tl->pos;
			tl->buf[tl->buf_len] = 0;
		}
		break;
	case 0x0c:
		/* Ctrl-l */
		tl->print(tl->user, "\x1b\x5b\x32\x4a\x1b\x5b\x48");
		tl->print(tl->user, tl->prompt);
		tl->print(tl->user, tl->buf);
		break;
	case 0x10:
		/* Ctrl-p */
		history_up(tl);
		break;
	case 0x0e:
		/* Ctrl-n */
		history_down(tl);
		break;
	case 0x17:
		/* Ctrl-w */
		while (tl->pos && tl->buf[tl->pos - 1] == ' ')
			line_backspace(tl);
		while (tl->pos && tl->buf[tl->pos - 1] != ' ')
			line_backspace(tl);
		break;
	default:
		if (c >= 0x20 && c <= 0x7e) {
			if (tl->buf_len < TL_MAX_LINE_LEN - 1)
				add_char(tl, c);
			tl->hist_step = -1;
		}
		break;
	}

	return ret;
}
Exemplo n.º 10
0
int do_cap(char* inp)
{
	char* dir;
	int   count;

	if(my_strcmp(inp, KL) == 0)
	{
		if(gl_env.pos > 0)
		{
			tputs(gl_env.backspace, 1, my_termprint);
			gl_env.pos--;
		}
		
		return 1;
	}
	else if(my_strcmp(inp, KR) == 0)
	{
		if(gl_env.pos < gl_env.count)
		{
			tputs(gl_env.move_right, 1, my_termprint);
			gl_env.pos++;
		}

		return 1;
	}
	else if(my_strcmp(inp, KU) == 0)
	{
		if(gl_env.current_history > 0 && my_strcmp(gl_env.history[gl_env.current_history - 1], "") != 0)
		{
			history_up();
		}

		return 1;
	}
	else if(my_strcmp(inp, KD) == 0)
	{
		if(gl_env.current_history < HISTORY_SIZE - 1)
		{
			history_down();
		}

		return 1;
	}
	else if(inp[0] == CTRL_L)
	{
		tputs(gl_env.clear, 1, my_termprint);
		my_str(gl_env.dir);
	    my_str(": ");
	    rewrite_pos_to_end(0, gl_env.current_history);
		count = 0;
		while(count++ < gl_env.pos)
		{
			tputs(gl_env.move_right, 1, my_termprint);
		}
		return 1;
	}
	else if(inp[0] == CTRL_A)
	{
		move_cursor_to_pos(0);
		gl_env.pos = 0;
		return 1;
	}
	else if(inp[0] == CTRL_E)
	{
		move_cursor_to_pos(gl_env.count);
		gl_env.pos = gl_env.count;
		return 1;
	}

	return 0;
}