mirror of
https://github.com/DoneJS-Runtime/quickjs-done-nextgen.git
synced 2025-01-09 17:43:15 +00:00
Support printing unicode characters on Windows
This commit is contained in:
parent
0bf36b98b9
commit
72d4587163
1 changed files with 29 additions and 1 deletions
|
@ -3875,13 +3875,40 @@ JSModuleDef *js_init_module_os(JSContext *ctx, const char *module_name)
|
||||||
|
|
||||||
/**********************************************************/
|
/**********************************************************/
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
static JSValue js_print(JSContext *ctx, JSValue this_val,
|
||||||
|
int argc, JSValue *argv)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
const char *str;
|
||||||
|
size_t len;
|
||||||
|
DWORD written;
|
||||||
|
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
if (hConsole == INVALID_HANDLE_VALUE)
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
for(i = 0; i < argc; i++) {
|
||||||
|
if (i != 0)
|
||||||
|
WriteConsoleW(hConsole, L" ", 1, &written, NULL);
|
||||||
|
str = JS_ToCStringLen(ctx, &len, argv[i]);
|
||||||
|
if (!str)
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
DWORD prev = GetConsoleOutputCP();
|
||||||
|
SetConsoleOutputCP(CP_UTF8);
|
||||||
|
WriteConsoleA(hConsole, str, len, &written, NULL);
|
||||||
|
SetConsoleOutputCP(prev);
|
||||||
|
JS_FreeCString(ctx, str);
|
||||||
|
}
|
||||||
|
WriteConsoleW(hConsole, L"\n", 1, &written, NULL);
|
||||||
|
FlushFileBuffers(hConsole);
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
#else
|
||||||
static JSValue js_print(JSContext *ctx, JSValue this_val,
|
static JSValue js_print(JSContext *ctx, JSValue this_val,
|
||||||
int argc, JSValue *argv)
|
int argc, JSValue *argv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
const char *str;
|
const char *str;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
for(i = 0; i < argc; i++) {
|
for(i = 0; i < argc; i++) {
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
|
@ -3895,6 +3922,7 @@ static JSValue js_print(JSContext *ctx, JSValue this_val,
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void js_std_add_helpers(JSContext *ctx, int argc, char **argv)
|
void js_std_add_helpers(JSContext *ctx, int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue