node and browser bindings for gleam

bindings for node:readlines

Changed files
+31 -5
src
+1 -5
gleam.toml
··· 1 1 name = "plinth" 2 - version = "0.5.1" 2 + version = "0.5.2" 3 3 description = "Bindings to Node.js and browser platform APIs" 4 4 target = "javascript" 5 5 6 - # Fill out these fields if you intend to generate HTML documentation or publish 7 - # your project to the Hex package manager. 8 - # 9 6 licences = ["Apache-2.0"] 10 7 repository = { type = "github", user = "Crowdhailer", repo = "plinth" } 11 8 gleam = ">= 0.32.0" 12 - # links = [{ title = "Website", href = "https://gleam.run" }] 13 9 14 10 [dependencies] 15 11 gleam_stdlib = "~> 0.29 or ~> 1.0"
+16
src/plinth/node/readlines.gleam
··· 1 + import gleam/javascript/array.{type Array} 2 + import gleam/javascript/promise.{type Promise} 3 + 4 + pub type PromiseInterface 5 + 6 + @external(javascript, "../../plinth_node_readlines_ffi.mjs", "createInterface") 7 + pub fn create_interface( 8 + completer: fn(String) -> #(Array(String), String), 9 + history: Array(String), 10 + ) -> PromiseInterface 11 + 12 + @external(javascript, "../../plinth_node_readlines_ffi.mjs", "question") 13 + pub fn question(interface: PromiseInterface, prompt: String) -> Promise(String) 14 + 15 + @external(javascript, "../../plinth_node_readlines_ffi.mjs", "close") 16 + pub fn close(interface: PromiseInterface) -> Promise(String)
+14
src/plinth_node_readlines_ffi.mjs
··· 1 + import * as readline from 'node:readline/promises'; 2 + import { stdin as input, stdout as output } from 'node:process'; 3 + 4 + export function createInterface(completer, history) { 5 + return readline.createInterface({ input, output, completer, history }); 6 + } 7 + 8 + export function question(rl, prompt) { 9 + return rl.question(prompt) 10 + } 11 + 12 + export function close(rl) { 13 + return rl.close() 14 + }