Lumesh UI module

wiki libs

Lumesh ui Module User Manual

Overview

The ui module provides a set of interactive command-line interface functions that support user input of various data types (integers, floats, text, passwords, etc.) as well as option selection functionality. The calling method can use ui.function_name(arg1, arg2) or space-separated parameters ui.function_name arg1 arg2.

View Help

help ui

Function List

Function Name Description Parameter Format Return Type
int Read integer input <Prompt Message> Integer
float Read float input <Prompt Message> Float
text Read text input <Prompt Message> String
passwd Read password input <Prompt Message> [Require Confirmation] String
confirm User confirmation (Yes/No) <Prompt Message> Boolean
pick Single choice (select one option) [Prompt or Config] <Option List/String> Any Type
multi_pick Multiple choice (select multiple options) [Prompt or Config] <Option List/String> List

Detailed Description of Input Functions

1. int - Read Integer Input

Get integer input from the user and validate its validity.

Syntax:

ui.int "Prompt Message"

Example:

; Read user age
let age = (ui.int "Please enter your age:")

2. float - Read Float Input

Get float input from the user and validate its validity.

Syntax:

ui.float "Prompt Message"

Example:

; Read product price
let price = ui.float "Please enter the product price:"

3. text - Read Text Input

Get a line of text input from the user.

Syntax:

ui.text "Prompt Message"

Example:

; Read username
let name = ui.text("Please enter your name:")

4. passwd - Read Password Input

Securely read password input, with an option to require password confirmation.

Syntax:

ui.passwd "Prompt Message" [confirm?]

Parameters:

  • confirm? (optional): Boolean value, defaults to true
    • true: Requires password confirmation (input twice)
    • false: No confirmation needed (input once)

Example:

; Read password (requires confirmation)
let pwd1 = (ui.passwd "Set password:" True)

; Read password (no confirmation needed)
let pwd2 = (ui.passwd "Please enter password:" false)

5. confirm - User Confirmation

Prompt the user to answer a Yes/No question and return a boolean value.

Syntax:

ui.confirm "Prompt Message"

Example:

; Confirm whether to continue the operation
if (ui.confirm "Do you want to continue?") {
; Code to execute if confirmed
}

Detailed Description of Selection Functions

6. pick - Single Choice

Allow the user to select one option from multiple choices.

Syntax:

ui.pick [Config|Prompt] Option List

Parameter Format:

  • Parameter 1 (optional): Configuration object or prompt string
    • Type: Map or String
    • Supported Configuration Items:
      • msg: Prompt message (string)
      • page_size: Number of options displayed per page (integer)
      • starting_cursor: Initial cursor position (integer)
  • Option Data Source (choose one):
    1. List Expression: list("Option1" "Option2" ...)
    2. Multi-line String: "Option1\nOption2\n..."
    3. Multiple Parameter Form: Directly pass multiple option expressions ui.pick Option1 Option2 ...

Example:

  1. Simple single choice:
let color = (ui.pick "Choose a color:" ["Red", "Green", "Blue"])
  1. Using string option source:
let fruits = "Apple\nBanana\nOrange"
let choice = (ui.pick "Choose your favorite fruit:" fruits)
  1. Using detailed configuration:
let oss = ["Windows", "Linux", "Mac"]
let choice = ui.pick({
msg: "Please select an operating system:",
page_size: 5,
starting_cursor: 1,
}, oss)

7. multi_pick - Multiple Choice

Allow the user to select multiple options from a list.

Syntax:

ui.multi_pick [Config|Prompt] Option List

Parameter Format:

  • Parameter 1 (optional): Configuration object or prompt string
    • Type: Map or String
    • Supported Configuration Items:
      • msg: Prompt message (string)
      • page_size: Number of options displayed per page (integer)
      • starting_cursor: Initial cursor position (integer)
  • Option Data Source (choose one):
    1. List Expression: list("Option1" "Option2" ...)
    2. Multi-line String: "Option1\nOption2\n..."
    3. Multiple Parameter Form: Directly pass multiple option expressions ui.multi_pick Option1 Option2 ...

Example:

fs.ls -l | ui.multi_pick "Which files do you want to delete?"

let oss = ["Windows", "Linux", "Mac", "Android", "Nokia"]
let choice = ui.multi_pick({
msg: "Which operating systems have you used:",
page_size: 5,
starting_cursor: 1,
}, oss)