cmake-tools.nvim icon indicating copy to clipboard operation
cmake-tools.nvim copied to clipboard

Integrate Toggleterm as terminal and executor

Open deeedob opened this issue 1 year ago • 14 comments

Toggleterm is a simple wrapper around native terminals. It extends native terminals and allows to execute processes on individual terminals and much more. It doesn't integrate nicely with cmake-tools however, where currently cmake-tools will use the native backend ignoring the toggleterm ones. It would be nice if there would be an additional Toggleterm backend.

Toggleterm provides access for custom terminals / customization with e.g. Terminal:new. It shouldn't be too complicated. Let's see if I find the time in the next days to implement this. Opinions welcome!

deeedob avatar Jan 18 '24 10:01 deeedob

Now, toggleterm is supported using the overseer, have you tried it?

Edit: add configuration

      cmake_executor = {             -- executor to use
        name = "overseer",           -- name of the executor
        ...
        default_opts = {             -- a list of default and possible values for executors
          ...
          overseer = {
            new_task_opts = {
              strategy = {
                "toggleterm",
                direction = "horizontal",
                autos_croll = true,
                quit_on_exit = "success"
              }
            },   -- options to pass into the `overseer.new_task` command
            ...
          },
          ...
      },

Civitasv avatar Jan 18 '24 11:01 Civitasv

Yes, i've tried it but I don't need another plugin (which I won't use) just for getting the output there. I would prefer a direct integration :)

deeedob avatar Jan 18 '24 12:01 deeedob

I understand. You can define a new executor/runner in the plugin. See the source code of overseer, quickfix and terminal to get some idea. It should not be that hard.

Civitasv avatar Jan 18 '24 12:01 Civitasv

Someday I may expose the definition of executor/runner as API so users can define their owns.

Civitasv avatar Jan 18 '24 12:01 Civitasv

I understand. You can define a new executor/runner in the plugin. See the source code of overseer, quickfix and terminal to get some idea. It should not be that hard.

I'll try something out in the following days, thanks.

Someday I may expose the definition of executor/runner as API so users can define their owns.

Yeah, that would be cool :)

deeedob avatar Jan 18 '24 19:01 deeedob

I've supported toggleterm as an executor or runner, just set executor or runner to toggleterm should be fine.

Civitasv avatar Jan 20 '24 12:01 Civitasv

Oh damn :D I was just about to push my version. Good job and thanks! I'm currently on it to improve it just a little bit and add some more features :)

deeedob avatar Jan 20 '24 13:01 deeedob

Okay, feel free to improve it 😄

Civitasv avatar Jan 20 '24 13:01 Civitasv

Okay, I've been improving it quite a bit. As e.g. running separate or unified terminals and also tracking the cmd finish accurately. I was a bit surprised about the chan_id property you've set and how you tracked the end of the cmd in general as on_exit will get invoked only if you start the terminal with the cmd and otherwise on shell exit. Anyway have a WIP patch here. Still need to fix some edgecases and create a PR then :)

deeedob avatar Jan 24 '24 18:01 deeedob

@Civitasv works great for me except that the command passed to toggleterm seems to contain unwanted parts:

/home/code/test/build/clang-17_mold/Debug/bin/test 
exit $? 

When the command finishes, exit$? is then executed by my shell.

Running separate or unified terminals would be really helpful @deeedob

athanase avatar Jan 25 '24 09:01 athanase

Yes, the ‘exit $?’ is used to stop the shell process. For reference, I kinda copied them from overseer.nvim.

Civitasv avatar Jan 25 '24 10:01 Civitasv

Okay, I've been improving it quite a bit. As e.g. running separate or unified terminals and also tracking the cmd finish accurately. I was a bit surprised about the chan_id property you've set and how you tracked the end of the cmd in general as on_exit will get invoked only if you start the terminal with the cmd and otherwise on shell exit. Anyway have a WIP patch here. Still need to fix some edgecases and create a PR then :)

Great to hear! And currently each cmd is executed using a separate shell process. After the command finish, we use exit $? to stop the shell process, then, the on_exit function will be executed.

Civitasv avatar Jan 25 '24 10:01 Civitasv

Ahh yeah, I see. I wanted to go with a different approach since I (personally) like it more if the shell stays 'active' e.g. just sending the cmd and then tracking the execution of it.

deeedob avatar Jan 25 '24 10:01 deeedob

I understand, actually our plugin’s terminal implementation(though kinda buggy) follows this idea, it is unified.

Civitasv avatar Jan 25 '24 10:01 Civitasv