amber/stdin
Values
pub fn close() -> Result(Nil, error.Error)
Closes stdin, freeing the resource.
Examples
let assert Ok(_) = stdin.close()
pub fn is_terminal() -> Bool
Checks if stdin is a TTY (terminal).
Examples
// This example is system and context specific
stdin.is_terminal() // True
pub fn read(
p: uint8_array.Uint8Array,
) -> promise.Promise(Result(option.Option(Int), error.Error))
Read the incoming data from stdin into an array buffer (p).
Resolves to either the number of bytes read during the operation or EOF
(None) if there was nothing more to read.
It is possible for a read to successfully return with 0 bytes. This
does not indicate EOF.
It is not guaranteed that the full buffer will be read in a single call.
Examples
// If the text "hello world" is piped into the script:
let buf = uint8_array.from_length(100)
use result <- promise.then(stdin.read(buf))
let assert Ok(bytes_read) = result
// bytes_read == Some(11)
let text = text_decoder.decode(uint8_array.buffer(buf))
// text == "hello world"
pub fn read_sync(
p: uint8_array.Uint8Array,
) -> Result(option.Option(Int), error.Error)
Synchronously read from the incoming data from stdin into an array
buffer (p).
Returns either the number of bytes read during the operation or EOF
(None) if there was nothing more to read.
It is possible for a read to successfully return with 0 bytes. This
does not indicate EOF.
It is not guaranteed that the full buffer will be read in a single call.
Examples
// If the text "hello world" is piped into the script:
let buf = uint8_array.from_length(100)
let assert Ok(bytes_read) = stdin.read_sync(buf)
// bytes_read == Some(11)
let text = text_decoder.decode(uint8_array.buffer(buf))
// text == "hello world"
pub fn readable() -> readable_stream.ReadableStream(
uint8_array.Uint8Array,
)
A readable stream interface to stdin.
pub fn set_raw(mode: Bool) -> Result(Nil, error.Error)
Set TTY to be under raw mode or not. In raw mode, characters are read and returned as is, without being processed. All special processing of characters by the terminal is disabled, including echoing input characters. Reading from a TTY device in raw mode is faster than reading from a TTY device in canonical mode.
Examples
let assert Ok(_) = stdin.set_raw(True)
pub fn set_raw_with(
mode mode: Bool,
with options: List(set_raw.SetRawOption),
) -> Result(Nil, error.Error)
Set TTY to be under raw mode or not with options.
Examples
let assert Ok(_) = stdin.set_raw_with(True, [set_raw.Cbreak(True)])