NSLog with UTF-8, better color handling

This commit is contained in:
Edward Li 2022-07-22 07:26:20 +08:00 committed by flyinghead
parent 76bf574668
commit 9b751fced8
2 changed files with 11 additions and 3 deletions

View File

@ -14,7 +14,7 @@
ConsoleListener::ConsoleListener()
{
#ifdef LOG_TO_PTY
#if defined(LOG_TO_PTY) || defined(__APPLE__)
m_use_color = 1;
#elif defined(__SWITCH__)
m_use_color = 0;

View File

@ -30,8 +30,16 @@ int darw_printf(const char* text, ...)
va_start(args, text);
vsnprintf(temp, sizeof(temp), text, args);
va_end(args);
NSLog(@"%s", temp);
NSString* log = [NSString stringWithCString:temp encoding: NSUTF8StringEncoding];
if (getenv("TERM") == NULL) //Xcode console does not support colors
{
log = [log stringByReplacingOccurrencesOfString:@"\x1b[0m" withString:@""];
log = [log stringByReplacingOccurrencesOfString:@"\x1b[92m" withString:@" "];
log = [log stringByReplacingOccurrencesOfString:@"\x1b[91m" withString:@"⚠️ "];
log = [log stringByReplacingOccurrencesOfString:@"\x1b[93m" withString:@"🛑 "];
}
NSLog(@"%@", log);
return 0;
}