summaryrefslogtreecommitdiffstats
path: root/after/plugin/statusline.lua
blob: d3a6ed24292a30f120b44626fba12580ee72ea74 (plain) (blame)
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
local status_ok, el = pcall(require, "el")
if not status_ok then
  return
end

el.reset_windows()

local builtin = require "el.builtin"
local sections = require "el.sections"
local c = require "components"

-- color setup
local hl_statusline = "StatusLine"
--diagnostic colors
local hl_hint = "DiagnosticHint"
local hl_info = "DiagnosticInfo"
local hl_warn = "DiagnosticWarn"
local hl_err = "DiagnosticError"
-- git colors
local hl_red = "ErrorMsg"
local hl_green = "diffAdded"
local hl_yellow = "WarningMsg"
local highlights = {
  -- diagnostic colors
  diag_err = c.extract_hl({
    bg = { [hl_statusline] = "bg" },
    fg = { [hl_err] = "fg" },
    bold = true,
  }),
  diag_warn = c.extract_hl({
    bg = { [hl_statusline] = "bg" },
    fg = { [hl_warn] = "fg" },
    bold = true,
  }),
  diag_info = c.extract_hl({
    bg = { [hl_statusline] = "bg" },
    fg = { [hl_info] = "fg" },
    bold = true,
  }),
  diag_hint = c.extract_hl({
    bg = { [hl_statusline] = "bg" },
    fg = { [hl_hint] = "fg" },
    bold = true,
  }),

  -- git colors
  red_fg = c.extract_hl({
    bg = { [hl_statusline] = "bg" },
    fg = { [hl_red] = "fg" },
    bold = true,
  }),
  green_fg = c.extract_hl({
    bg = { [hl_statusline] = "bg" },
    fg = { [hl_green] = "fg" },
    bold = true,
  }),
  yellow_fg = c.extract_hl({
    bg = { [hl_statusline] = "bg" },
    fg = { [hl_yellow] = "fg" },
    bold = true,
  }),
}

-- modes
local modes = {
  --     display name, mode, highlight group
  n      = { "Normal", "N" },
  niI    = { "Normal", "N" },
  niR    = { "Normal", "N" },
  niV    = { "Normal", "N" },
  no     = { "N·OpPd", "?" },
  v      = { "Visual", "V" },
  V      = { "V·Line", "Vl" },
  [""]   = { "V·Block", "Vb" },
  s      = { "Select", "S" },
  S      = { "S·Line", "Sl" },
  [""]   = { "S·Block", "Sb" },
  i      = { "Insert", "I" },
  ic     = { "ICompl", "Ic" },
  R      = { "Replace", "R" },
  Rv     = { "VReplace", "Rv" },
  c      = { "Command", "C" },
  cv     = { "Vim Ex", "E" },
  ce     = { "Ex (r)", "E" },
  r      = { "Prompt", "P" },
  rm     = { "More  ", "M" },
  ["r?"] = { "Confirm", "Cn" },
  ["!"]  = { "Shell ", "S" },
  nt     = { "Term  ", "T" },
  t      = { "Term  ", "T" },
}

el.setup {
  generator = function()

  local items = {
    { c.mode { modes = modes, fmt = " %s %s ", icon = "", hl_icon_only = false } },
    { sections.split, required = true },
    { sections.collapse_builtin { { builtin.filetype }, { " " } } },
    { sections.maximum_width(builtin.tail_file, 0.50), required = true },
    { sections.collapse_builtin { { " " }, { builtin.modified_flag } } },
    { sections.split, required = true },
    { c.diagnostics {
      fmt = "[%s]", lsp = true,
      hl_err  = highlights.diag_err,
      hl_warn = highlights.diag_warn,
      hl_info = highlights.diag_info,
      hl_hint = highlights.diag_hint,
      icon_err = 'x', icon_warn = '!', icon_info = 'i', icon_hint = 'h'
    }
    },
    { c.git_branch { fmt = "%s *%s", icon = "" } },
    { c.git_changes_buf {
        fmt = "[%s]",
        icon_insert = "+",
        icon_change = "~",
        icon_delete = "-",
        hl_insert = highlights.green_fg,
        hl_change = highlights.yellow_fg,
        hl_delete = highlights.red_fg,
      }
    },
  }

  local add_item = function(result, item)
    table.insert(result, item)
  end

  local result = {}
  for _, item in ipairs(items) do
    add_item(result, item)
  end

  return result
end,
}