Giter Club home page Giter Club logo

gleam_stdin's Introduction

Package Version Hex Docs

stdin

stdin provides a synchronous iterator for consuming stdin. It supports all the non-browser targets, Erlang, Node, Deno, and Bun.

The goal of this package is to provide a uniform way of consuming stdin for all supported targets on all supported platforms.

Platform Target Status Date
Windows 10 All OK. 2024-06-08
macOS 14.5 All OK. 2024-06-11
Ubuntu 24.04 All OK. 2024-06-11
Fedora 40 All OK. 2024-06-11
gleam add stdin
import gleam/io
import gleam/iterator
import stdin.{stdin}

pub fn main() {
  stdin()
  |> iterator.to_list
  |> io.debug
}

Further documentation can be found at https://hexdocs.pm/stdin.

Development

cat README.md | gleam test --target=javascript --runtime=node
cat README.md | gleam test --target=javascript --runtime=bun
cat README.md | gleam test --target=javascript --runtime=deno
cat README.md | gleam test --target=erlang

gleam_stdin's People

Contributors

olian04 avatar

Stargazers

Mohammad Ali Talebi avatar Comamoca avatar Zoo Sky avatar lv avatar Andrew Chou avatar Jen Stehlik avatar  avatar  avatar

Watchers

 avatar

gleam_stdin's Issues

Add support for Deno

$ cat README.md | gleam run --target=javascript --runtime=deno
   Compiled in 0.01s
    Running win_test.main
error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'stdin')
  process.stdin.resume();
          ^
    at stdinGenerator (file:///C:/Users/rift9/projects/win_test/build/dev/javascript/stdin/js_ffi.mjs:7:11)
    at stdinGenerator.next (<anonymous>)
    at read_line (file:///C:/Users/rift9/projects/win_test/build/dev/javascript/stdin/js_ffi.mjs:48:22)
    at read_line (file:///C:/Users/rift9/projects/win_test/build/dev/javascript/stdin/stdin.mjs:8:15)
    at file:///C:/Users/rift9/projects/win_test/build/dev/javascript/gleam_stdlib/gleam/iterator.mjs:102:53
    at file:///C:/Users/rift9/projects/win_test/build/dev/javascript/gleam_stdlib/gleam/iterator.mjs:84:13
    at file:///C:/Users/rift9/projects/win_test/build/dev/javascript/gleam_stdlib/gleam/iterator.mjs:472:13
    at file:///C:/Users/rift9/projects/win_test/build/dev/javascript/gleam_stdlib/gleam/iterator.mjs:247:13
    at do_fold (file:///C:/Users/rift9/projects/win_test/build/dev/javascript/gleam_stdlib/gleam/iterator.mjs:152:13)
    at fold (file:///C:/Users/rift9/projects/win_test/build/dev/javascript/gleam_stdlib/gleam/iterator.mjs:167:10)

Document that non-UNIX environments are not supported

Hello!

The description of this package claims that only the browser is not supported, but it also does not work on Windows or any other environment without stdin being fd 0. It would be fab to document this.

Thank you,
Louis

EAGAIN: resource temporarily unavailable

Running the following code with Nodejs v22.2.0 throws an error

import gleam/io
import gleam/iterator.{Next}
import stdin.{stdin}

pub fn main() {
  let assert Next(line1, _) =
    stdin()
    |> iterator.step()
  io.debug(line1)

  let assert Next(line2, _) =
    stdin()
    |> iterator.step()
  io.debug(line2)
}
Screencast.from.2024-06-08.13-06-43.mp4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.