Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Preview show "[Process exited 0]" when delta is used #32

Closed
Zeioth opened this issue Jun 5, 2023 · 7 comments
Closed

Bug: Preview show "[Process exited 0]" when delta is used #32

Zeioth opened this issue Jun 5, 2023 · 7 comments

Comments

@Zeioth
Copy link

Zeioth commented Jun 5, 2023

On linux
screenshot_2023-06-05_02-39-30_650523552

EDIT: I see previewers.new_termopen_previewer is a Telescope method, so I should probably report it there.

@debugloop
Copy link
Owner

Your EDIT is entirely correct, nothing I can do about this message from my end 🙃

@medwatt
Copy link

medwatt commented Jul 23, 2024

I came across this issue. Is there a solution for it?

@Ajaymamtora
Copy link

Is there any fix for this?

@debugloop
Copy link
Owner

Hi, there is no "fix" for this. Feel free to read up on it at the issue created by OP, which concerns the API I am using.

As far as I can tell that issue only contains hacky fixes which involve stripping the last line or similar. I am not willing to implement those just for aesthetics, others might consider the line useful: It is proof that delta ran successfully and no lingering terminal is running in the background. Further, this message actually comes from the underlying :term command used by the Telescope API which I in turn use here. You can try it out yourself by running :term echo for instance.

Feel free to create an issue with Telescope, as anything I could do would basically patch their API response anyhow. If they respond similarly, you could decide to take it up in a Neovim issue. However, I hardly think they'll consider it: This would be a breaking change for plugins and scripts which might depend on that line being there.

@debugloop debugloop closed this as not planned Won't fix, can't repro, duplicate, stale Aug 9, 2024
@Ajaymamtora
Copy link

Thanks I read that but how would I use the workaround for just undo-telescope?

@debugloop
Copy link
Owner

I haven't tried it myself, but you would do the same as the commenters there: Set the previewer in the opts and Telescope should pick it up correctly. You can copy the previewer used by telescope-undo as a base and implement their changes on top or go for theirs entirely at first 👍🏻

@Ajaymamtora
Copy link

I haven't tried it myself, but you would do the same as the commenters there: Set the previewer in the opts and Telescope should pick it up correctly. You can copy the previewer used by telescope-undo as a base and implement their changes on top or go for theirs entirely at first 👍🏻

Thanks I used yours as a base then merged it in, this seems to work:

    local function open_undo_ts()
      local previewers = require("telescope.previewers")

      local function get_previewer(opts)
        if opts.use_custom_command ~= nil then
          return previewers.new_termopen_previewer({
            get_command = function(entry)
              local difftext = entry.value.diff:gsub("'", [['"'"']])
              return vim.tbl_map(function(part)
                return part:gsub("$DIFF", difftext)
              end, opts.use_custom_command)
            end,
          })
        end

        local has_powershell = vim.fn.executable("powershell") == 1
        local has_bash = vim.fn.executable("bash") == 1

        if
          opts.use_delta
          and not _G.__os.is_wsl
          and (has_powershell or has_bash)
          and vim.fn.executable("delta") == 1
        then
          return previewers.new_termopen_previewer({
            get_command = function(entry)
              local append = opts.side_by_side and " -s" or ""
              if has_powershell then
                return {
                  "powershell",
                  "-Command",
                  "echo '" .. entry.value.diff:gsub([[']], [['']]) .. "' | delta" .. append,
                }
              elseif has_bash then
                return {
                  "bash",
                  "-c",
                  "echo '" .. entry.value.diff:gsub("'", [['"'"']]) .. "' | delta" .. append,
                }
              end
            end,
          })
        else
          -- Original undo previewer
          -- return previewers.new_buffer_previewer({
          --   define_preview = function(self, entry)
          --     vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, true, vim.split(entry.value.diff, "\n"))
          --     require("telescope.previewers.utils").highlighter(
          --       self.state.bufnr,
          --       "diff",
          --       { preview = { treesitter = { enable = {} } } }
          --     )
          --   end,
          -- })
          return previewers.new_buffer_previewer({
            define_preview = function(self, entry, status)
              local dir_name = vim.fn.substitute(vim.fn.getcwd(), "^.*/", "", "")
              local t = {}
              if entry.value == dir_name then
                local s = vim.fn.system("git status -s")
                for chunk in string.gmatch(s, "[^\n]+") do
                  t[#t + 1] = chunk
                end
              else
                local s = vim.fn.system("git -C " .. entry.value .. " status -s")
                for chunk in string.gmatch(s, "[^\n]+") do
                  t[#t + 1] = chunk
                end
              end
              vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, true, t)
            end,
          })
        end
      end

      require("telescope").extensions.undo.undo({
        get_previewer = get_previewer,
      })
    end

    vim.api.nvim_create_user_command("TelescopeUndo", open_undo_ts, {})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants