wez / wezterm

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

lua bindings for split-pane --move-pane-id #4216

Open madushan1000 opened 11 months ago

madushan1000 commented 11 months ago

Is your feature request related to a problem? Please describe. I want to merge a pane(from different tab or window) to a split of current pane. I can already achieve this in a hacky way using wezterm cli split-pane --move-pane-id <id> (see comments). But it would be nicer to do this completely in lua.

Describe the solution you'd like New argument move_pane_id to pane:split function so the above functionality can be achieved in lua

madushan1000 commented 11 months ago

I can already achieve this with the bellow config, it'll list all the panes not in this tab, and will merge the selected pane into the split of current pane. But it has to use wezterm.run_child_process

function find_other_window_panes(window, pane)
  local windows = wezterm.mux.all_windows()
  local panes = {}
  for _, window in ipairs(windows) do
    for _, tab in ipairs(window:tabs()) do
      for _, pane in ipairs(tab:panes()) do
        table.insert(panes, pane)
      end
    end
  end

  local current_tab_panes = {}
  for _, pane in ipairs(window:active_tab():panes()) do
      for i, v in ipairs(panes) do
        if v:pane_id() == pane:pane_id() then
          table.remove(panes, i)
        end
      end
  end

  return panes
end

config.key_tables = {
  tmux_bindings = {
    { key = "d", action=wezterm.action_callback(function(window, pane)
      local choices = {}
      local panes =  find_other_window_panes(window, pane)
      for i,pane in ipairs(panes) do
        table.insert(choices, { id = tostring(i), label = pane:pane_id() .. '/' .. pane:get_title()})
      end

      window:perform_action(wezterm.action.InputSelector {
        action = wezterm.action_callback(function(window, pane, id, label)
          print(panes[1])
          if id and label then
            wezterm.run_child_process { 'wezterm', 'cli', 'split-pane', '--move-pane-id', panes[tonumber(id)]:pane_id(), '--pane-id', pane:pane_id()}
          end
        end),
        title = "select pane",
        choices = choices,
      },
      pane)
    end)},
  }
}

config.keys = {
    { 
      key = "a", 
      mods = 'CTRL', 
      action = wezterm.action.ActivateKeyTable { 
        name = 'tmux_bindings', 
        timeout_milliseconds = 500,
        one_shot = false,
        -- until_unknown = true,
      }, 
    }

}

return config