components.lua 5.9 KB

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