summaryrefslogtreecommitdiff
path: root/pkgs/custom-neovim/config/lua/ui.lua
blob: 62127f134930b6f4564a6ffcf3a20dbf6c0e2f4c (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
-- UI customizations without plugins.

-- Statusline

-- TODO: Components to add
--
-- mode
-- git diff
-- git branch
--
-- cwd
--
-- lsp diagnostics
-- lsp status
-- position %
-- location ##:##

-- Highlight pattern
local hi_pattern = '%%#%s#%s%%*'

local statusline_components = {

  micro_spacer = function()
    return " "
  end,

  spacer = function()
    return '%='
  end,

  old_diagnostic_status = function()
    local ok = ' λ '

    local ignore = {
      ['c'] = true, -- command mode
      ['t'] = true  -- terminal mode
    }

    local mode = vim.api.nvim_get_mode().mode

    if ignore[mode] then
      return ok
    end

    local levels = vim.diagnostic.severity
    local errors = #vim.diagnostic.get(0, {severity = levels.ERROR})
    if errors > 0 then
      return ' ✘ '
    end

    local warnings = #vim.diagnostic.get(0, {severity = levels.WARN})
    if warnings > 0 then
      return ' ▲ '
    end

    return ok
  end,

  diagnostic_status = function()
    return ""
  end,

  mode = function()
    -- Note that: \19 = ^S and \22 = ^V.
    local mode_to_str = {
        ['n'] = 'NORMAL',
        ['no'] = 'OP-PENDING',
        ['nov'] = 'OP-PENDING',
        ['noV'] = 'OP-PENDING',
        ['no\22'] = 'OP-PENDING',
        ['niI'] = 'NORMAL',
        ['niR'] = 'NORMAL',
        ['niV'] = 'NORMAL',
        ['nt'] = 'NORMAL',
        ['ntT'] = 'NORMAL',
        ['v'] = 'VISUAL',
        ['vs'] = 'VISUAL',
        ['V'] = 'VISUAL',
        ['Vs'] = 'VISUAL',
        ['\22'] = 'VISUAL',
        ['\22s'] = 'VISUAL',
        ['s'] = 'SELECT',
        ['S'] = 'SELECT',
        ['\19'] = 'SELECT',
        ['i'] = 'INSERT',
        ['ic'] = 'INSERT',
        ['ix'] = 'INSERT',
        ['R'] = 'REPLACE',
        ['Rc'] = 'REPLACE',
        ['Rx'] = 'REPLACE',
        ['Rv'] = 'VIRT REPLACE',
        ['Rvc'] = 'VIRT REPLACE',
        ['Rvx'] = 'VIRT REPLACE',
        ['c'] = 'COMMAND',
        ['cv'] = 'VIM EX',
        ['ce'] = 'EX',
        ['r'] = 'PROMPT',
        ['rm'] = 'MORE',
        ['r?'] = 'CONFIRM',
        ['!'] = 'SHELL',
        ['t'] = 'TERMINAL',
    }

    -- Get the respective string to display.
    local mode = mode_to_str[vim.api.nvim_get_mode().mode] or 'UNKNOWN'

    -- Set the highlight group.
    local hl = 'MiniStatuslineModeOther'
    if mode:find 'NORMAL' then
        hl = 'MiniStatuslineModeNormal'
    elseif mode:find 'PENDING' then
        hl = 'MiniStatuslineModeNormal'
    elseif mode:find 'VISUAL' then
        hl = 'MiniStatuslineModeVisual'
    elseif mode:find 'REPLACE' then
        hl = 'MiniStatuslineModeReplace'
    elseif mode:find 'INSERT' or mode:find 'SELECT' then
        hl = 'MiniStatuslineModeInsert'
    elseif mode:find 'COMMAND' or mode:find 'TERMINAL' or mode:find 'EX' then
        hl = 'MiniStatuslineModeCommand'
    end

    -- Construct the component.
    return hi_pattern:format(hl, string.format(' %s ', mode))
  end,

  git_branch = function()
    if vim.b.minigit_summary and vim.b.minigit_summary.head_name then
        return string.format('  %s ', vim.b.minigit_summary.head_name)
    else
        return '' -- Return an empty string or some default value if the branch name is not available
    end
  end

}

Statusline_component = function(name)
  return statusline_components[name]()
end

local get_component = function(name)
  return string.format('%%{%%v:lua.Statusline_component("%s")%%} ', name)
end

local statusline = {
  get_component("micro_spacer"),
  get_component("mode"),
  get_component("diagnostic_status"),
  get_component("git_branch"),
  get_component("spacer"), -- spacer
  '%{&filetype}', -- filetype
  ' %2p%%', -- progress %
  ' %3l:%-2c ' -- position
}

vim.o.statusline = table.concat(statusline, '')