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 uiFunction 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> [confirm required] | String |
| confirm | User confirmation (yes/no) | <prompt message> | Boolean |
| pick | Single choice (select one option) | [prompt or config] <options list/string> | Any type |
| multi_pick | Multiple 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 truetrue: 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 listParameter Format:
- Parameter 1 (optional): Configuration object or prompt string
- Type:
MaporString - Supported configuration items:
msg: Prompt message (string)page_size: Number of options displayed per page (integer)starting_cursor: Initial cursor position (integer)
- Type:
- Options Data Source (choose one):
- List Expression:
list("Option1" "Option2" ...) - Multi-line String:
"Option1\nOption2\n..." - Multiple Parameter Form: Directly pass multiple option expressions
Ui.pick Option1 Option2 ...
- List Expression:
Example:
- Simple single choice:
1let color = (Ui.pick "Choose a color:" ["Red", "Green", "Blue"])- Using string option source:
1let fruits = "Apple\nBanana\nOrange"
2let choice = (Ui.pick "Choose your favorite fruit:" fruits)- 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 listParameter Format:
- Parameter 1 (optional): Configuration object or prompt string
- Type:
MaporString - Supported configuration items:
msg: Prompt message (string)page_size: Number of options displayed per page (integer)starting_cursor: Initial cursor position (integer)
- Type:
- Options Data Source (choose one):
- List Expression:
list("Option1" "Option2" ...) - Multi-line String:
"Option1\nOption2\n..." - Multiple Parameter Form: Directly pass multiple option expressions
Ui.multi_pick Option1 Option2 ...
- List Expression:
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)