Packages

Synchronous cross-target stdin reading for Erlang, Node.js, Deno, and Bun

Current section

Files

Jump to
simplinput README.md
Raw

README.md

# simplinput

[![Package Version](https://img.shields.io/hexpm/v/simplinput)](https://hex.pm/packages/simplinput)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://simplinput.hexdocs.pm/)

Synchronous, cross-target stdin reading for Gleam across Erlang, Node.js, Deno, and Bun.

Requires Erlang/OTP 28+ on the Erlang target.

```sh
gleam add simplinput
```

## Usage

### Reading whole input

```gleam
import gleam/io
import simplinput

pub fn main() {
  case simplinput.read() {
    Ok(text) -> io.println(text)
    Error(_) -> io.println_error("failed to read stdin")
  }
}
```

```shell
$ echo "Hello, Joe" | gleam run
Hello, Joe
```

### Interactive CLI helpers

```gleam
import gleam/io
import simplinput

pub fn main() {
  case simplinput.is_tty() {
    True ->
      case simplinput.prompt("Name: ") {
        Ok(name) -> io.println("Hello, " <> name)
        Error(_) -> Nil
      }
    False -> Nil
  }
}
```

```shell
$ gleam run
Name: Joe
Hello, Joe
```