Skip to main content
  1. Lumesh Document/
  2. Lumesh Libs/Modules/

Lumesh UI Module

611 words·3 mins
Table of Contents

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 the ability to select options. The calling format can use Ui.function_name(arg1, arg2) or space-separated parameters Ui.function_name arg1 arg2.

View Help
#

1help ui

Function List
#

Function NameDescriptionParameter FormatReturn Type
intRead integer input<prompt message>Integer
floatRead float input<prompt message>Float
textRead text input<prompt message>String
passwdRead password input<prompt message> [confirm required]String
confirmUser confirmation (yes/no)<prompt message>Boolean
pickSingle choice (select one option)[prompt or config] <options list/string>Any type
multi_pickMultiple choice (select multiple options)[prompt or config] <options list/string>List

Input Function Detailed Description
#

1. int - Read Integer Input
#

Get integer input from the user and validate its validity.

Syntax:

1Ui.int "Prompt message"

Example:

1; Read user age
2let age = (Ui.int "Please enter your age:")

2. float - Read Float Input
#

Get float input from the user and validate its validity.

Syntax:

1Ui.float "Prompt message"

Example:

1; Read product price
2let price = Ui.float "Please enter the product price:"

3. text - Read Text Input
#

Get a line of text input from the user.

Syntax:

1Ui.text "Prompt message"

Example:

1# Read username
2let name = Ui.text("Please enter your name:")

4. passwd - Read Password Input
#

Securely read password input, with an option to confirm the password.

Syntax:

1Ui.passwd "Prompt message" [confirm?]

Parameters:

  • confirm? (optional): Boolean, defaults to true
    • true: Requires password confirmation (input twice)
    • false: Does not require confirmation (input once)

Example:

1# Read password (requires confirmation)
2let pwd1 = (Ui.passwd "Set password:" True)
3
4# Read password (no confirmation)
5let pwd2 = (Ui.passwd "Please enter password:" false)

5. confirm - User Confirmation
#

Ask the user a yes/no question and return a boolean value.

Syntax:

1Ui.confirm "Prompt message"

Example:

1# Confirm whether to continue operation
2if (Ui.confirm "Do you want to continue the operation?") {
3    # Code to continue execution
4}

Selection Function Detailed Description
#

6. pick - Single Choice
#

Allow the user to select one option from multiple choices.

Syntax:

1Ui.pick [config|prompt] options 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)
  • Options 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:
1let color = (Ui.pick "Choose a color:" ["Red", "Green", "Blue"])
  1. Using string option source:
1let fruits = "Apple\nBanana\nOrange"
2let choice = (Ui.pick "Choose your favorite fruit:" fruits)
  1. Using detailed configuration:
1let oss = ["Windows", "Linux", "macOS"]
2let choice = Ui.pick({
3    msg: "Please select an operating system:",
4    page_size: 5,
5    starting_cursor: 1,
6    }, oss)

7. multi_pick - Multiple Choice
#

Allow the user to select multiple options from a list.

Syntax:

1Ui.multi_pick [config|prompt] options 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)
  • Options 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:

1Fs.ls -l | Ui.multi_pick "Which files do you want to delete?"
2
3let oss = ["Windows", "Linux", "macOS", "Android", "Nokia"]
4let choice = Ui.multi_pick({
5    msg: "Which operating systems have you used:",
6    page_size: 5,
7    starting_cursor: 1,
8    }, oss)

Related