numToStr / FTerm.nvim

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

feature request - only auto close when cmd success (exit code 0) #61

Closed zhengpd closed 1 year ago

zhengpd commented 2 years ago

Currently, when auto_close = true, FTerm always close window after cmd finished, success or failure. I think it's useful to check the error msg if a cmd failed. So I suggest we can keep the terminal window if cmd didn't exit with code 0.

zhengpd commented 2 years ago

For example, here's what I do with FTerm for now to only close window on exit code 0:

local open_cmd = function(cmd)
  local term = require('FTerm'):new({
    cmd = cmd,
    auto_close = false,
    dimensions = { height = 1, width = 1 }
  })

  term.config.on_exit = function(job_id, code, event)
    if code == 0 then term:close(true) end
  end

  term:open()
end

The on_exit seems not supporting self:close so I have to split config.on_exit away from :new call.

numToStr commented 2 years ago

So I suggest we can keep the terminal window if cmd didn't exit with code 0.

I think your assessment is right. It would also be helpful in seeing the error message if the command didn't succeed.

numToStr commented 1 year ago

Apologies for coming so late on this. Now this should be the default behavior. Ref: https://github.com/numToStr/FTerm.nvim/commit/a798d1c0a54ff35257cad17b448c783028b8437b

zhengpd commented 1 year ago

@numToStr 👍 This could be really helpful.