-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Implement new Erlang shell #6144
Conversation
CT Test Results 8 files 325 suites 3h 44m 24s ⏱️ For more details on these failures, see this check. Results for commit cf981d3. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
@garazdawi is there a way to detect if we are running with ANSI support or not? We need to detect this from Elixir in order to know if we should emit ANSI escape sequences or not. I assume On Unix, we use https://github.com/elixir-lang/elixir/blob/main/bin/elixir.bat#L170 However, I am assuming that with this patch we will have ANSI enabled on Windows regardless of the registry key? Thank you! ❤️ |
Out of curiosity which systems don't in ? Wondering if it's even necessary to worry about this. |
So to answer your question: No there is no way to check if we are running with ANSI support or not. There is however a way to check if standard output is a terminal, which I think is what you were really asking for. 1> io:getopts(user).
[{expand_fun,#Fun<group.0.63993037>},
{echo,false},
{binary,false},
{encoding,unicode},
{tty,true}] %% This is set to true when stdout is a isatty
Windows Terminal Sequences will be enabled when you start an interactive session. At the moment it will not enabled if you do " |
Embedded devices that care a lot about the size of the disk of their system. |
Perfect, thank you!
I would say that we also want to enable ANSI for Windows on those cases. For example, Elixir test runner does use ANSI escapes while running tests or other installation scripts, which often run with Ideally, in terms of ANSI support, everything is the same regardless if the Erlang shell is available. For example,
I also assume the -oldshell/fd is used when redirecting stdout to a file. |
I'm just wondering if there are any cases when you would not want ANSI enabled on windows. We can always add some extra functionality for Windows later if it is a problem.
No, it is not. The new nifs are used there so that the work can be properly done on dirty I/O schedulers. The only cases when the fd driver is used is if "-oldshell" is passed, or libtinfo is unavailable and you attempt to start a shell. |
Do you mean technical cases? Or cases based on the use case? For the latter, we always handle it at the application level. For example, some recommend disabling ANSI when NO_COLOR is set, so I am hoping we can change Elixir to do something like this to detect if we should emit ANSI or not:
Perfect, thanks! |
55d4fc1
to
080996d
Compare
I've pushed updates that:
|
Fantastic!!!!!!!! @garazdawi I have one additional question based on another recurring issue on Windows: what about UTF-8 support? Can we now force the terminal to be in UTF-8? We often have to ask users to set Sorry for the questions. I got a new computer and I am struggling to setup a Windows VM (due to the Apple chip). :( |
Yes it is fixed. We call SetConsoleOutputCP to set the correct output codepage. |
f77079c
to
4757d56
Compare
One other feature me (and @josevalim I think as well) is really interested about is some way to extend pretty printing in the shell. There is some very basic mechanism for format records (after loading with |
@max-au I replied in Erlang Forums about something similar. We can discuss it more there if you would like. Let's keep this PR about the contents of this PR. |
0678580
to
b8e51f6
Compare
530f845
to
784e780
Compare
This commit re-implements the entire tty driver for both Unix and Windows to use a common nif instead of two seperate drivers. The Unix implementation works pretty much as it did before only that a lot more of the terminal logic has been moved from Erlang to C. The windows implementation now uses Windows Terminal Sequences, i.e. the same sequences as most Unixes to control the terminal. This means that werl.exe is no longer needed and erl.exe will have the "newshell" with all the features normally only found on Unix. The new implementation also uses dirty I/O threads for all I/O which means that it can leave the FDs in blocking mode. This fixes problems when the Erlang tty is interacting with other systems such as bash. Closes erlang#3150 Closes erlang#3390 Closes erlang#4343
We want as much of the I/O work as possible to go through the user_drv as it will use dirty I/O schedulers to schedule the work. Also this makes the unicode detection work even for -noshell/-noinput type systems. This commit also adds user_drv:start_shell/0 to allow the user to start the shell after the fact. For instance when rebar3 starts as en escript it may want to start a shell depending on what arguments are given to it.
This is useful to have when checking if the target of output is a terminal.
If the cleanup code in sys_tty_reset is never run it can leave the terminal in a broken state. The cleanup code is not executed if erts receives a SIGKILL or if Ctrl-C is pressed when +B is started. Closes erlang#3150
784e780
to
919561f
Compare
eb0165e
to
cf981d3
Compare
Not clearing it triggered the assert below when stdin was deselected.
Argument parsing by init is a bit naive. In the escript testcase "-noshell xxxx...." was interpreted as the "-noshell" flag being given the value "xxxx....". So to fix this, we push the "-boot file" argument last and thus "xxxxx" will be seen as a separate argument as it should.
This is needed for when prim_tty is cover compiled.
When running in embedded mode the on_load function is called by the init process after the user processes are started. So we add a way for user to call the on_load function earlier in the boot sequence so that the shell can be started when it should. We cannot move the on_load calls for all modules to an earlier place in the kernel boot sequence as the code in on_load may depend on kernel services being started.
cf981d3
to
945b37f
Compare
This PR re-implements the entire tty driver for both Unix
and Windows to use a common nif instead of two seperate drivers.
The Unix implementation works pretty much as it did before only that
a lot more of the terminal logic has been moved from Erlang to C.
The windows implementation now uses Windows Terminal Sequences, i.e.
the same sequences as most Unixes to control the terminal. This means
that werl.exe is no longer needed and erl.exe will have the "newshell"
with all the features normally only found on Unix.
The new implementation also uses dirty I/O threads for all I/O which
means that it can leave the FDs in blocking mode. This fixes problems
when the Erlang tty is interacting with other systems such as bash.
The PR also moves all non-shell I/O to use the new nifs instead of using
the "fd driver" so that the I/O for escripts use dirty IO threads. The only time
when the "fd driver" is used is when "-oldshell" is explicitly given or a shell
is requested in a system that does not support termcap.
This PR is not ready to merge yet, I'm opening it up for people to try it out and
give feedback.