Class cli.Prompt
Prompt input for CLI tools.
This module provides a simple way to read line input from the terminal. The user can confirm their choices by pressing <Enter> or cancel their choices by pressing <Esc>.
Features: Prompt, UTF8 support, async input, (to be added: secrets, scrolling and wrapping)
NOTE: you MUST call terminal.initialize before calling this widget's :run()
method.
Usage:
local prompt = Prompt { prompt = "Enter something: ", value = "Hello, 你-好 World 🚀!", max_length = 62, -- overflow = "wrap" -- or "scroll" -- TODO: implement -- cancellable = true, -- TODO: implement position = 2, } local result, exitkey = pr:run()
Functions
cli.Prompt (opts) | Create a new Prompt instance. |
Methods
cli.prompt:handleInput () | Processes key input async This function listens for key events and processes them. |
cli.prompt:run (redraw) | Starts the prompt input loop. |
Functions
- cli.Prompt (opts)
-
Create a new Prompt instance.
Parameters:
- opts Options for the prompt.
- prompt string or EditLine The prompt text to display. (default "")
- value string or EditLine The initial value of the prompt (truncated if too long). (default "")
- position number The initial cursor position (in char) of the input (default at the end). (optional)
- max_length number The maximum length of the input. (default 80)
- word_delimiters string Word delimiters for word operations. (optional)
- text_attr table Text attributes for the prompt (input value only). (optional)
- wordwrap boolean Whether to wordwrap the input value. (default false)
Returns:
-
Prompt
A new Prompt instance.
- opts Options for the prompt.
Methods
- cli.prompt:handleInput ()
-
Processes key input async
This function listens for key events and processes them.
Returns:
-
string "returned" or "cancelled" based on the key pressed.
- cli.prompt:run (redraw)
-
Starts the prompt input loop.
This function initializes the input loop for the readline instance.
It uses a coroutine to process key input until an exit key is pressed.
Parameters:
- redraw boolean Whether to redraw the prompt initially.
Returns: