andweeb / presence.nvim

Discord Rich Presence for Neovim
817 stars 65 forks source link

Add support for processes on ToggleTerm #61

Open kabessao opened 2 years ago

kabessao commented 2 years ago

Is your feature request related to a problem? Please describe. Whenever I open lazygit using toggleterm this shows up: image

Describe the solution you'd like Show that I'm commiting files.

Describe alternatives you've considered Explain how it would be possible to configure it myself if that is the case.

Additional context I'm using the Lunarvim project

andweeb commented 2 years ago

Hi @kabessao! Sorry for the very late response, this year has been crazy hectic for me so I'm only just now following up on these issues.

As for your request, this has been something I've been meaning to add support for a while. Well, not lazygit specifically, but for any process running in a terminal window, as currently the plugin just sees a terminal window as a "read-only" buffer which is why you're seeing that "Reading ..." text in Discord.

Adding that full support however may take some time (time that I probably won't have soon), so here's a workaround for you to use to at least be able to customize the text to be more sensible:

require("presence"):setup {
    -- Example buf_name value: 64629:lazygit;#toggleterm#101
    reading_text = function(buf_name)
        -- Extract the process name running in toggleterm from the given buffer name
        local toggleterm_process = buf_name:match(".+:(.+);#toggleterm")

        -- Return custom text
        if toggleterm_process == "lazygit" then
            return "Committing files"
        end

        return string.format("Reading %s", buf_name)
    end
}

You could add also add any additional processes here that you'd wanna add custom text support for, maybe even create a mapping if you have quite a lot like this:

        local process_text = {
            ["ts-node"] = "Evaluating TypeScript in Node",
            croissant = "Evaluating Lua code",
            grip = "Previewing Markdown",
            lazygit = "Commiting files"
        }

        -- Return custom text
        if process_text[toggleterm_process] then
            return process_text[toggleterm_process]
        end

FYI when support is added for terminal windows, this code will most likely become defunct.

kabessao commented 2 years ago

Hello, and thank you for answering my question.

When I posted the issue I've had the feeling that this would take quite some time to be done, and I understand that everybody has its personal things going on, so for me it's not a problem. The project is awesome the way it is anyway, with or without this feature. And honestly, you providing a way for me to do this myself works wonderfully.

I see you've changed the title of the issue, so I'm gonna leave it open in case you need it or something.

andweeb commented 2 years ago

Thanks, I appreciate it :) Yep my thought is that I'd have this issue be open and represent the feature to add support for toggleterm in general (and potentially terminal windows as a whole), especially considering that the workaround above will be deprecated once support is added.

astahjmo commented 10 months ago

I'm thinking of taking some time off and I can help you with this if you need me to, anyway I'm doing something for the float term that might fit in with this. @andweeb