pyodide/docs/usage
Hood Chatham 7422ab370d
Implement more detailed streams support (#3268)
Resolves https://github.com/pyodide/pyodide/issues/3112
This adds a carefully designed API for controlling stdin, stdout, and stderr. It changes
the default behavior to be a bit more useful, though in doing so introduces some mild
backwards incompatibility. In particular:

1. By default, stdin reads directly from `process.stdin` in node (as before) and raises an
error if in browser (not as before).
2. By default, stdout writes directly to `process.stdout` in node (before it called console.log)
and calls console.log in browser (as before).
3. By default, stderr writes directly to `process.stderr` in node (before it called console.warn)
and calls console.warn in browser (as before).
4. In all three cases, by default isatty(stdin/stdout/stderr) is true in node and false in browser
(in the browser it used to be true).
5. As before, if you pass `stdin`, `stdout`, or `stderr` as arguments to `loadPyodide`, `isatty` of
the corresponding stream is set to false.

The stdin function is now more flexible: we now correctly handle the case where it returns an
ArrayBuffer or ArrayBufferView.

I also added 3 new functions to set streams after Pyodide is loaded which offer additional
control:
* `setStdin({stdin?, error?, isatty = false})` -- Sets the stdin function. The stdin function takes no
arguments and should return null, undefined, a string, or a buffer. Sets and `isatty(stdin)` to 
`isatty` (by default `false`). If error is true, set stdin to always raise an EIO error when it is read.
* `setStdout({raw?, batched?, isatty = false})` -- If neither raw nor batched is passed, restore 
default stdout behavior. If rwa is passed, the raw stdout function receives a byte which it should
interpret as a utf8 character code. Sets `isatty(stdout)` to isatty (by default `false`). If batched is
passed but not raw, it sets a batched stdout function. The stdout function receives a string and
should do something with it. In this case it ignores isatty and sets isatty(stdout) to false.
* `setStderr({raw?, batched?, isatty = false})` -- same but with stderr.
2022-12-18 15:55:52 -08:00
..
api Update to micropip v0.2.0 (#3347) 2022-12-14 09:11:19 +01:00
api-reference.md Update to micropip v0.2.0 (#3347) 2022-12-14 09:11:19 +01:00
downloading-and-deploying.md DOC Remove warnings about pyodide-cdn2.iodide.io (#3150) 2022-09-26 09:46:19 +02:00
faq.md docs: fix typos (#3359) 2022-12-16 11:13:52 -08:00
file-system.md DOC Add a FAQ entry for async filesystem usage (#3222) 2022-11-04 11:04:35 +09:00
index.md Remove "Python initialization complete" log line (#3247) 2022-12-12 18:54:47 -08:00
keyboard-interrupts.md DOCS Edits and updates (#2756) 2022-06-21 20:15:37 -07:00
loading-custom-python-code.md DOC Fix doc warnings (#2898) 2022-07-25 13:30:56 +09:00
loading-packages.md [pre-commit.ci] pre-commit autoupdate (#2928) 2022-09-13 15:12:40 -07:00
packages-in-pyodide.md DOCS Edits and updates (#2756) 2022-06-21 20:15:37 -07:00
quickstart.md Fix Pyodide REPL URL (#3244) 2022-11-10 15:53:37 +01:00
service-worker.md Allow use with (module-type) service workers (#3070) 2022-09-17 21:35:32 -07:00
streams.md Implement more detailed streams support (#3268) 2022-12-18 15:55:52 -08:00
type-conversions.md [pre-commit.ci] pre-commit autoupdate (#2928) 2022-09-13 15:12:40 -07:00
wasm-constraints.md Rename unvendored _hashlib to hashlib (#3349) 2022-12-14 09:05:17 +01:00
webworker.md [pre-commit.ci] pre-commit autoupdate (#2928) 2022-09-13 15:12:40 -07:00