vip

VI Plus
git clone https://codeberg.org/night0721/vip
Log | Files | Refs | README | LICENSE

commit e603eaa74cdd6e95fd5f6fa07ecc0d484fa6fdf0
parent 2e662a95c15eef0409dc2aa427609be37412c039
Author: night0721 <[email protected]>
Date:   Mon,  1 Jul 2024 20:40:07 +0100

handle more keys

Diffstat:
Ainclude/editor.h | 6++++++
Minclude/vip.h | 3+++
Asrc/editor.c | 12++++++++++++
Msrc/vip.c | 22++++++++++++++++++++++
4 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/include/editor.h b/include/editor.h @@ -0,0 +1,6 @@ +#ifndef EDITOR_H_ +#define EDITOR_H_ + +void insert_char(int c); + +#endif diff --git a/include/vip.h b/include/vip.h @@ -39,6 +39,9 @@ struct abuf { void abAppend(struct abuf *ab, const char *s, int len); +void append_row(char *s, size_t len); +void row_insert_char(row *row, int at, int c); + extern editor vip; #endif diff --git a/src/editor.c b/src/editor.c @@ -0,0 +1,12 @@ +#include "vip.h" + +extern editor vip; + +void insert_char(int c) +{ + if (vip.cy == vip.rows) { + append_row("", 0); + } + row_insert_char(&vip.row[vip.cy], vip.cx, c); + vip.cx++; +} diff --git a/src/vip.c b/src/vip.c @@ -11,10 +11,12 @@ #include "vip.h" #include "term.h" #include "bar.h" +#include "editor.h" #define CTRL_KEY(k) ((k) & 0x1f) enum editorKey { + BACKSPACE = 127, ARROW_LEFT = 1000, ARROW_RIGHT, ARROW_UP, @@ -300,6 +302,10 @@ void process_key() { int c = read_key(); switch (c) { + case '\r': + /* TBC */ + break; + case CTRL_KEY('q'): write(STDOUT_FILENO, "\x1b[2J", 4); write(STDOUT_FILENO, "\x1b[H", 3); @@ -309,11 +315,19 @@ void process_key() case HOME_KEY: vip.cx = 0; break; + case END_KEY: if (vip.cy < vip.rows) { vip.cx = vip.row[vip.cy].size; } break; + + case BACKSPACE: + case CTRL_KEY('h'): + case DEL_KEY: + /* TBC */ + break; + case PAGE_UP: case PAGE_DOWN: { @@ -335,6 +349,14 @@ void process_key() case ARROW_RIGHT: move_cursor(c); break; + + case CTRL_KEY('l'): + case '\x1b': + break; + + default: + insert_char(c); + break; } }