Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

neovim/lua/bugabinga/winbar.lua

Raw
local puk     = require 'std.puk'
local ignored = require 'std.ignored'
local icon    = require 'std.icon'
local table   = require 'std.table'

local function get_diagnostic_label( bufnr )
	local icons = {
		Error = icon.error,
		Warn = icon.warn,
		Info = icon.info,
		Hint = icon.hint,
	}

	local label = {}
	for severity, icon_txt in pairs( icons ) do
		local n = #vim.diagnostic.get( bufnr, { severity = vim.diagnostic.severity[string.upper( severity )] } )
		if n > 0 then
			table.insert( label, { icon_txt .. ' ' .. n .. ' ', group = 'DiagnosticSign' .. severity } )
		end
	end
	return label
end

puk.defer 'incline' ( function ( incline )
	incline.setup {
		ignore = {
			filetypes = ignored.filetypes,
		},
		debounce_threshold = { falling = 500, rising = 250 },
		window = {
			placement = {
				horizontal = 'right',
				vertical = 'bottom',
			},
			padding = 1,
			margin = {
				horizontal = 0,
				vertical = 1,
			},
		},
		render = function ( properties )
			local bufnr = properties.buf
			local focused = properties.focused
			local buffer_full_name = vim.api.nvim_buf_get_name( bufnr )
			local buffer_name = vim.fn.fnamemodify( buffer_full_name, ':t' )
			local filename = (buffer_name and buffer_name ~= '') and buffer_name or '[scratch]'
			local diagnostics = get_diagnostic_label( bufnr )
			local highlight = focused and 'WinBar' or 'WinBarNC'
			local modified_highlight = vim.api.nvim_get_option_value( 'modified', { buf = bufnr } ) and 'Title' or highlight
			local filetype_icon, icon_highlight = MiniIcons.get( 'file', buffer_name ) ---@diagnostic disable-line: undefined-global

			local buffer = {
				{ filetype_icon, group = icon_highlight },
				{ '  ' },
				{ filename,      group = modified_highlight },
			}

			if #diagnostics > 0 then
				table.insert( diagnostics, { '| ', group = highlight } )
			end
			for _, segment in ipairs( buffer ) do
				table.insert( diagnostics, segment )
			end
			return diagnostics
		end,
	}
end )