simplinput

Package Version Hex Docs

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

Requires Erlang/OTP 28+ on the Erlang target.

gleam add simplinput

Usage

Reading whole input

import gleam/io
import simplinput

pub fn main() {
  case simplinput.read() {
    Ok(text) -> io.println(text)
    Error(_) -> io.println_error("failed to read stdin")
  }
}
$ echo "Hello, Joe" | gleam run
Hello, Joe

Interactive CLI helpers

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
  }
}
$ gleam run
Name: Joe
Hello, Joe
✨ Search Document