components.lua 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. local conditions = require "lvim.core.lualine.conditions"
  2. local colors = require "lvim.core.lualine.colors"
  3. local function diff_source()
  4. local gitsigns = vim.b.gitsigns_status_dict
  5. if gitsigns then
  6. return {
  7. added = gitsigns.added,
  8. modified = gitsigns.changed,
  9. removed = gitsigns.removed,
  10. }
  11. end
  12. end
  13. local statusline_hl = vim.api.nvim_get_hl_by_name("StatusLine", true)
  14. local cursorline_hl = vim.api.nvim_get_hl_by_name("CursorLine", true)
  15. local normal_hl = vim.api.nvim_get_hl_by_name("Normal", true)
  16. vim.api.nvim_set_hl(0, "SLGitIcon", { fg = "#E8AB53", bg = cursorline_hl.background })
  17. vim.api.nvim_set_hl(0, "SLBranchName", { fg = normal_hl.foreground, bg = cursorline_hl.background })
  18. vim.api.nvim_set_hl(0, "SLProgress", { fg = "#ECBE7B", bg = statusline_hl.background })
  19. local location_color = nil
  20. local branch = lvim.icons.git.Branch
  21. local separator = lvim.icons.ui.LineMiddle
  22. if lvim.colorscheme == "tokyonight" then
  23. location_color = "SLBranchName"
  24. branch = "%#SLGitIcon#" .. lvim.icons.git.Branch .. "%*" .. "%#SLBranchName#"
  25. local status_ok, tnc = pcall(require, "tokyonight.colors")
  26. if status_ok then
  27. local tncolors = tnc.setup { transform = true }
  28. vim.api.nvim_set_hl(0, "SLSeparator", { fg = cursorline_hl.background, bg = tncolors.black })
  29. separator = "%#SLSeparator#" .. lvim.icons.ui.LineMiddle .. "%*"
  30. end
  31. end
  32. return {
  33. mode = {
  34. function()
  35. return " " .. lvim.icons.ui.Target .. " "
  36. end,
  37. padding = { left = 0, right = 0 },
  38. color = {},
  39. cond = nil,
  40. },
  41. branch = {
  42. "b:gitsigns_head",
  43. icon = branch,
  44. color = { gui = "bold" },
  45. },
  46. filename = {
  47. "filename",
  48. color = {},
  49. cond = nil,
  50. },
  51. diff = {
  52. "diff",
  53. source = diff_source,
  54. symbols = {
  55. added = lvim.icons.git.LineAdded .. " ",
  56. modified = lvim.icons.git.LineModified .. " ",
  57. removed = lvim.icons.git.LineRemoved .. " ",
  58. },
  59. padding = { left = 2, right = 1 },
  60. diff_color = {
  61. added = { fg = colors.green },
  62. modified = { fg = colors.yellow },
  63. removed = { fg = colors.red },
  64. },
  65. cond = nil,
  66. },
  67. python_env = {
  68. function()
  69. local utils = require "lvim.core.lualine.utils"
  70. if vim.bo.filetype == "python" then
  71. local venv = os.getenv "CONDA_DEFAULT_ENV" or os.getenv "VIRTUAL_ENV"
  72. if venv then
  73. local icons = require "nvim-web-devicons"
  74. local py_icon, _ = icons.get_icon ".py"
  75. return string.format(" " .. py_icon .. " (%s)", utils.env_cleanup(venv))
  76. end
  77. end
  78. return ""
  79. end,
  80. color = { fg = colors.green },
  81. cond = conditions.hide_in_width,
  82. },
  83. diagnostics = {
  84. "diagnostics",
  85. sources = { "nvim_diagnostic" },
  86. symbols = {
  87. error = lvim.icons.diagnostics.BoldError .. " ",
  88. warn = lvim.icons.diagnostics.BoldWarning .. " ",
  89. info = lvim.icons.diagnostics.BoldInformation .. " ",
  90. hint = lvim.icons.diagnostics.BoldHint .. " ",
  91. },
  92. -- cond = conditions.hide_in_width,
  93. },
  94. treesitter = {
  95. function()
  96. return lvim.icons.ui.Tree
  97. end,
  98. color = function()
  99. local buf = vim.api.nvim_get_current_buf()
  100. local ts = vim.treesitter.highlighter.active[buf]
  101. return { fg = ts and not vim.tbl_isempty(ts) and colors.green or colors.red }
  102. end,
  103. cond = conditions.hide_in_width,
  104. },
  105. lsp = {
  106. function(msg)
  107. msg = msg or "LS Inactive"
  108. local buf_clients = vim.lsp.buf_get_clients()
  109. if next(buf_clients) == nil then
  110. -- TODO: clean up this if statement
  111. if type(msg) == "boolean" or #msg == 0 then
  112. return "LS Inactive"
  113. end
  114. return msg
  115. end
  116. local buf_ft = vim.bo.filetype
  117. local buf_client_names = {}
  118. -- add client
  119. for _, client in pairs(buf_clients) do
  120. if client.name ~= "null-ls" then
  121. table.insert(buf_client_names, client.name)
  122. end
  123. end
  124. -- add formatter
  125. local formatters = require "lvim.lsp.null-ls.formatters"
  126. local supported_formatters = formatters.list_registered(buf_ft)
  127. vim.list_extend(buf_client_names, supported_formatters)
  128. -- add linter
  129. local linters = require "lvim.lsp.null-ls.linters"
  130. local supported_linters = linters.list_registered(buf_ft)
  131. vim.list_extend(buf_client_names, supported_linters)
  132. local unique_client_names = vim.fn.uniq(buf_client_names)
  133. return "[" .. table.concat(unique_client_names, ", ") .. "]"
  134. end,
  135. separator = separator,
  136. color = { gui = "bold" },
  137. cond = conditions.hide_in_width,
  138. },
  139. location = { "location", color = location_color },
  140. progress = {
  141. "progress",
  142. fmt = function()
  143. return "%P/%L"
  144. end,
  145. color = {},
  146. },
  147. spaces = {
  148. function()
  149. local shiftwidth = vim.api.nvim_buf_get_option(0, "shiftwidth")
  150. return lvim.icons.ui.Tab .. " " .. shiftwidth
  151. end,
  152. separator = separator,
  153. padding = 1,
  154. },
  155. encoding = {
  156. "o:encoding",
  157. fmt = string.upper,
  158. color = {},
  159. cond = conditions.hide_in_width,
  160. },
  161. filetype = { "filetype", cond = nil, padding = { left = 1, right = 1 } },
  162. scrollbar = {
  163. function()
  164. local current_line = vim.fn.line "."
  165. local total_lines = vim.fn.line "$"
  166. local chars = { "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" }
  167. local line_ratio = current_line / total_lines
  168. local index = math.ceil(line_ratio * #chars)
  169. return chars[index]
  170. end,
  171. padding = { left = 0, right = 0 },
  172. color = "SLProgress",
  173. cond = nil,
  174. },
  175. }