akinsho / toggleterm.nvim

A neovim lua plugin to help easily manage multiple terminal windows
GNU General Public License v3.0
4.21k stars 170 forks source link

Question: keep terminal opened for session #502

Closed coffebar closed 9 months ago

coffebar commented 10 months ago

Hi, I have a plugin neovim-project, that manages projects as sessions. Project switching in based on :mks command. I see 0 existing plugins that support to keep terminals attached to sessions, and understand the reasons. But, I think maybe it's possible to implement this workflow in coop with toggleterm:

  1. open nvim with neovim-project & toggleterm, the last seesion loaded
  2. open terminal, do some stuff
  3. switch to another project (without closing nvim)
  4. open terminal, see a fresh terminal (old terminal is not available for user)
  5. switch back to previous project
  6. open terminal, see your stuff from step 2

Sound interesting?

neovim-project has an interface to be extended with save some data from other plugins. Data will be saved to the session file and restored back. It can be a terminal address or some other strings/tables.

So we can save some sort of link to the terminal on saving session and check it on restoring - if this terminal not still exists, restore it.

I am not familiar with how toggleterm works, and just asking:

  1. Can anyone help to make such an integration?
  2. Will it be useful to many people?
WizardStark commented 9 months ago

Commenting just to +1 this, I am religiously checking in on the status of this issue.

akinsho commented 9 months ago

FWIW neovim by default will attempt to restore a terminal buffer in a session as long as the user includes terminal in the sessionoptions. It will not restore the contents of the terminal and will generally just re-run the command that spawned the terminal if it was included in the name IIRC.

This plugin used to and is supposed to at least support that basic use case i.e. allow neovim to re-open and relaunch the terminal.

On the subject of restoring terminal output this is absolutely an issue for neovim upstream and definitely not for this plugin but is probably a non-starter. Don't think a person can re-open a session and pick back up with a terminal from another session since that buffer was destroyed and it's history is gone.

On the subject of just re-opening terminal from one session to another that should work similarly to the native functionality and that just needs fixing i.e. not sure what/when it broke.

I personally will not have time for this any time soon, anyone in the community is free to dig into the code base and try and restore the session behaviour and I will look at a PR. If no one else is willing to pick this up there's really no reason to check the status of this issue religiously as it will need someone to actually do the legwork.