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.
    • prompt string The prompt text to display. (default "")
    • value string The initial value of the prompt. (default "")
    • max_length number The maximum length of the input. (default 80)
    • drawn_before boolean If the prompt has been drawn before. (default false)

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:

  1. string The final input value entered by the user.
  2. string The exit key that terminated the input loop.
generated by LDoc 1.5.0