components.lua 4.7 KB

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