Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/support/libsupportinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ static int isInitialized = 0;
void libsupport_init(void)
{
if (!isInitialized) {
#ifdef _OS_WINDOWS_
SetConsoleCP(1252); // ANSI Latin1; Western European (Windows)
#endif

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels slightly risky and unrelated? (reverts eac525c, but libuv is now unicode-aware, so perhaps that's not as bad now)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to remove this or set the console to SetConsoleCP(CP_UTF8) or else the sequences don't get interpreted correctly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CP_UTF8 (65001) is not well supported. That's why we set it to 1252 (It even can break dir: nodejs/node-v0.x-archive#4246 (comment))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that comment relevant? It looks like part of the issue was with using a raster front

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at #6795

print("测试")
测试

julia> print("\346\265\213\350\257\225")
测试

With this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like things probably got fixed internally in libuv?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, libuv Is fixed now to bypass this. The issue would be with other shared libraries that assume an ascii-compatible stream.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to hear. Is that issue more theoretical than practically relevant (?), I don't know what we could do about this pathological case without regressing the whole system to be dumber because of some library is forcing ascii.

setlocale(LC_ALL, ""); // set to user locale
setlocale(LC_NUMERIC, "C"); // use locale-independent numeric formats

Expand Down
31 changes: 31 additions & 0 deletions stdlib/REPL/src/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1272,8 +1272,39 @@ function write_prompt(terminal, p::Prompt)
return width
end

# On Windows, when launching external processes, we cannot control what assumption they make on the
# console mode. We thus forcibly reset the console mode at the start of the prompt to ensure they do
# not leave the console mode in a corrupt state.
# FIXME: remove when pseudo-tty are implemented for child processes
if Sys.iswindows()
function _console_mode()
hOutput = ccall(:GetStdHandle, stdcall, Ptr{Cvoid}, (UInt32,), -11 % UInt32) # STD_OUTPUT_HANDLE
dwMode = Ref{UInt32}()
ccall(:GetConsoleMode, stdcall, Int32, (Ref{Cvoid}, Ref{UInt32}), hOutput, dwMode)
return dwMode[]
end
const default_console_mode_ref = Ref{UInt32}()
const default_console_mode_assigned = Ref(false)
function get_default_console_mode()
if default_console_mode_assigned[] == false
default_console_mode_assigned[] = true
default_console_mode_ref[] = _console_mode()
end
return default_console_mode_ref[]
end
function _reset_console_mode()
mode = _console_mode()
if mode !== get_default_console_mode()
hOutput = ccall(:GetStdHandle, stdcall, Ptr{Cvoid}, (UInt32,), -11 % UInt32) # STD_OUTPUT_HANDLE
ccall(:SetConsoleMode, stdcall, Int32, (Ptr{Cvoid}, UInt32), hOutput, default_console_mode_ref[])
end
nothing
end
end

# returns the width of the written prompt
function write_prompt(terminal, s::Union{AbstractString,Function})
@static Sys.iswindows() && _reset_console_mode()
promptstr = prompt_string(s)
write(terminal, promptstr)
return textwidth(promptstr)
Expand Down