mfussenegger / nvim-dap

Debug Adapter Protocol client implementation for Neovim
GNU General Public License v3.0
5.11k stars 179 forks source link

Color output not displayed correctly in debugpy with Neovim DAP #1114

Closed lyy4758 closed 6 months ago

lyy4758 commented 6 months ago

Debug adapter definition and debug configuration

    config = function()
        local dap = require("dap")
        dap.adapters.python = {
            type = "executable",
            command = os.getenv("HOME") .. "/anaconda3/envs/aigc/bin/python", -- 
            args = { "-m", "debugpy.adapter" },
        }

        dap.configurations.python = {
            {
                type = "python",
                request = "launch",
                name = "Launch Flask App",
                program = "${workspaceFolder}/app.py", -
                -- args = {"run", "--no-debugger", "--no-reload", "--port", "5001"};
                pythonPath = function()
                    return os.getenv("HOME") .. "/anaconda3/envs/aigc/bin/python" --
                end,
                env = {

                    FLASK_ENV = "local",
                },

                gevent = true, -- 
            },
        }
    end,

Debug adapter version

No response

Steps to Reproduce

1.Open a Python file in Neovim. 2.Set up a breakpoint in the file by placing :DapBreakpoint on the desired line. 3.Start the debugging session by running :DapContinue.

Expected Result

"With this feature, when a script outputs colored text (using ANSI color codes), the nvim-dap REPL should display these colors. For example, error messages could appear in red, warnings in yellow, etc., similar to how they are displayed in a standard terminal."

Actual Result

"Currently, the nvim-dap REPL displays all text in monochrome. ANSI color codes are either stripped or displayed as raw text, which can be hard to read and interpret." image

Vinzent03 commented 3 months ago

Hey, I'm facing the same issue. Were you able to solve the issue, or just accepted it?

mfussenegger commented 3 months ago

Hey, I'm facing the same issue. Were you able to solve the issue, or just accepted it?

You can set console = "integratedTerminal" in your configuration to have it run in a real terminal that supports color codes. If you don't want to run it in an integrated terminal you could try setting a NO_COLOR=1 environment variable. Most sane apps honor that flag (see http://no-color.org/)

That said, I'd be open to change the output processing and strip out color codes for the REPL

serranomorante commented 3 months ago

Another option could be using chrisbra/Colorizer

The following code is working for me on vscode-js-debug DAP (which doesn't have an "integratedTerminal" option in request=launch type=pwa-chrome).

return {
  "chrisbra/Colorizer",
  lazy = false,
  init = function()
    vim.g.colorizer_auto_filetype = "dap-repl"
    vim.g.colorizer_disable_bufleave = 1

    vim.api.nvim_create_autocmd("FileType", {
      desc = "Force colorize on dap-repl",
      pattern = "dap-repl",
      group = vim.api.nvim_create_augroup("auto_colorize", { clear = true }),
      callback = function() vim.cmd("ColorHighlight!") end,
    })
  end,
}