catgoose / nvim

Neovim config for Typescript Angular/Vue and Lua plugin development
128 stars 0 forks source link

What plugin can be used to achieve this effect? #1

Closed jonahfang closed 11 months ago

jonahfang commented 11 months ago
image
jonahfang commented 11 months ago

I use akinsho/bufferline.nvim .

catgoose commented 11 months ago

That would be heirline. Heirline starts with nothing and you have to build your own statusline/winbars. It takes a little work to get setup, but you can really make it your own. For example, though it's hard to see in the screenshot there is an indicator at the bottom showing how far you have scrolled down a buffer:

image

That indicator is only shown on the active window.

jonahfang commented 11 months ago

Thanks for reply. Why do you not use plugin like 'akinsho/bufferline.nvim'? I want to see all buffers opened:

image
catgoose commented 11 months ago

Because I want to see the file name of the buffer in the current window and not all the buffers that I have open. I don't generally close buffers, and when I do I close all of them at once using bufdelete plug-in.

It's my opinion that it's a mistake to treat buffers as tabs the way bufferline shows them. They are the contents of a file that can be mounted into a window. They are not tabs. That's just my opinion of course.

jonahfang commented 11 months ago

Good! You make sense, but I need time to accept your point of view.

catgoose commented 11 months ago

I would recommend reading this if you haven't already:

https://gist.github.com/nifl/1178878

jonahfang commented 11 months ago

Thank you very much, you change my mind. I have just remove 'bufferline', and use 'heilline'+'lualine' (heiline just as winbar):

