1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-26 05:07:41 +00:00

Use memmove instead of copying.

Also some comment things, and re-add old code from linenoise.
It seems to have a purpose for some keyboard layouts, so I will leave
it.
This commit is contained in:
Calvin Rose
2020-01-21 23:11:00 -06:00
parent 688e18a891
commit 2f9ed8a572

View File

@@ -642,12 +642,9 @@ static int line() {
historymove(1); historymove(1);
break; break;
case 21: { /* ctrl-u */ case 21: { /* ctrl-u */
char *temp = sdup(&gbl_buf[gbl_pos]); memmove(gbl_buf, gbl_buf + gbl_pos, gbl_len - gbl_pos);
memcpy(temp, &gbl_buf[gbl_pos], sizeof(char) * (gbl_len - gbl_pos)); gbl_len -= gbl_pos;
memcpy(gbl_buf, temp, sizeof(char) * (gbl_len - gbl_pos)); gbl_buf[gbl_len] = '\0';
free(temp);
gbl_buf[gbl_len - gbl_pos] = '\0';
gbl_len = gbl_len - gbl_pos;
gbl_pos = 0; gbl_pos = 0;
refresh(); refresh();
break; break;
@@ -666,7 +663,7 @@ static int line() {
* Use two calls to handle slow terminals returning the two * Use two calls to handle slow terminals returning the two
* chars at different times. */ * chars at different times. */
if (read(STDIN_FILENO, seq, 1) == -1) break; if (read(STDIN_FILENO, seq, 1) == -1) break;
// Esc[ = Control Sequence Introducer (CSI) /* Esc[ = Control Sequence Introducer (CSI) */
if (seq[0] == '[') { if (seq[0] == '[') {
if (read(STDIN_FILENO, seq + 1, 1) == -1) break; if (read(STDIN_FILENO, seq + 1, 1) == -1) break;
if (seq[1] >= '0' && seq[1] <= '9') { if (seq[1] >= '0' && seq[1] <= '9') {
@@ -689,6 +686,20 @@ static int line() {
break; break;
} }
} }
} else if (seq[0] == 'O') {
if (read(STDIN_FILENO, seq + 1, 1) == -1) break;
switch (seq[1]) {
default:
break;
case 'H': /* Home (some keyboards) */
gbl_pos = 0;
refresh();
break;
case 'F': /* End (some keyboards) */
gbl_pos = gbl_len;
refresh();
break;
}
} else { } else {
switch (seq[1]) { switch (seq[1]) {
/* Single escape sequences */ /* Single escape sequences */
@@ -721,19 +732,19 @@ static int line() {
switch (seq[0]) { switch (seq[0]) {
default: default:
break; break;
case 'd': // Alt-d case 'd': /* Alt-d */
kdeletew(); kdeletew();
break; break;
case 'b': // Alt-b case 'b': /* Alt-b */
kleftw(); kleftw();
break; break;
case 'f': // Alt-f case 'f': /* Alt-f */
krightw(); krightw();
break; break;
case ',': // Alt-, case ',': /* Alt-, */
historymove(JANET_HISTORY_MAX); historymove(JANET_HISTORY_MAX);
break; break;
case '.': // Alt-. case '.': /* Alt-. */
historymove(-JANET_HISTORY_MAX); historymove(-JANET_HISTORY_MAX);
break; break;
} }