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 terminal.initialize()
before calling this widget's :run()
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()
Methods
cli.prompt:draw (redraw) | Draw the prompt and input value. |
cli.prompt:handleInput () | Processes key input async This function listens for key events and processes them. |
cli.prompt:init (opts) | Create a new Prompt instance. |
cli.prompt:run (redraw) | Starts the prompt input loop. |
Methods
- cli.prompt:draw (redraw)
-
Draw the prompt and input value.
This function writes the prompt and the current input value to the terminal.
Parameters:
- redraw boolean ????
Returns:
-
nothing
- 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:init (opts)
-
Create a new Prompt instance.
Parameters:
- opts Options for the prompt.
Returns:
-
Prompt
A new Prompt instance.
- 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: