Fix path backslashes with DJUI console

This commit is contained in:
Agent X 2023-11-23 12:21:01 -05:00
parent 0a39303a5a
commit f8e0bfc2e4
5 changed files with 14 additions and 8 deletions

View File

@ -736,6 +736,7 @@ void Print(const char *aFmt, Args... aArgs) {
template <typename... Args>
void PrintConsole(const char *aFmt, Args... aArgs) {
snprintf(gDjuiConsoleTmpBuffer, CONSOLE_MAX_TMP_BUFFER, aFmt, aArgs...);
sys_swap_backslashes(gDjuiConsoleTmpBuffer);
djui_console_message_create(gDjuiConsoleTmpBuffer);
}

View File

@ -7,7 +7,7 @@ struct DjuiConsole {
bool scrolling;
};
#define CONSOLE_MAX_TMP_BUFFER 256
#define CONSOLE_MAX_TMP_BUFFER 512
extern struct DjuiConsole* gDjuiConsole;
extern bool gDjuiConsoleFocus;
extern char gDjuiConsoleTmpBuffer[];

View File

@ -81,13 +81,7 @@ static bool loading_screen_on_render(struct DjuiBase* base) {
snprintf(buffer, 256, "%s...", gCurrLoadingSegment.str);
}
// swap around the backslashes
bool inColor = false;
for (u32 i = 0; i < length; i++) {
if (buffer[i] == '\\' && buffer[MIN(i+1,length)] == '#') { inColor = true; }
if (buffer[i] == '\\' && !inColor) { buffer[i] = '/'; }
if (buffer[i] == '\\' && inColor && buffer[MIN(i+1,length)] != '#') { inColor = false; }
}
sys_swap_backslashes(buffer);
}
djui_text_set_text(sLoading->loadingDesc, buffer);
djui_base_set_location(&sLoading->loadingDesc->base, 0, windowHeight - 250);

View File

@ -66,6 +66,16 @@ const char *sys_file_name(const char *fpath) {
return sep + 1;
}
void sys_swap_backslashes(char* buffer) {
size_t length = strlen(buffer);
bool inColor = false;
for (u32 i = 0; i < length; i++) {
if (buffer[i] == '\\' && buffer[MIN(i + 1, length)] == '#') { inColor = true; }
if (buffer[i] == '\\' && !inColor) { buffer[i] = '/'; }
if (buffer[i] == '\\' && inColor && buffer[MIN( i + 1, length)] != '#') { inColor = false; }
}
}
/* this calls a platform-specific impl function after forming the error message */
static void sys_fatal_impl(const char *msg) __attribute__ ((noreturn));

View File

@ -22,6 +22,7 @@ const char *sys_user_path(void);
const char *sys_exe_path(void);
const char *sys_file_extension(const char *fpath);
const char *sys_file_name(const char *fpath);
void sys_swap_backslashes(char* buffer);
// shows an error message in some way and terminates the game
void sys_fatal(const char *fmt, ...) __attribute__ ((noreturn));