aboutsummaryrefslogtreecommitdiff
path: root/.config/nvim/lua/plugins/cokeline.lua
blob: 2b70c536ee25a349bcc08cdcc066b90da3ef5c3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
local state = require "state"

return {
    "willothy/nvim-cokeline",
    lazy = false,
    config = function()
        local hl = require "cokeline.hlgroups"
        local is_picking_focus = require("cokeline.mappings").is_picking_focus
        local is_picking_close = require("cokeline.mappings").is_picking_close

        local function has_diagnostics(buffer)
            return buffer.diagnostics.errors > 0
                or buffer.diagnostics.warnings > 0
                or buffer.diagnostics.infos > 0
                or buffer.diagnostics.hints > 0
        end

        require("cokeline").setup {
            show_if_buffers_are_at_least = 0,
            components = {
                {
                    text = function(buffer)
                        return buffer.is_first and (require("cokeline.sidebar").get_width "left" == 0 and "" or "│")
                            or "▎"
                    end,
                    fg = function()
                        return hl.get_hl_attr("WinSeparator", "fg")
                    end,
                    bg = function()
                        return hl.get_hl_attr("Normal", "bg")
                    end,
                },
                {
                    text = function(buffer)
                        return (is_picking_focus() or is_picking_close()) and " " .. buffer.pick_letter or ""
                    end,
                    fg = function()
                        return hl.get_hl_attr("PrismiteYellow", "fg")
                    end,
                },
                {
                    text = function(buffer)
                        return " " .. buffer.devicon.icon
                    end,
                    fg = function(buffer)
                        return buffer.devicon.color
                    end,
                },
                {
                    text = function(buffer)
                        return buffer.unique_prefix
                    end,
                    fg = function()
                        return hl.get_hl_attr("Comment", "fg")
                    end,
                    italic = true,
                },
                {
                    text = function(buffer)
                        return buffer.filename
                    end,
                },
                {
                    text = function(buffer)
                        return buffer.is_modified and " " or ""
                    end,
                },
                {
                    text = function(buffer)
                        return has_diagnostics(buffer) and " [" or ""
                    end,
                    fg = function()
                        return hl.get_hl_attr("WinSeparator", "fg")
                    end,
                },
                {
                    text = function(buffer)
                        local errors = buffer.diagnostics.errors
                        return errors > 0 and errors or ""
                    end,
                    fg = function()
                        return hl.get_hl_attr("DiagnosticError", "fg")
                    end,
                },
                {
                    text = function(buffer)
                        local bd = buffer.diagnostics
                        return (bd.errors > 0 and (bd.warnings > 0 or bd.infos > 0 or bd.hints > 0)) and "|" or ""
                    end,
                    fg = function()
                        return hl.get_hl_attr("WinSeparator", "fg")
                    end,
                },
                {
                    text = function(buffer)
                        local warnings = buffer.diagnostics.warnings
                        return warnings > 0 and warnings or ""
                    end,
                    fg = function()
                        return hl.get_hl_attr("DiagnosticWarn", "fg")
                    end,
                },
                {
                    text = function(buffer)
                        local bd = buffer.diagnostics
                        return (bd.warnings > 0 and (bd.infos > 0 or bd.hints > 0)) and "|" or ""
                    end,
                    fg = function()
                        return hl.get_hl_attr("WinSeparator", "fg")
                    end,
                },
                {
                    text = function(buffer)
                        local infos = buffer.diagnostics.infos
                        return infos > 0 and infos or ""
                    end,
                    fg = function()
                        return hl.get_hl_attr("DiagnosticInfo", "fg")
                    end,
                },
                {
                    text = function(buffer)
                        local bd = buffer.diagnostics
                        return (bd.infos > 0 and bd.hints > 0) and "|" or ""
                    end,
                    fg = function()
                        return hl.get_hl_attr("WinSeparator", "fg")
                    end,
                },
                {
                    text = function(buffer)
                        local hints = buffer.diagnostics.hints
                        return hints > 0 and hints or ""
                    end,
                    fg = function()
                        return hl.get_hl_attr("DiagnosticHint", "fg")
                    end,
                },
                {
                    text = function(buffer)
                        return has_diagnostics(buffer) and "]" or ""
                    end,
                    fg = function()
                        return hl.get_hl_attr("WinSeparator", "fg")
                    end,
                },
                {
                    text = "  ",
                },
            },
            buffers = {
                delete_on_right_click = false,
            },
            mappings = {
                disable_mouse = true,
            },
            sidebar = {
                components = {
                    {
                        text = function()
                            local width = require("cokeline.sidebar").get_width "left"
                            if #state.nvim_tree_root > width then
                                return state.nvim_tree_root:sub(1, width - 2) .. "…"
                            else
                                return state.nvim_tree_root
                            end
                        end,
                        bg = function()
                            return hl.get_hl_attr("TabLineSel", "bg")
                        end,
                    },
                    {
                        text = function()
                            return string.rep(
                                " ",
                                math.max(0, require("cokeline.sidebar").get_width "left" - #state.nvim_tree_root)
                            )
                        end,
                        bg = function()
                            return hl.get_hl_attr("TabLineSel", "bg")
                        end,
                    },
                },
            },
        }
    end,
    dependencies = { "nvim-tree/nvim-web-devicons", "nvim-lua/plenary.nvim" },
    keys = {
        {
            "<leader>bp",
            function()
                require("cokeline.mappings").pick "focus"
            end,
            desc = "Pick a buffer to focus",
        },
        {
            "<leader>bd",
            function()
                require("cokeline.mappings").pick "close"
            end,
            desc = "Pick a buffer to close",
        },
        {
            "<Leader>p",
            function()
                require("cokeline.mappings").by_step("switch", -1)
            end,
            desc = "Move current buffer left",
            silent = true,
        },
        {
            "<Leader>n",
            function()
                require("cokeline.mappings").by_step("switch", 1)
            end,
            desc = "Move current buffer right",
            silent = true,
        },
    },
}