numToStr / FTerm.nvim

:fire: No-nonsense floating terminal plugin for neovim :fire:
MIT License
721 stars 24 forks source link

Trigger FocusGained after closing the terminal window #86

Open mjakl opened 1 year ago

mjakl commented 1 year ago

When I manipulate an open file through FTerm (like resetting the file via LazyGit, or simply echo test >> file.txt, I need to manually reload the file from disk when I close/toggle FTerm.

NeoVim usually checks for modifications on FocusGained events, and reloads the files automatically if autoread is active. E.g. when I call echo anothertest >> file.txt in a separate terminal, and then switch back to Vim, the file is reloaded automatically.

Is it possible for FTerm to issue the FocusGained event to trigger the check if the file has been modified when closing FTerm? Users can decide how to deal with this through the autoread option.

It looks like NeoVim has an API for that nvim_ui_set_focus since 0.8.0 (see this ticket).

mjakl commented 1 year ago

Small sidenote: when toggling FTerm, it is possible to include :checktime to check for file-changes and reload on demand. For example: vim.keymap.set("t", "<F7>", "<C-\\><C-n><CMD>lua require('FTerm').toggle()<CR>:checktime<CR>")

To trigger this behavior on exit (FTerm close), I can add a on_exit callback:

        on_exit = function()
          vim.cmd(":checktime")
        end,