Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL: Query libuv for virtual terminal support #57132

Merged
merged 1 commit into from
Feb 3, 2025

Conversation

topolarity
Copy link
Member

@topolarity topolarity commented Jan 22, 2025

The query-and-restore logic here was pretty flawed:

  • it had no way to guarantee when the "default" mode is available to query, so it could easily save a "bad" mode
  • it did not ensure / check whether the "default" mode is compatible with the output generated by REPL (esp. ASCII escape codes / color)
  • it persisted the "default" mode from pre-compilation to runtime, causing Julia nightly has ASCII salad for prompt in Windows CMD #56073

With this PR, ENABLE_VIRTUAL_TERMINAL_PROCESSING is the only flag that we're agnostic about. It was added relatively recently (Windows 10 version 1511), and libuv has support to emulate its behavior when it's not available natively. We query libuv directly to ask whether it is expecting to emulate, rather than measuring the console mode at some random point in time.

Otherwise this PR resets ENABLE_PROCESSED_OUTPUT and ENABLE_WRAP_AT_EOL_OUTPUT always, since we output ASCII control sequences unconditionally.

Resolves #56073.

@topolarity topolarity marked this pull request as draft January 22, 2025 18:26
@topolarity topolarity changed the title REPL: Hard-code ConsoleMode flags on Windows REPL: Query libuv for virtual terminal support Jan 23, 2025
@topolarity topolarity changed the title REPL: Query libuv for virtual terminal support REPL: Query libuv for virtual terminal support Jan 23, 2025
@topolarity topolarity force-pushed the ct/REPL-ConsoleMode branch 2 times, most recently from 5ef9f00 to 37e0f88 Compare January 23, 2025 20:27
@topolarity topolarity marked this pull request as ready for review January 23, 2025 20:27
@topolarity topolarity requested a review from vtjnash January 23, 2025 20:27
@giordano giordano added system:windows Affects only Windows REPL Julia's REPL (Read Eval Print Loop) labels Jan 23, 2025
The query-and-restore logic here was pretty flawed:
  - it had no way to guarantee when the "default" mode is available to
    query, so it could easily save a "bad" mode
  - it did not ensure / check whether the "default" mode is compatible
    with the output generated by REPL (esp. ASCII escape codes / color)
  - it persisted the "default" mode from pre-compilation to runtime,
    causing JuliaLang#56073

`ENABLE_VIRTUAL_TERMINAL_PROCESSING` is the only flag that we're
agnostic about. It was added relatively recently (Windows 10 version
1511), and `libuv` has support to emulate its behavior when it's not
available natively.

Otherwise this PR resets ENABLE_PROCESSED_OUTPUT and
ENABLE_WRAP_AT_EOL_OUTPUT always, since we output ASCII control
sequences unconditionally.

Resolves JuliaLang#56073.
@topolarity
Copy link
Member Author

topolarity commented Jan 28, 2025

This might technically be a minor abuse of the libuv API, which was apparently intended for the opposite case, where the terminal does not appear to support ENABLE_VIRTUAL_TERMINAL_PROCESSING as a flag, but does support VT sequences anyway.

The alternative would be to do what libuv does and try to see if the feature flag "sticks" after a SetConsoleMode or just set the "compatible" flags first, followed by the "virtual terminal" flags which will presumably be ignored by any terminals that don't understand them.

@topolarity
Copy link
Member Author

@vtjnash any concerns here before I merge?

@vtjnash vtjnash merged commit e592169 into JuliaLang:master Feb 3, 2025
7 checks passed
@vtjnash vtjnash added the backport 1.12 Change should be backported to release-1.12 label Feb 3, 2025
@KristofferC
Copy link
Member

Removing label since this was merged before branching.

@KristofferC KristofferC removed the backport 1.12 Change should be backported to release-1.12 label Feb 4, 2025
@topolarity topolarity deleted the ct/REPL-ConsoleMode branch February 4, 2025 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
REPL Julia's REPL (Read Eval Print Loop) system:windows Affects only Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Julia nightly has ASCII salad for prompt in Windows CMD
4 participants