Code Editor WIP

This commit is contained in:
2021-12-15 12:16:36 +01:00
parent acfaf873ce
commit 11bb1b5283

View File

@@ -94,7 +94,8 @@ void do_terminal() {
}
void load_code() {
FILE *f = fopen(get_filename(), "rb");
const char* file = get_filename();
FILE *f = fopen(file, "rb");
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
fseek(f, 0, SEEK_SET); /* same as rewind(f); */
@@ -105,11 +106,17 @@ void load_code() {
int start = 0;
for (int pos=0;pos<fsize;++pos) {
if (buffer[pos] == '\r') {
if (buffer[pos] == '\n') {
buffer[pos]='\0';
code.push_back(&buffer[start]);
start=pos+2;
start=pos+1;
} else if (buffer[pos] == '\r') {
buffer[pos]='\0';
code.push_back(&buffer[start]);
start=pos+1;
if (buffer[start] == '\n') start++;
}
}
free(buffer);
}
@@ -237,6 +244,17 @@ void delete_char() {
}
}
void add_char(uint8_t chr) {
std::string str = get_current_line();
std::string a = str.substr(0,col);
std::string b = str.substr(col);
std::string c = " "; c[0] = chr;
*ls[line] = a+c+b;
col++;
blink_wait=1;
refresh_code_editor();
}
void do_code_editor() {
const uint8_t key = whichbtn();
if (key != KEY_UNKNOWN) {
@@ -250,7 +268,7 @@ void do_code_editor() {
else if (key == KEY_BACKSPACE) delete_char();
else {
uint8_t chr = get_char(key);
if (chr != 0) debugchr(chr);
if (chr != 0) add_char(chr);
}
}