Skip to content

Make DapUI extension work with the control bar #1251

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 51 additions & 11 deletions lua/lualine/extensions/nvim-dap-ui.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,58 @@
-- MIT license, see LICENSE for more details.
-- Extension for nvim-dap-ui
local M = {}

M.sections = {
lualine_a = { { 'filename', file_status = false } },
M.filetypes = {
"dap-repl",
"dapui_console",
"dapui_console",
"dapui_watches",
"dapui_stacks",
"dapui_breakpoints",
"dapui_scopes",
}

M.filetypes = {
'dap-repl',
'dapui_console',
'dapui_watches',
'dapui_stacks',
'dapui_breakpoints',
'dapui_scopes',
local function merge_colors(foreground, background)
local new_name = foreground .. background

local hl_fg = vim.api.nvim_get_hl(0, { name = foreground })
local hl_bg = vim.api.nvim_get_hl(0, { name = background })

local fg = string.format("#%06x", hl_fg.fg and hl_fg.fg or 0)
local bg = string.format("#%06x", hl_bg.bg and hl_bg.bg or 0)

vim.api.nvim_set_hl(0, new_name, { fg = fg, bg = bg })
return new_name
end

local function get_dap_repl_winbar(active)
local get_mode = require("lualine.highlight").get_mode_suffix

return function()
local filetype = vim.bo.filetype
local disabled_filetypes = { "dap-repl" }

if not vim.tbl_contains(disabled_filetypes, filetype) then
return ""
end

local background_color = string.format("lualine_b" .. "%s", active and get_mode() or "_inactive")

local controls_string = "%#" .. background_color .. "#"
for element in require("dapui.controls").controls():gmatch("%S+") do
local color, action = string.match(element, "%%#(.*)#(%%.*)%%#0#")
controls_string = controls_string .. " %#" .. merge_colors(color, background_color) .. "#" .. action
end
return controls_string
end
end

M.winbar = {
lualine_a = { { "filename", file_status = false } },
lualine_b = { get_dap_repl_winbar(true) },
}

M.inactive_winbar = {
lualine_a = { { "filename", file_status = false } },
lualine_b = { get_dap_repl_winbar(false) },
}

return M
Loading