components.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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, "SLGitIcon", { fg = "#E8AB53", bg = cursorline_hl.background })
  17. vim.api.nvim_set_hl(0, "SLBranchName", { fg = normal_hl.foreground, bg = cursorline_hl.background })
  18. vim.api.nvim_set_hl(0, "SLProgress", { fg = "#ECBE7B", bg = statusline_hl.background })
  19. local location_color = nil
  20. local branch = ""
  21. if lvim.colorscheme == "tokyonight" then
  22. location_color = "SLBranchName"
  23. branch = "%#SLGitIcon#" .. "" .. "%*" .. "%#SLBranchName#"
  24. end
  25. return {
  26. mode = {
  27. function()
  28. return "  "
  29. end,
  30. padding = { left = 0, right = 0 },
  31. color = {},
  32. cond = nil,
  33. },
  34. branch = {
  35. "b:gitsigns_head",
  36. icon = branch,
  37. color = { gui = "bold" },
  38. },
  39. filename = {
  40. "filename",
  41. color = {},
  42. cond = nil,
  43. },
  44. diff = {
  45. "diff",
  46. source = diff_source,
  47. symbols = { added = "  ", modified = " ", removed = " " },
  48. diff_color = {
  49. added = { fg = colors.green },
  50. modified = { fg = colors.yellow },
  51. removed = { fg = colors.red },
  52. },
  53. cond = nil,
  54. },
  55. python_env = {
  56. function()
  57. local utils = require "lvim.core.lualine.utils"
  58. if vim.bo.filetype == "python" then
  59. local venv = os.getenv "CONDA_DEFAULT_ENV" or os.getenv "VIRTUAL_ENV"
  60. if venv then
  61. return string.format("  (%s)", utils.env_cleanup(venv))
  62. end
  63. end
  64. return ""
  65. end,
  66. color = { fg = colors.green },
  67. cond = conditions.hide_in_width,
  68. },
  69. diagnostics = {
  70. "diagnostics",
  71. sources = { "nvim_diagnostic" },
  72. symbols = { error = " ", warn = " ", info = " ", hint = " " },
  73. -- cond = conditions.hide_in_width,
  74. },
  75. treesitter = {
  76. function()
  77. return ""
  78. end,
  79. color = function()
  80. local buf = vim.api.nvim_get_current_buf()
  81. local ts = vim.treesitter.highlighter.active[buf]
  82. return { fg = ts and not vim.tbl_isempty(ts) and colors.green or colors.red }
  83. end,
  84. cond = conditions.hide_in_width,
  85. },
  86. lsp = {
  87. function(msg)
  88. msg = msg or "LS Inactive"
  89. local buf_clients = vim.lsp.buf_get_clients()
  90. if next(buf_clients) == nil then
  91. -- TODO: clean up this if statement
  92. if type(msg) == "boolean" or #msg == 0 then
  93. return "LS Inactive"
  94. end
  95. return msg
  96. end
  97. local buf_ft = vim.bo.filetype
  98. local buf_client_names = {}
  99. -- add client
  100. for _, client in pairs(buf_clients) do
  101. if client.name ~= "null-ls" then
  102. table.insert(buf_client_names, client.name)
  103. end
  104. end
  105. -- add formatter
  106. local formatters = require "lvim.lsp.null-ls.formatters"
  107. local supported_formatters = formatters.list_registered(buf_ft)
  108. vim.list_extend(buf_client_names, supported_formatters)
  109. -- add linter
  110. local linters = require "lvim.lsp.null-ls.linters"
  111. local supported_linters = linters.list_registered(buf_ft)
  112. vim.list_extend(buf_client_names, supported_linters)
  113. local unique_client_names = vim.fn.uniq(buf_client_names)
  114. return "[" .. table.concat(unique_client_names, ", ") .. "]"
  115. end,
  116. color = { gui = "bold" },
  117. cond = conditions.hide_in_width,
  118. },
  119. location = { "location", color = location_color },
  120. progress = {
  121. "progress",
  122. fmt = function()
  123. return "%P/%L"
  124. end,
  125. color = {},
  126. },
  127. spaces = {
  128. function()
  129. if not vim.api.nvim_buf_get_option(0, "expandtab") then
  130. return "Tab size: " .. vim.api.nvim_buf_get_option(0, "tabstop") .. " "
  131. end
  132. local size = vim.api.nvim_buf_get_option(0, "shiftwidth")
  133. if size == 0 then
  134. size = vim.api.nvim_buf_get_option(0, "tabstop")
  135. end
  136. return "Spaces: " .. size .. " "
  137. end,
  138. cond = conditions.hide_in_width,
  139. color = {},
  140. },
  141. encoding = {
  142. "o:encoding",
  143. fmt = string.upper,
  144. color = {},
  145. cond = conditions.hide_in_width,
  146. },
  147. filetype = { "filetype", cond = conditions.hide_in_width, padding = { left = 0, 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. }