components.lua 4.2 KB

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