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

	move_left(buf);
	bstring previous_line = current_line_as_bstring(buf->contents, max(buf->point - 1, 0));
	char c = curr_char(buf);
	delete_char(buf);
	bstring s = current_line_as_bstring(buf->contents, max(buf->point, 0));

	if (c == '\n') {
		statusprintf("s : %s", bstr2cstr(s, '\0'));
		clear_nfirst_lines(buffer_win, max(buf->y, 0));
		scroll_up(buffer_win);
 		paint_buffer_nlines(buf, buf->y + 1); 
		screen_prev_line(buf);
		buf->x = max(screen_line_length(previous_line, 0) - 1, 0); /* max because scr_l_len("a") == 1 and coords begin at 0 */

		move(buf->y, buf->x);
	} else {
		draw_line(s, buf->y);
		screen_move_left(buf);
		move_right(buf); /* yes it's ugly but I don't feel like recoding screen_move_right atm */
	}

	bdestroy(previous_line);
	bdestroy(s);
}
Beispiel #2
0
void screen_prev_line(struct te_buffer *buf)
{
	if (buf == NULL)
		return;

	if (buf->y > 0) {
		buf->y--;
		buf->x = screen_line_length(buf->contents, buf->point);
	} else {

		if (bstrrchrp(buf->contents, '\n', buf->point) == BSTR_ERR) /* is it the first line of the file ? */
			return;

		scroll_down(buffer_win);
		bstring s = current_line_as_bstring(buf->contents, buf->point - 1);
		draw_line(s, 0);
		bdestroy(s);

		/* update buf->top_char */
		s = current_line_as_bstring(buf->contents, buf->top_char);
		buf->top_char -= blength(s);
		buf->top_char = max(buf->top_char, 0);
		bdestroy(s);
	}
}
Beispiel #3
0
void input_loop(void)
{
	while(1) {

		int c = getch();
		
		if (command_mode)
			process_command(c);
		else 
			process_input(c);

		refresh();

		miniprintf("%c, line length: %d, y: %d, x%d",
			   (bchar(current_buf->contents, current_buf->point) == '\n') ? 'N' : bchar(current_buf->contents, current_buf->point),
			   screen_line_length(current_buf->contents, current_buf->point),
			   current_buf->y, current_buf->x);

	}

}
Beispiel #4
0
int screen_move_left(struct te_buffer *buf)
{
	if (buf == NULL)
		return ERR;

	if(move_left(buf) == ERR)
		return ERR;
	
	if (curr_char(buf) == '\n') {
			screen_prev_line(buf);
			buf->x = screen_line_length(buf->contents, buf->point);
	} else { 
		if (buf->x > 0)
			if (curr_char(buf) == '\t') {
				buf->x -= TAB_LEN;
			} else {
					buf->x--;
			}
	}

	move(buf->y, buf->x);
	return OK;
}