2021-08-21 01:55:48 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include "options.h"
|
|
|
|
#include "text.h"
|
|
|
|
#include "util.h"
|
2021-08-21 09:12:04 +03:00
|
|
|
#include "kbd.h"
|
2021-08-21 01:55:48 +03:00
|
|
|
|
2021-08-21 09:12:04 +03:00
|
|
|
int boot_edit = 0;
|
2021-08-21 01:55:48 +03:00
|
|
|
|
2021-08-21 09:12:04 +03:00
|
|
|
int boot_editor(void) {
|
2021-08-21 01:55:48 +03:00
|
|
|
int len = strlen(cmdline);
|
|
|
|
int cursor = len;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
move_cursor(0,0);
|
|
|
|
for (int i = 0; i <= len; ++i) {
|
|
|
|
set_attr(i == cursor ? 0x70 : 0x07);
|
|
|
|
print_((char[]){cmdline[i],'\0'});
|
|
|
|
}
|
|
|
|
print_(" ");
|
|
|
|
set_attr(0x07);
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
print_(" ");
|
|
|
|
} while (x);
|
|
|
|
} while (y);
|
|
|
|
|
|
|
|
char data = 0;
|
|
|
|
int status = read_key(&data);
|
|
|
|
|
|
|
|
if (status == 0) {
|
|
|
|
/* Handle a few special characters */
|
|
|
|
if (data == '\n') {
|
2021-08-21 09:12:04 +03:00
|
|
|
return 1;
|
|
|
|
} else if (data == 27) {
|
|
|
|
return 0;
|
2021-08-21 01:55:48 +03:00
|
|
|
} else if (data == '\b') {
|
|
|
|
if (!cursor) continue;
|
|
|
|
if (cursor == len) {
|
|
|
|
cmdline[len-1] = '\0';
|
|
|
|
cursor--;
|
|
|
|
len--;
|
|
|
|
} else {
|
|
|
|
cmdline[cursor-1] = '\0';
|
|
|
|
strcat(cmdline,&cmdline[cursor]);
|
|
|
|
cursor--;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (len > 1022) continue;
|
|
|
|
/* Move everything from the cursor onward forward */
|
|
|
|
if (cursor < len) {
|
|
|
|
int x = len + 1;
|
|
|
|
while (x > cursor) {
|
|
|
|
cmdline[x] = cmdline[x-1];
|
|
|
|
x--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cmdline[cursor] = data;
|
|
|
|
len++;
|
|
|
|
cursor++;
|
|
|
|
}
|
|
|
|
} else if (status == 2) {
|
|
|
|
/* Left */
|
|
|
|
if (cursor) cursor--;
|
|
|
|
} else if (status == 3) {
|
2021-08-21 09:12:04 +03:00
|
|
|
/* Right */
|
2021-08-21 01:55:48 +03:00
|
|
|
if (cursor < len) cursor++;
|
2021-08-21 09:12:04 +03:00
|
|
|
} else if (status == 4) {
|
|
|
|
/* Shift-left: Word left */
|
|
|
|
while (cursor && cmdline[cursor] == ' ') cursor--;
|
|
|
|
while (cursor && cmdline[cursor] != ' ') cursor--;
|
|
|
|
} else if (status == 5) {
|
|
|
|
/* Shift-right: Word right */
|
|
|
|
while (cursor < len && cmdline[cursor] == ' ') cursor++;
|
|
|
|
while (cursor < len && cmdline[cursor] != ' ') cursor++;
|
2021-08-21 01:55:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|