1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-29 16:42:13 +03:00
wezterm/docs/config/lua/keyassignment/PromptInputLine.md
Wez Furlong e3e9821c4d
Add InputSelector action
Allows prompting the user to select from a list and then
triggering some action on the selected item.

This is the guts of the launcher menu hooked up to user-supplied
arbitrary entries.
2023-04-05 17:22:09 -07:00

2.6 KiB

PromptInputLine

{{since('nightly')}}

Activates an overlay to display a prompt and request a line of input from the user.

When the user enters the line, emits an event that allows you to act upon the input.

PromptInputLine accepts two fields:

  • description - the text to show at the top of the display area. You may embed escape sequences and/or use wezterm.format.
  • action - and event callback registerd via wezterm.action_callback. The callback's function signature is (window, pane, line) where window and pane are the Window and Pane objects from the current pane and window, and line is the text that the user entered. line may be nil if they hit Escape without entering anything, or CTRL-C to cancel the input.

Example of interactively renaming the current tab

local wezterm = require 'wezterm'
local act = wezterm.action

local config = wezterm.config_builder()
config.keys = {
  {
    key = 'E',
    mods = 'CTRL|SHIFT',
    action = act.PromptInputLine {
      description = 'Enter new name for tab',
      action = wezterm.action_callback(function(window, pane, line)
        -- line will be `nil` if they hit escape without entering anything
        -- An empty string if they just hit enter
        -- Or the actual line of text they wrote
        if line then
          window:active_tab():set_title(line)
        end
      end),
    },
  },
}

return config

Example of interactively picking a name and creating a new workspace

Similar to the above, but prompts for a name prior to creating the workspace.

This example also shows the use of wezterm.format to emit colored text.

local wezterm = require 'wezterm'
local act = wezterm.action

local config = wezterm.config_builder()
config.keys = {
  {
    key = 'N',
    mods = 'CTRL|SHIFT',
    action = act.PromptInputLine {
      description = wezterm.format {
        { Attribute = { Intensity = 'Bold' } },
        { Foreground = { AnsiColor = 'Fuchsia' } },
        { Text = 'Enter name for new workspace' },
      },
      action = wezterm.action_callback(function(window, pane, line)
        -- line will be `nil` if they hit escape without entering anything
        -- An empty string if they just hit enter
        -- Or the actual line of text they wrote
        if line then
          window:perform_action(
            act.SwitchToWorkspace {
              name = line,
            },
            pane
          )
        end
      end),
    },
  },
}

return config

See also InputSelector.