otp icon indicating copy to clipboard operation
otp copied to clipboard

Implement lazy-read and noshell raw mode

Open garazdawi opened this issue 1 year ago • 2 comments

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 #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 #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 avatar Oct 17 '24 19:10 garazdawi

CT Test Results

    6 files    303 suites   3h 10m 25s :stopwatch: 5 401 tests 5 070 :white_check_mark: 330 :zzz: 1 :x: 7 972 runs  7 544 :white_check_mark: 427 :zzz: 1 :x:

For more details on these failures, see this check.

Results for commit 28953cea.

:recycle: 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

github-actions[bot] avatar Oct 17 '24 19:10 github-actions[bot]

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

*Creating a terminal application

garazdawi avatar Oct 18 '24 06:10 garazdawi

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

EliasDerHai avatar Aug 08 '25 17:08 EliasDerHai

They can now be found in the official documentation

I updated the links above as well

frazze-jobb avatar Sep 02 '25 11:09 frazze-jobb

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 avatar Nov 04 '25 03:11 wmealing

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

wmealing avatar Nov 04 '25 03:11 wmealing