|
|
@ -49,16 +49,27 @@ void buffer_insert(char ch, Buffer* buffer) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void buffer_delete(Buffer* buffer) {
|
|
|
|
|
|
|
|
if (buffer->start != buffer->text) {
|
|
|
|
|
|
|
|
buffer->start--;
|
|
|
|
|
|
|
|
buffer->gap_size++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void buffer_right(Buffer* buffer) {
|
|
|
|
void buffer_right(Buffer* buffer) {
|
|
|
|
buffer->start++;
|
|
|
|
if (buffer->end != buffer->text + buffer->size) {
|
|
|
|
buffer->end--;
|
|
|
|
buffer->start++;
|
|
|
|
|
|
|
|
buffer->end++;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void buffer_left(Buffer* buffer) {
|
|
|
|
void buffer_left(Buffer* buffer) {
|
|
|
|
buffer->start--;
|
|
|
|
if (buffer->start != buffer->text) {
|
|
|
|
buffer->end--;
|
|
|
|
char c = *(buffer->start - 1);
|
|
|
|
|
|
|
|
buffer->start--;
|
|
|
|
|
|
|
|
buffer->end--;
|
|
|
|
|
|
|
|
*(buffer->end) = c;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void init_curses() {
|
|
|
|
void init_curses() {
|
|
|
@ -79,6 +90,8 @@ int main() {
|
|
|
|
Buffer* buffer = new_buffer(10);
|
|
|
|
Buffer* buffer = new_buffer(10);
|
|
|
|
init_curses();
|
|
|
|
init_curses();
|
|
|
|
int ch;
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int y, x;
|
|
|
|
while (true) {
|
|
|
|
while (true) {
|
|
|
|
clear();
|
|
|
|
clear();
|
|
|
|
|
|
|
|
|
|
|
@ -91,23 +104,35 @@ int main() {
|
|
|
|
i++;
|
|
|
|
i++;
|
|
|
|
if ((buffer->start - buffer->text) == i) { /* If we have encountered
|
|
|
|
if ((buffer->start - buffer->text) == i) { /* If we have encountered
|
|
|
|
the start of the gap */
|
|
|
|
the start of the gap */
|
|
|
|
|
|
|
|
getyx(stdscr,y,x);
|
|
|
|
i += buffer->gap_size;
|
|
|
|
i += buffer->gap_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
move(y,x);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ch = getch();
|
|
|
|
ch = getch();
|
|
|
|
|
|
|
|
|
|
|
|
switch(ch) {
|
|
|
|
switch(ch) {
|
|
|
|
case KEY_BACKSPACE:
|
|
|
|
case KEY_BACKSPACE:
|
|
|
|
if (buffer->start != buffer->text) {
|
|
|
|
buffer_delete(buffer);
|
|
|
|
buffer->start--;
|
|
|
|
break;
|
|
|
|
buffer->gap_size++;
|
|
|
|
|
|
|
|
}
|
|
|
|
case KEY_LEFT:
|
|
|
|
goto continue_while_loop;
|
|
|
|
buffer_left(buffer);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case KEY_RIGHT:
|
|
|
|
|
|
|
|
buffer_right(buffer);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
|
|
|
|
buffer_insert(ch,buffer);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buffer_insert(ch,buffer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
continue_while_loop:
|
|
|
|
continue_while_loop:
|
|
|
|
|
|
|
|
|
|
|
|