Std.Process
effect ArgsThe arguments of the process, in order, without the name of the program.
-
fn get(index: Int) -> Option[String]The argument at
index(from 0), orNonewhenindexis negative or not less than the number of arguments. -
fn list() -> List[String]The arguments in the order given, without the name of the program.
InvalidInput
Section titled “InvalidInput”error InvalidInputStandard input is not valid UTF-8.
StdinFailure
Section titled “StdinFailure”error StdinFailure(message: String)The host cannot read standard input. message is the host’s text.
message: String
effect StdinReads standard input as text (UTF-8).
-
suspend fn read_line() -> Option[String] fails InvalidInput | StdinFailureThe next line without its line terminator (
\n, or\r\n), orNoneat the end of the input. -
suspend fn read_text() -> String fails InvalidInput | StdinFailureThe rest of the input, line terminators included, or
""at the end of the input.
SystemArgs
Section titled “SystemArgs”handler SystemArgs: Argsuses { ProcessHost }The arguments given by the host: argv[1] and after on native, what the launcher of
emela run passes on JS, and get-arguments without its first element on WASM. Has no state.
SystemStdin
Section titled “SystemStdin”handler SystemStdin: Stdinuses { Async, ProcessHost }The standard input of the process (JS process.stdin, file descriptor 0 on native). The host
starts reading only when an operation first waits, and does not keep the program running while
no operation waits. Requires Async. Has no state.
StdinLines
Section titled “StdinLines”type StdinLines(lines: List[String])The state of TestStdin: the lines not read yet.
lines: List[String]
TestStdin
Section titled “TestStdin”handler TestStdin: Stdinuses { State[StdinLines] }The test handler. It keeps the lines in State[StdinLines] and resumes at once, so use it
inside State.run:
(line, rest) = State.run(StdinLines(lines: ["a", "b"]), || { with TestStdin { stdin <- Stdin stdin.read_line() }})read_line removes the first line and returns it, or None when no line is left. read_text
returns the lines left joined with \n and leaves none. It never fails.
Stdout
Section titled “Stdout”effect StdoutWrites to the standard output of the process. Does not fail and does not suspend.
-
fn print(text: String) -> ()Writes
textas is. -
fn print_line(text: String) -> ()Writes
text, then\n.
Stderr
Section titled “Stderr”effect StderrWrites to the standard error of the process. Does not fail and does not suspend.
-
fn print(text: String) -> ()Writes
textas is. -
fn print_line(text: String) -> ()Writes
text, then\n.
SystemStdout
Section titled “SystemStdout”handler SystemStdout: Stdoutuses { ProcessHost }The standard output of the process: file descriptor 1, written synchronously, on JS, stdout
on native, and wasi:cli/stdout on WASM. Has no state.
SystemStderr
Section titled “SystemStderr”handler SystemStderr: Stderruses { ProcessHost }The standard error of the process: file descriptor 2, written synchronously, on JS, stderr
on native, and wasi:cli/stderr on WASM. Has no state.
StdoutText
Section titled “StdoutText”type StdoutText(text: String)The state of TestStdout: everything written so far.
text: String
StderrText
Section titled “StderrText”type StderrText(text: String)The state of TestStderr: everything written so far.
text: String
TestStdout
Section titled “TestStdout”handler TestStdout: Stdoutuses { State[StdoutText] }The test handler of Stdout. It appends what is written to text of State[StdoutText], so use
it inside State.run:
(_, out) = State.run(StdoutText(text: ""), || with TestStdout { stdout <- Stdout stdout.print("a")})assert out.text == "a"print_line appends \n after the text.
TestStderr
Section titled “TestStderr”handler TestStderr: Stderruses { State[StderrText] }The test handler of Stderr, the same as TestStdout with State[StderrText].
Process
Section titled “Process”layer Process { SystemConsole, SystemClock, SystemRandom, SystemHttp, SystemArgs, SystemStdin, SystemStdout, SystemStderr, SystemEnv, SystemFileSystem, SystemTcp }uses { Async, ProcessHost }Platform and the System handlers that need a process: the arguments, the standard streams, the
environment variables, the file system and TCP. Requires Async and ProcessHost ([effect.host]),
which main, tests and Http.serve are given. A program that uses none of these writes
with Platform { ... } instead.
ExitCode
Section titled “ExitCode”opaque enum ExitCodeThe exit code of a program, an Int from 0 to 255. A main that returns one exits with it
([dyn.error]). Making one uses no effect.
exit_code
Section titled “exit_code”fn exit_code(code: Int) -> ExitCodeThe exit code code. A defect if code is outside 0 to 255: the exit status of a POSIX process
and the argument of exit-with-code of WASI are 8 bits wide.
exit_code_to_int
Section titled “exit_code_to_int”fn exit_code_to_int(code: ExitCode) -> IntThe number of the exit code.
EXIT_SUCCESS
Section titled “EXIT_SUCCESS”const EXIT_SUCCESS: ExitCodeThe exit code 0.
EXIT_FAILURE
Section titled “EXIT_FAILURE”const EXIT_FAILURE: ExitCodeThe exit code 1.