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); }
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; } }
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; } }