-- Just used as winbar
local config = function()
    local heirline = require("heirline")
    local conditions = require("heirline.conditions")
    local u = require("heirline.utils")
    local kanagawa = require("kanagawa.colors").setup({ theme = "wave" })
    local colors = kanagawa.palette
    heirline.load_colors(colors)
    local fn, api, bo = vim.fn, vim.api, vim.bo

    local winbar_inactive = {
        buftype = { "nofile", "prompt", "quickfix", "terminal","acwrite" },
        filetype = { "toggleterm", "qf", "terminal", "gypsy" },
    }
    local Align = { provider = "%=" }
    local Space = { provider = " " }
    local LeftSep = { provider = "" }

    local ActiveWindow = {
        hl = function()
            if conditions.is_active() then
                return { bg = active_background_color }
            else
                return { bg = inactive_background_color }
            end
        end,
    }
    local ActiveBlock = {
        hl = function()
            if conditions.is_active() then
                return { bg = active_foreground_color }
            else
                return { bg = active_foreground_color }
            end
        end,
    }
    local ActiveSep = {
        hl = function()
            if conditions.is_active() then
                return { fg = active_background_color }
            else
                return { fg = inactive_background_color }
            end
        end,
    }
    local FileIcon = {
        init = function(self)
            local filename = self.filename
            local extension = fn.fnamemodify(filename, ":e")
            self.icon, self.icon_color =
                require("nvim-web-devicons").get_icon_color(filename, extension, { default = true })
        end,
        provider = function(self)
            if self.filename == "" then
                return ""
            else
                return self.icon and (self.icon .. " ")
            end
        end,
        hl = function(self)
            return { fg = self.icon_color }
        end,
    }
    local FileName = {
        provider = function(self)
            local filename = fn.fnamemodify(self.filename, ":t")
            if filename == "" then
                return ""
            end
            if not conditions.width_percent_below(#filename, 0.1) then
                filename = fn.pathshorten(filename)
            end
            return filename
        end,
        hl = { fg = colors.oldWhite, bold = true },
    }
    local FileFlags = {
        {
            provider = function()
                if bo.modified then
                    return "[+] "
                end
            end,
            hl = { fg = colors.oldWhite, bold = true, italic = true },
        },
        {
            provider = function()
                if not bo.modifiable or bo.readonly then
                    return " "
                end
            end,
            hl = { fg = colors.roninYellow, bold = true, italic = true },
        },
    }
    local FileNameModifer = {
        hl = function()
            if bo.modified then
                return { italic = true, force = true }
            end
        end,
    }
    local FileType = {
        condition = function()
            return conditions.buffer_matches({ filetype = { "coderunner" } })
        end,
        provider = function()
            return bo.filetype
        end,
        hl = { fg = colors.oldWhite, bold = true },
    }
    local FileNameBlock = {
        init = function(self)
            self.filename = api.nvim_buf_get_name(0)
        end,
    }
    FileNameBlock = u.insert(
        FileNameBlock,
        FileType,
        u.insert(ActiveSep, LeftSep),
        Space,
        unpack(FileFlags),
        u.insert(FileNameModifer, FileName, Space, FileIcon),
        { provider = "%<" }
    )
    ActiveWinbar = {
        condition = function()
            local empty_buffer = function()
                return bo.ft == "" and bo.buftype == ""
            end
            -- return not conditions.buffer_matches(winbar_inactive) and not empty_buffer()
            return not empty_buffer()
        end,
        Align,
        u.insert(ActiveBlock, FileNameBlock),
    }

    local WinBars = {
        u.insert(ActiveWindow, ActiveWinbar),
    }

    heirline.setup({
        winbar = WinBars,
        opts = {
            disable_winbar_cb = function(args)
                return conditions.buffer_matches(winbar_inactive, args.buf)
            end,
        },
    })
    vim.opt.winbar = "%{%v:lua.require'heirline'.eval_winbar()%}"
end

return {
    "rebelot/heirline.nvim",
    config = config,
    event = "BufReadPre",
    dependencies = "nvim-tree/nvim-web-devicons",
}
jonahfang commented 11 months ago

The effect:

image
jonahfang commented 11 months ago

I lost the grey background of winbar filename, can you help me?

image

catgoose commented 11 months ago

I manually set the colors in colors.lua so make sure you are using the correct reference. You may have to verify the colors are correct. I can take a better look in the morning.

On Tue, Oct 10, 2023 at 6:39 PM Jonah Fang @.***> wrote:

I lost the grey background of winbar filename, can you help me?

[image: image] https://user-images.githubusercontent.com/16301509/274097185-8b02bfde-1405-4b39-88c0-01c2a777d7a4.png

— Reply to this email directly, view it on GitHub https://github.com/catgoose/nvim/issues/1#issuecomment-1756467827, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFAJNGH7P7GKCU3A5LTZAPTX6XMC3AVCNFSM6AAAAAA52KRRGOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJWGQ3DOOBSG4 . You are receiving this because you commented.Message ID: @.***>

jonahfang commented 11 months ago

I sovled. Your nvim configuration is awesome.

catgoose commented 11 months ago

Thanks I really appreciate that! I need to do a few tweaks here and there but I find it useful for work.

jonahfang commented 11 months ago

There are still some minor flaws in the interface:

image

My current config like this:

local config = function()
    local heirline = require("heirline")
    local conditions = require("heirline.conditions")
    local u = require("heirline.utils")
    local kanagawa = require("kanagawa.colors").setup({ theme = "wave" })
    local colors = kanagawa.palette
    heirline.load_colors(colors)
    local fn, api, bo = vim.fn, vim.api, vim.bo

    local active_background_color = colors.sumiInk3
    local active_foreground_color = colors.sumiInk5
    local inactive_background_color = colors.sumiInk1

    local winbar_inactive = {
        buftype = { "nofile", "prompt", "quickfix", "terminal","acwrite"},
        filetype = { "toggleterm", "qf", "terminal", "gypsy","neo-tree" },
    }
    local Align = { provider = "%=" }
    local Space = { provider = " " }
    local LeftSep = { provider = "" }

    local ActiveWindow = {
        hl = function()
            if conditions.is_active() then
                return { bg = active_background_color }
            else
                return { bg = inactive_background_color }
            end
        end,
    }
    local ActiveBlock = {
        hl = function()
            if conditions.is_active() then
                return { bg = active_foreground_color }
            else
                return { bg = active_foreground_color }
            end
        end,
    }
    local ActiveSep = {
        hl = function()
            if conditions.is_active() then
                return { fg = active_background_color }
            else
                return { fg = inactive_background_color }
            end
        end,
    }
    local FileName = {
        provider = function(self)
            local filename = fn.fnamemodify(self.filename, ":t")
            if filename == "" then
                return ""
            end
            if not conditions.width_percent_below(#filename, 0.1) then
                filename = fn.pathshorten(filename)
            end
            return filename
        end,
        hl = { fg = colors.oldWhite, bold = true },
    }
    local FileFlags = {
        {
            provider = function()
                if bo.modified then
                    return "[+] "
                end
            end,
            hl = { fg = colors.oldWhite, bold = true, italic = true },
        },
        {
            provider = function()
                if not bo.modifiable or bo.readonly then
                    return " "
                end
            end,
            hl = { fg = colors.roninYellow, bold = true, italic = true },
        },
    }
    local FileNameModifer = {
        hl = function()
            if bo.modified then
                return { italic = true, force = true }
            end
        end,
    }
    local FileNameBlock = {
        init = function(self)
            self.filename = api.nvim_buf_get_name(0)
        end,
    }
    FileNameBlock = u.insert(
        FileNameBlock,
        u.insert(ActiveSep, LeftSep),
        Space,
        unpack(FileFlags),
        u.insert(FileNameModifer, FileName, Space),
        { provider = "%<" }
    )
    ActiveWinbar = {
        condition = function()
            local empty_buffer = function()
                return bo.ft == "" and bo.buftype == ""
            end
            return not conditions.buffer_matches(winbar_inactive) and not empty_buffer()
        end,
        Align,
        u.insert(ActiveBlock, FileNameBlock),
    }

    local WinBars = {
        u.insert(ActiveWindow, ActiveWinbar),
    }

    heirline.setup({
        winbar = WinBars,
        opts = {
            disable_winbar_cb = function(args)
                return conditions.buffer_matches(winbar_inactive, args.buf)
            end,
        },
    })
    vim.opt.winbar = "%{%v:lua.require'heirline'.eval_winbar()%}"
end

return {
    "rebelot/heirline.nvim",
    config = config,
    event = "BufReadPre",
    dependencies = "nvim-tree/nvim-web-devicons",
}
jonahfang commented 11 months ago

The above problem only exists in MacOS iTerm2, in WezTerm it is ok.