starlight-terminalui
v1.0.1
Published
Interactive terminal UI utilities for Starlight Programming Language
Maintainers
Readme
Starlight TerminalUI Usage
Introduction: Starlight TerminalUI is a module that helps you create interactive terminal programs easily. It provides menus, input prompts, colored text, confirmations, and progress bars.
Importing TerminalUI
readline-sync is required as a dependency.
Use the following import in your Starlight script:
import TerminalUI from "starlight-terminalui"
Basic Features
1. Menu
TerminalUI.menu(title, options)
Displays a simple numbered menu.
- title: string, the menu title
- options: array of strings, menu items
- Returns: the index of the selected option, or null if invalid
2. Confirm
TerminalUI.confirm(message)
Shows a yes/no prompt to the user.
- message: string, the question
- Returns: true if yes, false if no
3. Input
TerminalUI.input(message, options)
Prompts the user for input.
- message: string, the prompt text
- options: optional object for readline-sync options
- Returns: string entered by the user
4. Select
TerminalUI.select(message, choices)
Displays a list of choices navigable with arrow keys.
- message: string, the prompt
- choices: array of strings
- Returns: index of selected choice, -1 if cancelled
5. Print
TerminalUI.print(text, style)
Displays text in color.
- text: string, content to display
- style: optional, one of red, green, yellow, blue, magenta, cyan, white
- Defaults to white if no style is specified
6. Progress Bar
TerminalUI.progress(total, delay, label)
Shows a progress bar animation.
- total: number of steps
- delay: milliseconds per step
- label: string, label displayed before the bar
Example Usage
` import TerminalUI from "starlight-terminalui";
func main() { let name = TerminalUI.input("What is your name?"); TerminalUI.print("Hello, " + name + "!", "cyan");
let choice = TerminalUI.menu("Pick a fruit:", ["Apple", "Banana", "Cherry"]); if (choice != null) { TerminalUI.print("You picked: " + ["Apple", "Banana", "Cherry"][choice], "green"); }
let proceed = TerminalUI.confirm("Do you want to see a progress bar?"); if (proceed) TerminalUI.progress(20, 100, "Loading");
sldeploy "Demo finished!"; }
main(); `
