components.lua 4.8 KB

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