components.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. padding = { left = 2, right = 1 },
  49. diff_color = {
  50. added = { fg = colors.green },
  51. modified = { fg = colors.yellow },
  52. removed = { fg = colors.red },
  53. },
  54. cond = nil,
  55. },
  56. python_env = {
  57. function()
  58. local utils = require "lvim.core.lualine.utils"
  59. if vim.bo.filetype == "python" then
  60. local venv = os.getenv "CONDA_DEFAULT_ENV" or os.getenv "VIRTUAL_ENV"
  61. if venv then
  62. return string.format("  (%s)", utils.env_cleanup(venv))
  63. end
  64. end
  65. return ""
  66. end,
  67. color = { fg = colors.green },
  68. cond = conditions.hide_in_width,
  69. },
  70. diagnostics = {
  71. "diagnostics",
  72. sources = { "nvim_diagnostic" },
  73. symbols = { error = " ", warn = " ", info = " ", hint = " " },
  74. -- cond = conditions.hide_in_width,
  75. },
  76. treesitter = {
  77. function()
  78. return ""
  79. end,
  80. color = function()
  81. local buf = vim.api.nvim_get_current_buf()
  82. local ts = vim.treesitter.highlighter.active[buf]
  83. return { fg = ts and not vim.tbl_isempty(ts) and colors.green or colors.red }
  84. end,
  85. cond = conditions.hide_in_width,
  86. },
  87. lsp = {
  88. function(msg)
  89. msg = msg or "LS Inactive"
  90. local buf_clients = vim.lsp.buf_get_clients()
  91. if next(buf_clients) == nil then
  92. -- TODO: clean up this if statement
  93. if type(msg) == "boolean" or #msg == 0 then
  94. return "LS Inactive"
  95. end
  96. return msg
  97. end
  98. local buf_ft = vim.bo.filetype
  99. local buf_client_names = {}
  100. -- add client
  101. for _, client in pairs(buf_clients) do
  102. if client.name ~= "null-ls" then
  103. table.insert(buf_client_names, client.name)
  104. end
  105. end
  106. -- add formatter
  107. local formatters = require "lvim.lsp.null-ls.formatters"
  108. local supported_formatters = formatters.list_registered(buf_ft)
  109. vim.list_extend(buf_client_names, supported_formatters)
  110. -- add linter
  111. local linters = require "lvim.lsp.null-ls.linters"
  112. local supported_linters = linters.list_registered(buf_ft)
  113. vim.list_extend(buf_client_names, supported_linters)
  114. local unique_client_names = vim.fn.uniq(buf_client_names)
  115. return "[" .. table.concat(unique_client_names, ", ") .. "]"
  116. end,
  117. color = { gui = "bold" },
  118. cond = conditions.hide_in_width,
  119. },
  120. location = { "location", color = location_color },
  121. progress = {
  122. "progress",
  123. fmt = function()
  124. return "%P/%L"
  125. end,
  126. color = {},
  127. },
  128. spaces = {
  129. function()
  130. if not vim.api.nvim_buf_get_option(0, "expandtab") then
  131. return "Tab size: " .. vim.api.nvim_buf_get_option(0, "tabstop") .. " "
  132. end
  133. local size = vim.api.nvim_buf_get_option(0, "shiftwidth")
  134. if size == 0 then
  135. size = vim.api.nvim_buf_get_option(0, "tabstop")
  136. end
  137. return "Spaces: " .. size .. " "
  138. end,
  139. cond = conditions.hide_in_width,
  140. color = {},
  141. },
  142. encoding = {
  143. "o:encoding",
  144. fmt = string.upper,
  145. color = {},
  146. cond = conditions.hide_in_width,
  147. },
  148. filetype = { "filetype", cond = conditions.hide_in_width, padding = { left = 1, right = 2 } },
  149. scrollbar = {
  150. function()
  151. local current_line = vim.fn.line "."
  152. local total_lines = vim.fn.line "$"
  153. local chars = { "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" }
  154. local line_ratio = current_line / total_lines
  155. local index = math.ceil(line_ratio * #chars)
  156. return chars[index]
  157. end,
  158. padding = { left = 0, right = 0 },
  159. color = "SLProgress",
  160. cond = nil,
  161. },
  162. }