[FEAT] New terminal console system
This commit is contained in:
48
ascii.cpp
48
ascii.cpp
@@ -224,6 +224,7 @@ int main(int argc,char*argv[]) {
|
||||
|
||||
if (lua_is_playing()) {
|
||||
lua_call_update();
|
||||
if (!lua_is_playing()) debug_set_prompt();
|
||||
} else {
|
||||
debug_cursor_blink--;
|
||||
if (debug_cursor_blink == 0) {
|
||||
@@ -299,10 +300,9 @@ void cls(uint8_t value) {
|
||||
SDL_memset(char_screen, value, screen_width*screen_height);
|
||||
if (current_mode != 0) SDL_memset(color_screen, current_color, screen_width*screen_height);
|
||||
cursor_x = cursor_y = 0;
|
||||
if (!lua_is_playing()) {
|
||||
char_screen[0] = '>';
|
||||
cursor_x=1;
|
||||
}
|
||||
//if (!lua_is_playing()) {
|
||||
// debug_set_prompt()
|
||||
//}
|
||||
}
|
||||
|
||||
void ink(uint8_t value) {
|
||||
@@ -478,16 +478,21 @@ void debugchr(const uint8_t chr) {
|
||||
}
|
||||
}
|
||||
|
||||
void debug(const char *str) {
|
||||
void debug(const char *str, const bool newline) {
|
||||
const int len = SDL_strlen(str);
|
||||
int cursor = cursor_x+cursor_y*screen_width;
|
||||
for (int i=0; i<len;++i) {
|
||||
char_screen[cursor++] = str[i];
|
||||
if (cursor >= screen_width*screen_height) debug_one_line_up();
|
||||
}
|
||||
cursor_x = 0;
|
||||
cursor_y = (cursor/screen_width)+1;
|
||||
if (cursor_y >= screen_height) debug_one_line_up();
|
||||
if (newline) {
|
||||
cursor_x = 0;
|
||||
cursor_y = (cursor/screen_width)+1;
|
||||
if (cursor_y >= screen_height) debug_one_line_up();
|
||||
} else {
|
||||
cursor_x = cursor%screen_width;
|
||||
cursor_y = cursor/screen_width;
|
||||
}
|
||||
//debug_set_prompt();
|
||||
}
|
||||
|
||||
@@ -511,24 +516,36 @@ void debug_get_cmd() {
|
||||
char_screen[cursor_x+cursor_y*screen_width] = 32;
|
||||
cursor_x=0;cursor_y++;if(cursor_y>=screen_height)debug_one_line_up();
|
||||
cmd_index=0;
|
||||
lua_call_cmd(cmd_list[cmd_list.size()-1].c_str());
|
||||
//if ((cursor_y>0) || (cursor_x>0)) { cursor_x=0;cursor_y++;if(cursor_y>=screen_height)debug_one_line_up(); }
|
||||
debug_set_prompt();
|
||||
const char* cmd = cmd_list[cmd_list.size()-1].c_str();
|
||||
|
||||
if (cmd[0]=='r' && cmd[1]=='u' && cmd[2]=='n' && cmd[3]=='\0') {
|
||||
lua_quit();
|
||||
reinit();
|
||||
lua_init(lua_filename);
|
||||
lua_call_init();
|
||||
} else {
|
||||
lua_call_cmd(cmd);
|
||||
debug_set_prompt();
|
||||
}
|
||||
}
|
||||
|
||||
void next_cmd() {
|
||||
if (cmd_index < cmd_list.size()) cmd_index++;
|
||||
void get_cmd_by_index() {
|
||||
const char* cmd = cmd_list[cmd_list.size()-cmd_index].c_str();
|
||||
int pos = cursor_x+cursor_y*screen_width;
|
||||
for (int i=debug_prompt;i<=pos;++i) char_screen[i] = 32;
|
||||
SDL_memcpy(&char_screen[debug_prompt], cmd, strlen(cmd));
|
||||
pos += debug_prompt;
|
||||
pos = debug_prompt+strlen(cmd);
|
||||
cursor_x = pos%screen_width;
|
||||
cursor_y = pos/screen_width;
|
||||
}
|
||||
void next_cmd() {
|
||||
if (cmd_index < cmd_list.size()) cmd_index++;
|
||||
get_cmd_by_index();
|
||||
}
|
||||
|
||||
void prev_cmd() {
|
||||
|
||||
if (cmd_index > 0) cmd_index--;
|
||||
get_cmd_by_index();
|
||||
}
|
||||
|
||||
uint8_t ascii(const char *str, uint8_t index) {
|
||||
@@ -598,6 +615,7 @@ void play(const char* str) {
|
||||
void setmode(const uint8_t mode) {
|
||||
current_mode = mode;
|
||||
reinit();
|
||||
cls();
|
||||
}
|
||||
|
||||
void load(const char* str) {
|
||||
|
||||
Reference in New Issue
Block a user