Skip to content

Implement lazy-read and noshell raw mode - #8962

Merged
garazdawi merged 7 commits into
erlang:masterfrom
garazdawi:lukas/kernel/shell-improvements
Oct 30, 2024
Merged

garazdawi merged 7 commits into
erlang:masterfrom
garazdawi:lukas/kernel/shell-improvements

Conversation

@garazdawi

Copy link
Copy Markdown
Member

This PR implements a couple of new fetures to how stdin and stdout is handled by Erlang.

  • All reads from stdin are now done upon request, instead of greedingly reading all data. So it is only when an io:get_line/2 or equivilant is issued by the Erlang program that a read is done. This solves io:get_line/1 cannot read cyrillic input on Windows with -noshell #8113 and also the problem mentioned by Josè here. This change also basically makes the -noinput flag obsolete, as no data will be read from stdin without it being requested.

  • The noshell mode has been updated to have two "submodes" called raw or cooked, where cooked is the old default behaviour and raw can be used to bypass the line editing support of the native terminal. Using raw mode it is possible to read keystrokes as they happen without the user having to type Enter. The raw mode also does not echo the typed characters to stdout. An example of how to create a tic-tac-toe game using this mechanism is included in the documentation. This solves Getch for OTP26  #8037.

  • There is also a new guide added that shows how to create a custom shell with autocomplete using Erlang's builtin line editor (basically what Elixir, Luerl and other do).

@garazdawi garazdawi added team:VM Assigned to OTP team VM feature labels Oct 17, 2024
@garazdawi garazdawi added this to the OTP-28.0 milestone Oct 17, 2024
@garazdawi
garazdawi requested a review from frazze-jobb October 17, 2024 19:46
@garazdawi garazdawi self-assigned this Oct 17, 2024
@github-actions

github-actions Bot commented Oct 17, 2024 •

Copy link
Copy Markdown
Contributor

CT Test Results

    6 files    303 suites   3h 10m 25s ⏱️
5 401 tests 5 070 ✅ 330 💤 1 ❌
7 972 runs  7 544 ✅ 427 💤 1 ❌

For more details on these failures, see this check.

Results for commit 28953ce.

♻️ 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

garazdawi commented Oct 18, 2024 •

Copy link
Copy Markdown
Member Author

You can read the new guides here:
*Creating a custom shell

*Creating a terminal application

Comment thread lib/stdlib/doc/guides/custom_shell.md Resolved
@garazdawi
garazdawi force-pushed the lukas/kernel/shell-improvements branch from 8e32c5a to cd522a8 Compare October 22, 2024 19:25
@garazdawi garazdawi added testing currently being tested, tag is used by OTP internal CI and removed testing currently being tested, tag is used by OTP internal CI labels Oct 23, 2024
@garazdawi
garazdawi force-pushed the lukas/kernel/shell-improvements branch from 4f90535 to 085259c Compare October 23, 2024 13:43
@garazdawi garazdawi added the testing currently being tested, tag is used by OTP internal CI label Oct 23, 2024
@sverker sverker removed the testing currently being tested, tag is used by OTP internal CI label Oct 23, 2024
@garazdawi
garazdawi force-pushed the lukas/kernel/shell-improvements branch from c70d9fa to f321f21 Compare October 25, 2024 11:25
When running in `-noshell` mode, it is "normal" for programs
to not eagerly read from stdin. This commit changes so that
we only issue read requests to stdin when `user` has received
a read request from the application.

This change also makes it so that on Windows we don't have to
abort an ongoing read request, which means that we can use
ReadFile in non-overlapped mode and thus Unicode will work
when reading from stdin in noshell mode on windows.
When an Erlang shell gets EOF it should halt the node, however
very often stderr is also closed at the same time which caused
the error printing to crash preventing halt to be called.
@garazdawi
garazdawi force-pushed the lukas/kernel/shell-improvements branch from 28953ce to bd2ba03 Compare October 30, 2024 12:25
@garazdawi
garazdawi merged commit 14e885a into erlang:master Oct 30, 2024
@garazdawi
garazdawi deleted the lukas/kernel/shell-improvements branch November 5, 2024 12:16
@EliasDerHai

Copy link
Copy Markdown

You can read the new guides here:

* [Creating a custom shell](https://erlang.github.io/prs/8962/lib/stdlib-6.1.2/doc/html/custom_shell.html)

* [Creating a terminal application](https://erlang.github.io/prs/8962/lib/stdlib-6.1.2/doc/html/terminal_interface.html)

broken links

@frazze-jobb

frazze-jobb commented Sep 2, 2025 •

Copy link
Copy Markdown
Contributor

They can now be found in the official documentation

I updated the links above as well

@wmealing

wmealing commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

As a heads up. The "Creating a terminal application" links to https://www.erlang.org/doc/apps/stdlib/assets/tic-tac-toe.es, which has a problem.

The board characters served up the browser seem strangely encoded.
Screenshot 2025-11-04 at 1 53 00 pm

But when I use curl/wget it is encoded correctly.

Screenshot 2025-11-04 at 1 53 15 pm

I'll be looking where to report this correctly, but for now I'll report it here in case anyone trips over it.

@wmealing

wmealing commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

Probably a character encoding issue on the server.

I think the problem is that its serving this file as:

Content-Type: application/ecmascript

While it should be:

Content-Type: text/html; charset=utf-8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature team:VM Assigned to OTP team VM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants