readline

A readline library for MoonBit

readline
input
interactive
console
cli
moon add oboard/readline@0.1.6
Download zip
Author
Version
0.1.6
License
Apache-2.0
Last updated
8 months ago
Downloads
33
README

#oboard/readline

A readline library for MoonBit

#Features

  • ๐Ÿ”„ Callback-based: Asynchronous input handling with callback functions
  • ๐Ÿงน Resource management: Proper cleanup with close() method
  • ๐Ÿ“ Simple API: Easy-to-use interface for interactive console applications
  • ๐Ÿš€ Zero dependencies: Lightweight implementation using only standard libraries
  • ๐ŸŒ Cross-platform: Works on JavaScript, Native (C) targets

#Installation

Add this package to your MoonBit project:

moon add oboard/readline

#Quick Start

fn main {
let rl = @readline.new()
rl.question("What is your name? ", name => {
println("Hello " + name)
rl.question("How old are you? ", age => {
println("You are " + age + " years old")
rl.close()
})
})
}

#API Reference

#new() -> T

Creates a new readline instance.

let rl = @readline.new()

#T::question(self: T, question: String, callback: (String) -> Unit) -> Unit

Prompts the user with a question and calls the callback function with the user's input.

Parameters:
  • question: The prompt text to display
  • callback: Function to handle the user's input

rl.question("Enter your name: ", input => {
println("You entered: " + input)
})

#T::close(self: T) -> Unit

Cleans up the readline instance and releases resources.

rl.close()

#Platform Support

PlatformImplementationStatus
JavaScriptBrowser/Node.jsโœ… Supported
NativeC with stdioโœ… Supported
WebAssemblyWASMโŒ Unsupported

#Examples

#Simple Q&A

fn main {
let rl = @readline.new()
rl.question("What's your favorite color? ", color => {
println("Nice choice: " + color)
rl.close()
})
}

#Multiple Questions

fn main {
let rl = @readline.new()
rl.question("First name: ", first => {
rl.question("Last name: ", last => {
println("Full name: " + first + " " + last)
rl.close()
})
})
}

#Building and Testing

#Implementation Details

  • JavaScript: Uses prompt() for browser environments and stdin/stdout for Node.js
  • Native: Uses standard C scanf() and printf() functions

#License

Apache-2.0

#Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

#Changelog

#v0.1.0

  • Initial release
  • Cross-platform readline support
  • Basic question/answer functionality
  • Resource cleanup with close() method

type T

#
T::close

fn T::close(self : T) -> Unit

#
T::question

fn T::question(self : T, question : String, callback : (String) -> Unit) -> Unit

#
T::wait_for_completion

fn T::wait_for_completion(self : T) -> Unit

#
new

fn new() -> T

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

ยฉ 2026 mooncakes.io