aboutsummaryrefslogtreecommitdiff
path: root/.config/nvim/lua/plugins/ui.lua
blob: e79ee3aae6b9f8b842c9321e3ebe7d6b0fd74af5 (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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
local leap_active = false
vim.api.nvim_create_autocmd("User", {
    pattern = "LeapEnter",
    callback = function()
        leap_active = true
    end,
})

vim.api.nvim_create_autocmd("User", {
    pattern = "LeapLeave",
    callback = function()
        leap_active = false
    end,
})

local nvim_tree_root = nil

return {
    {
        "willothy/nvim-cokeline",

        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,
                    },
                    {
                        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,
                    },
                    {
                        ---@param buffer Buffer
                        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 #nvim_tree_root > width then
                                    return nvim_tree_root:sub(1, width - 2) .. "…"
                                else
                                    return 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") - #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" },
    },
    {
        "folke/trouble.nvim",
        opts = {},
        dependencies = { "nvim-tree/nvim-web-devicons" },
    },
    {
        "nvimdev/indentmini.nvim",
        config = true,
        opts = {
            char = "▏"
        }
    },
    {
        "folke/noice.nvim",
        event = "VeryLazy",
        opts = {
            cmdline = {
                format = {
                    cmdline = { icon = ":" },
                },
            },
            lsp = {
                override = {
                    ["vim.lsp.util.convert_input_to_markdown_lines"] = true,
                    ["vim.lsp.util.stylize_markdown"] = true,
                    ["cmp.entry.get_documentation"] = true,
                },
            },
            presets = {
                command_palette = true,
                long_message_to_split = true,
                inc_rename = false,
                lsp_doc_border = true,
            },
            messages = {
                view_search = false,
            },
            routes = {
                {
                    filter = {
                        event = "msg_show",
                        kind = "",
                        find = "Already at newest change",
                    },
                    view = "mini",
                },
                {
                    filter = {
                        event = "msg_show",
                        kind = "",
                        find = "Already at oldest change",
                    },
                    view = "mini",
                },
                {
                    filter = {
                        event = "msg_show",
                        kind = "",
                        find = "E486: Pattern not found:"
                    },
                    view = "mini"
                },
                -- normal search
                {
                    filter = {
                        event = "msg_show",
                        kind = "",
                        find = "E486: Pattern not found:"
                    },
                    view = "mini"
                },
                -- failed search
                {
                    filter = {
                        event = "msg_show",
                        kind = "",
                        find = "E486: Pattern not found:"
                    },
                    view = "mini"
                },
                -- undo
                {
                    filter = {
                        event = "msg_show",
                        kind = "",
                        find = "%d+ .+ line.?; before #%d+",
                    },
                    view = "mini",
                },
                {
                    filter = {
                        event = "msg_show",
                        kind = "",
                        find = "%d+ .+ line.?; before #%d+",
                    },
                    view = "mini",
                },
                -- redo
                {
                    filter = {
                        event = "msg_show",
                        kind = "",
                        find = "%d+ change; after #%d+",
                    },
                    view = "mini"
                },
            },
        },
        dependencies = {
            "MunifTanjim/nui.nvim",
            "rcarriga/nvim-notify",
        },
    },
    {
        "nvim-lualine/lualine.nvim",
        event = "VeryLazy",
        opts = {
            options = {
                section_separators = { left = "", right = "" },
                component_separators = { left = "", right = "" },
                fmt = function(str)
                    return vim.trim(str)
                end,
                globalstatus = true,
                disabled_filetypes = { "NvimTree" },
            },
            sections = {
                lualine_a = {
                    "mode",
                    {
                        function()
                            return "[L]"
                        end,
                        cond = function ()
                            return leap_active
                        end
                    },
                    {
                        function()
                            local reg = vim.fn.reg_recording()
                            if reg == "" then return "" end -- not recording
                            return "[@" .. reg .. "]"
                        end
                    }
                },
                lualine_b = { "filename" },
                lualine_c = { "diagnostics", "diff" },
                lualine_x = {
                    {
                        function ()
                            local noice_loaded, noice = pcall(require, "noice")
                            if noice_loaded then
                                return noice.api.status.command.get()
                            else
                                return ""
                            end
                        end,
                        cond = function()
                            local noice_loaded, noice = pcall(require, "noice")
                            if noice_loaded then
                                return noice.api.status.command.has()
                            else
                                return false
                            end
                        end
                    }
                },
                lualine_y = { "filetype" },
                lualine_z = { "searchcount", "progress", "location" },
            },
        },
        dependencies = {
            "nvim-tree/nvim-web-devicons",
        },
    },
    { "stevearc/dressing.nvim", config = true },
    {
        "nvim-tree/nvim-tree.lua",
        opts = {
            sort_by = "case_sensitive",
            view = {
                width = 30,
            },
            renderer = {
                root_folder_label = function() return ".." end,
                indent_markers = {
                    enable = true,
                },
                icons = {
                    show = {
                        folder_arrow = false,
                    },
                    glyphs = {
                        git = {
                            unstaged = "-",
                            staged = "+",
                            unmerged = "",
                            renamed = "󰏪",
                            untracked = "",
                            deleted = "󰆴",
                            ignored = "",
                        },
                    },
                },
            },
            filters = {
                git_ignored = false,
                custom = {
                    "^.git$",
                },
            },
        },
        config = function(_, opts)
            local api = require("nvim-tree.api")
            local Event = api.events.Event

            api.events.subscribe(Event.Ready, function()
                nvim_tree_root = api.tree.get_nodes().absolute_path
            end)

            api.events.subscribe(Event.TreeRendered, function()
                nvim_tree_root = api.tree.get_nodes().absolute_path
            end)

            require("nvim-tree").setup(vim.tbl_extend("force", opts, {
                -- on_attach = function ()
                --     local function opts(desc)
                --       return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
                --     end
                --
                --     local function edit_or_open()
                --       local node = api.tree.get_node_under_cursor()
                --
                --       if node.nodes ~= nil then
                --         -- expand or collapse folder
                --         api.node.open.edit()
                --       else
                --         -- open file
                --         api.node.open.edit()
                --         -- Close the tree if file was opened
                --         api.tree.close()
                --       end
                --     end
                --
                --     -- open as vsplit on current node
                --     local function vsplit_preview()
                --       local node = api.tree.get_node_under_cursor()
                --
                --       if node.nodes ~= nil then
                --         -- expand or collapse folder
                --         api.node.open.edit()
                --       else
                --         -- open file as vsplit
                --         api.node.open.vertical()
                --       end
                --
                --       -- Finally refocus on tree if it was lost
                --       api.tree.focus()
                --     end
                --
                --     vim.keymap.set("n", "l", edit_or_open,          opts("Edit Or Open"))
                --     vim.keymap.set("n", "h", api.tree.close,        opts("Close"))
                -- end
                --
            }))
        end,
        dependencies = {
            "nvim-tree/nvim-web-devicons",
        },
    },
    {
        "goolord/alpha-nvim",
        dependencies = { "nvim-tree/nvim-web-devicons" },
        config = function()
            require("alpha").setup(require "dash")
        end,
    },
}