Example #1
0
void screen_move_down(struct te_buffer *buf)
{
	if (buf == NULL)
		return;

	if (buf->point == blength(buf->contents))
	    return;

	int	i = 0;
	int	old_x = buf->x;

	do {
		/* move until the first char of the next line */
		if (move_right(buf) == ERR)
			break;

	} while (prev_char(buf) != '\n');

	screen_next_line(buf);

	/* mimic emacs' behaviour of moving the user to the exact offset we were on */
	while (buf->x < old_x && curr_char(buf) != '\n') {
		if(screen_move_right(buf) == ERR)
			return;
	}

	move(buf->y, buf->x);
	return;
}
Example #2
0
void screen_move_up(struct te_buffer *buf)
{
	if (buf == NULL)
		return;

	int	i = 0;
	int	old_x = buf->x;

	/* move until the first character of the line */
	while(prev_char(buf) != '\n') {
		if(move_left(buf) == ERR)
			break;
	} 
	move_left(buf);

	/* then, move to the beginning of the previous line */
	while(prev_char(buf) != '\n') {
		if(move_left(buf) == ERR)
			break;
	}

 	screen_prev_line(buf);
 	buf->x = 0; 

	/* mimic emacs' behaviour of moving the user to the exact offset we were on */
		
	while(buf->x < old_x && next_char(buf) != '\n' && curr_char(buf) != '\n') {
		if (screen_move_right(buf) == ERR)
			break;
	}

	move(buf->y, buf->x);
	return;
}
Example #3
0
void process_command(int c)
{
			switch(c) {
			case 'q':
				exit(0);

			case 'h':
			case KEY_LEFT:
				screen_move_left(current_buf);
				break;

			case 'l':
			case KEY_RIGHT:
				screen_move_right(current_buf);
				break;

			case 'j':
			case KEY_DOWN:
				screen_move_down(current_buf);
				break;

			case 'k':
			case KEY_UP:
				screen_move_up(current_buf);
				break;

			case 'w':
				write_buffer(current_buf);
				break;

			case 'x':
				screen_delete_char(current_buf);
				break;

			case 'i':
			case 0x1B: /* escape */
			case KEY_END:
				/* switch between command and input mode */
				command_mode = 0;
				miniprintf("-- INPUT --");
				break;

			case 'v':

			case 'b':
			default:
				miniprintf("%c - invalid command", c);
				break;
			}
}
Example #4
0
void screen_insert_char(struct te_buffer *buf, char c)
{
	if (buf == NULL)
		return;

	if (buf->dirty < 1)
		buf->dirty = 1;

	insert_char(buf, c);

	if (c == '\n') {
		clrtoeol();
		clear_nfirst_lines(buffer_win, max(buf->y - 1, 0));
		scroll_down(buffer_win);
		paint_buffer_nlines(buf, buf->y + 1);
		paint_nthline(buf, buf->y + 2, buf->y + 1);
		screen_move_right(buf);
	} else {
		bstring s = current_line_as_bstring(buf->contents, buf->point);
		draw_line(s, buf->y);
		screen_move_right(buf);
	}
}
Example #5
0
void process_input(int c)
{
			switch(c) {
			case KEY_ENTER:
				screen_insert_char(current_buf, '\n');
				break;

			case KEY_BACKSPACE:
				screen_delete_char(current_buf);
				break;

			case KEY_LEFT:
				screen_move_left(current_buf);
				break;

			case KEY_RIGHT:
				screen_move_right(current_buf);
				break;

			case KEY_DOWN:
				screen_move_down(current_buf);
				break;

			case KEY_UP:
				screen_move_up(current_buf);
				break;

			case 0x1B: /* escape */
			case KEY_END:
				command_mode = 1;
				miniprintf("-- COMMAND --");
				break;

			default:
				screen_insert_char(current_buf, c);
				refresh();
				break;
			}

}