nvterm icon indicating copy to clipboard operation
nvterm copied to clipboard

auto-focus with .send?

Open joshvisionalgo opened this issue 1 year ago • 2 comments

Loving nvterm. I have mapped a binding to use .send to run lazygit in a new term. Is there a way to assign focus to the term when using .send? I noticed auto-focus works when using .toggle or .new, but not .send.

joshvisionalgo avatar May 02 '23 19:05 joshvisionalgo

I encountered the same problem and went with this for the time being:

["<leader>gg"] = {
  function()
    local nvterm = require "nvterm.terminal"
    local terminal = nvterm.new "float"
    local id = terminal.job_id

    -- The previous id was not always right for some reason so I made a fallback, 
    -- as you can only have one floating terminal
    for _, term in pairs(nvterm.list_terms()) do
      if term.type == "float" then
        id = term.job_id
      end
    end

    if vim.api.nvim_buf_is_valid(id) then
      vim.api.nvim_chan_send(id, "lazygit && exit\n")
    end
  end,
  "Open Lazygit",
},

Npahlfer avatar May 23 '23 08:05 Npahlfer

I could not get it to work this way with an error. It seems to be possible if it is not a float.

Instead, I used the following silly method.

    ["<leader>gg"] = {
      function()
        local nvterm = require "nvterm.terminal"
        nvterm.send("lazygit && exit", "float")
        nvterm.toggle "float"
        nvterm.toggle "float"
      end,
      "Open lazygit",
    },

umlx5h avatar Sep 22 '23 02:09 umlx5h