Code Editor WIP
This commit is contained in:
26
main.cpp
26
main.cpp
@@ -94,7 +94,8 @@ void do_terminal() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void load_code() {
|
void load_code() {
|
||||||
FILE *f = fopen(get_filename(), "rb");
|
const char* file = get_filename();
|
||||||
|
FILE *f = fopen(file, "rb");
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
long fsize = ftell(f);
|
long fsize = ftell(f);
|
||||||
fseek(f, 0, SEEK_SET); /* same as rewind(f); */
|
fseek(f, 0, SEEK_SET); /* same as rewind(f); */
|
||||||
@@ -105,11 +106,17 @@ void load_code() {
|
|||||||
|
|
||||||
int start = 0;
|
int start = 0;
|
||||||
for (int pos=0;pos<fsize;++pos) {
|
for (int pos=0;pos<fsize;++pos) {
|
||||||
if (buffer[pos] == '\r') {
|
if (buffer[pos] == '\n') {
|
||||||
buffer[pos]='\0';
|
buffer[pos]='\0';
|
||||||
code.push_back(&buffer[start]);
|
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);
|
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() {
|
void do_code_editor() {
|
||||||
const uint8_t key = whichbtn();
|
const uint8_t key = whichbtn();
|
||||||
if (key != KEY_UNKNOWN) {
|
if (key != KEY_UNKNOWN) {
|
||||||
@@ -250,7 +268,7 @@ void do_code_editor() {
|
|||||||
else if (key == KEY_BACKSPACE) delete_char();
|
else if (key == KEY_BACKSPACE) delete_char();
|
||||||
else {
|
else {
|
||||||
uint8_t chr = get_char(key);
|
uint8_t chr = get_char(key);
|
||||||
if (chr != 0) debugchr(chr);
|
if (chr != 0) add_char(chr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user