components.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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(msg)
  92. msg = msg or "LS Inactive"
  93. local buf_clients = vim.lsp.buf_get_clients()
  94. if next(buf_clients) == nil then
  95. -- TODO: clean up this if statement
  96. if type(msg) == "boolean" or #msg == 0 then
  97. return "LS Inactive"
  98. end
  99. return msg
  100. end
  101. local buf_ft = vim.bo.filetype
  102. local buf_client_names = {}
  103. local copilot_active = false
  104. -- add client
  105. for _, client in pairs(buf_clients) do
  106. if client.name ~= "null-ls" and client.name ~= "copilot" then
  107. table.insert(buf_client_names, client.name)
  108. end
  109. if client.name == "copilot" then
  110. copilot_active = true
  111. end
  112. end
  113. -- add formatter
  114. local formatters = require "lvim.lsp.null-ls.formatters"
  115. local supported_formatters = formatters.list_registered(buf_ft)
  116. vim.list_extend(buf_client_names, supported_formatters)
  117. -- add linter
  118. local linters = require "lvim.lsp.null-ls.linters"
  119. local supported_linters = linters.list_registered(buf_ft)
  120. vim.list_extend(buf_client_names, supported_linters)
  121. local unique_client_names = vim.fn.uniq(buf_client_names)
  122. local language_servers = "[" .. table.concat(unique_client_names, ", ") .. "]"
  123. if copilot_active then
  124. language_servers = language_servers .. "%#SLCopilot#" .. " " .. lvim.icons.git.Octoface .. "%*"
  125. end
  126. return language_servers
  127. end,
  128. color = { gui = "bold" },
  129. cond = conditions.hide_in_width,
  130. },
  131. location = { "location" },
  132. progress = {
  133. "progress",
  134. fmt = function()
  135. return "%P/%L"
  136. end,
  137. color = {},
  138. },
  139. spaces = {
  140. function()
  141. local shiftwidth = vim.api.nvim_buf_get_option(0, "shiftwidth")
  142. return lvim.icons.ui.Tab .. " " .. shiftwidth
  143. end,
  144. padding = 1,
  145. },
  146. encoding = {
  147. "o:encoding",
  148. fmt = string.upper,
  149. color = {},
  150. cond = conditions.hide_in_width,
  151. },
  152. filetype = { "filetype", cond = nil, padding = { left = 1, right = 1 } },
  153. scrollbar = {
  154. function()
  155. local current_line = vim.fn.line "."
  156. local total_lines = vim.fn.line "$"
  157. local chars = { "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" }
  158. local line_ratio = current_line / total_lines
  159. local index = math.ceil(line_ratio * #chars)
  160. return chars[index]
  161. end,
  162. padding = { left = 0, right = 0 },
  163. color = "SLProgress",
  164. cond = nil,
  165. },
  166. }