components.lua 5.4 KB

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