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