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> (when cancellable is enabled).
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, position = 2, } local result, err = prompt:run() --> nil, "cancelled": if cancelled
Alternative short version:
local result, err = Prompt{ prompt = "What's your name: " }()
Note: ctrl-c is handled as a cancellation, just like escape (if the terminal was set up to handle ctrl-c).
Functions
| cli.Prompt (opts) | Create a new Prompt instance. |
Methods
| cli.prompt:run () | Starts the prompt input loop. |
Functions
Methods- 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)
- cancellable
boolean
When true, pressing <Esc> cancels
the input and
run()returns nil, "cancelled". (default false)
Returns:
-
Prompt
A new Prompt instance.
- opts Options for the prompt.