CE Improve line editing logic, add KB_DELETE
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m18s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m18s
This commit is contained in:
44
ce/ce.c
44
ce/ce.c
@@ -17,8 +17,9 @@
|
||||
#include <tcursor.h>
|
||||
#include <tscreen.h>
|
||||
|
||||
#define LINE_INIT_MAX 40
|
||||
#define PROMPT "$ "
|
||||
#define LINE_INIT_MAX 40
|
||||
#define LINE_TAIL_BATCH_MAX 1024
|
||||
#define PROMPT "$ "
|
||||
|
||||
struct edit_line {
|
||||
struct gapbuffer gb;
|
||||
@@ -55,18 +56,32 @@ void app_main (void) {
|
||||
if (ch == '\n')
|
||||
break;
|
||||
|
||||
gapbuffer_move (&edit_line.gb, edit_line.cursor);
|
||||
|
||||
switch (ch) {
|
||||
case '\b':
|
||||
if (edit_line.cursor > 0) {
|
||||
gapbuffer_backspace (&edit_line.gb);
|
||||
edit_line.cursor--;
|
||||
gapbuffer_backspace (&edit_line.gb);
|
||||
|
||||
mprintf ("\b");
|
||||
mprintf (ANSIQ_CUR_LEFT (1));
|
||||
|
||||
char* tail = gapbuffer_string_at (&edit_line.gb, edit_line.cursor);
|
||||
mprintf ("%s" ANSIQ_SCR_CLR2END, tail);
|
||||
mprintf ("%s" ANSIQ_SCR_CLR2LEND, tail);
|
||||
|
||||
int move_back = (int)strlen (tail);
|
||||
int move_back = strlen (tail);
|
||||
if (move_back > 0)
|
||||
mprintf (ANSIQ_DYN_CUR_LEFT, move_back);
|
||||
}
|
||||
break;
|
||||
case KB_DELETE:
|
||||
if (edit_line.cursor < gapbuffer_length (&edit_line.gb)) {
|
||||
edit_line.gb.gap_end++;
|
||||
|
||||
char* tail = gapbuffer_string_at (&edit_line.gb, edit_line.cursor);
|
||||
mprintf ("%s" ANSIQ_SCR_CLR2LEND, tail);
|
||||
|
||||
int move_back = strlen (tail);
|
||||
if (move_back > 0)
|
||||
mprintf (ANSIQ_DYN_CUR_LEFT, move_back);
|
||||
}
|
||||
@@ -84,21 +99,20 @@ void app_main (void) {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (isascii (ch)) {
|
||||
if (isprint (ch)) {
|
||||
gapbuffer_insert (&edit_line.gb, ch);
|
||||
edit_line.cursor++;
|
||||
|
||||
char* tail = gapbuffer_string_at (&edit_line.gb, edit_line.cursor - 1);
|
||||
mprintf ("%s" ANSIQ_SCR_CLR2LEND, tail);
|
||||
|
||||
int move_back = (int)strlen (tail) - 1;
|
||||
if (move_back > 0)
|
||||
mprintf (ANSIQ_DYN_CUR_LEFT, move_back);
|
||||
if (edit_line.cursor == gapbuffer_length (&edit_line.gb)) {
|
||||
mprintf ("%c", ch);
|
||||
} else {
|
||||
char* tail = gapbuffer_string_at (&edit_line.gb, edit_line.cursor - 1);
|
||||
size_t move_back = strlen (tail) - 1;
|
||||
mprintf ("%s" ANSIQ_DYN_CUR_LEFT, tail, move_back);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
gapbuffer_move (&edit_line.gb, edit_line.cursor);
|
||||
}
|
||||
|
||||
mprintf ("\n");
|
||||
|
||||
Reference in New Issue
Block a user