components.lua 4.2 KB

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