wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
18.08k stars 808 forks source link

Docs: augment-command-palette docs do not show how to add multiple commands #6211

Open alecthegeek opened 1 month ago

alecthegeek commented 1 month ago

What Operating System(s) are you seeing this problem on?

macOS

Which Wayland compositor or X11 Window manager(s) are you using?

No response

WezTerm version

wezterm 20240203-110809-5046fc22

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

No, and I'll explain why below

Describe the bug

I am not using nightly builds because I want to document mainstream behaviour.

When using the augment-command-palette event only the 1st command is registered.

To Reproduce

For example

wezterm.log_info(wezterm.on('augment-command-palette', function(window, pane)
  return {
    {
      brief = "Action Number 1",
      icon = 'fa_plug',

      action = wezterm.action.PromptInputLine {
        description = "Action Number 1",
        action = wezterm.action_callback(function(window, pane, line)  -- do nothing but wait for keypress
        end),
        },
      },
    }
  end))

wezterm.log_info(wezterm.on('augment-command-palette', function(window, pane)
  return {
    {
      brief = "Action Number 2",
      icon = 'fa_plug',

      action = wezterm.action.PromptInputLine {
        description = "Action Number 2",
        action = wezterm.action_callback(function(window, pane, line)  -- do nothing but wait for keypress
        end),
        },
      },
    }
  end))

Only the 1st action is show in the command palette.

Configuration

See above

Expected Behavior

I expect action 1 and action 2 to appear in the command palette

Logs

No response

Anything else?

No response

neogeographica commented 1 month ago

The handler must return a table containing elements for both action 1 and action 2.

alecthegeek commented 1 month ago

However each time any existing entries are replaced. This is a problem, for example when two plugins both want to add palette commands.

I propose to make this a documentation fix, and create a new enhancement request to allow new entries to be added to the command palette.

An example:

wezterm.on('augment-command-palette', function(window, pane)
  return {
    {
        brief = 'Action 1',
      icon = 'fa_plug',

      action = wezterm.action.PromptInputLine {
        description = "This is action 1",
        action = wezterm.action_callback(function(window, pane, line)  -- do nothing but wait for keypress
        end),
      },
    },
    {
      brief = 'Action 2
      icon = 'fa_plug',

      action = wezterm.action.PromptInputLine {
        description = "This is action 2",
        action = wezterm.action_callback(function(window, pane, line)  -- do nothing but wait for keypress
        end),
      },
    },
  }
end)