components.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. local conditions = require "core.lualine.conditions"
  2. local colors = require "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. left_padding = 0,
  19. right_padding = 0,
  20. color = {},
  21. condition = nil,
  22. },
  23. branch = {
  24. "b:gitsigns_head",
  25. icon = " ",
  26. color = { gui = "bold" },
  27. condition = conditions.hide_in_width,
  28. },
  29. filename = {
  30. "filename",
  31. color = {},
  32. condition = nil,
  33. },
  34. diff = {
  35. "diff",
  36. source = diff_source,
  37. symbols = { added = "  ", modified = "柳", removed = " " },
  38. color_added = { fg = colors.green },
  39. color_modified = { fg = colors.yellow },
  40. color_removed = { fg = colors.red },
  41. color = {},
  42. condition = nil,
  43. },
  44. python_env = {
  45. function()
  46. local utils = require "core.lualine.utils"
  47. if vim.bo.filetype == "python" then
  48. local venv = os.getenv "CONDA_DEFAULT_ENV"
  49. if venv then
  50. return string.format("  (%s)", utils.env_cleanup(venv))
  51. end
  52. venv = os.getenv "VIRTUAL_ENV"
  53. if venv then
  54. return string.format("  (%s)", utils.env_cleanup(venv))
  55. end
  56. return ""
  57. end
  58. return ""
  59. end,
  60. color = { fg = colors.green },
  61. condition = conditions.hide_in_width,
  62. },
  63. diagnostics = {
  64. "diagnostics",
  65. sources = { "nvim_lsp" },
  66. symbols = { error = " ", warn = " ", info = " ", hint = " " },
  67. color = {},
  68. condition = conditions.hide_in_width,
  69. },
  70. treesitter = {
  71. function()
  72. if next(vim.treesitter.highlighter.active) then
  73. return "  "
  74. end
  75. return ""
  76. end,
  77. color = { fg = colors.green },
  78. condition = conditions.hide_in_width,
  79. },
  80. lsp = {
  81. function(msg)
  82. msg = msg or "LS Inactive"
  83. local buf_clients = vim.lsp.buf_get_clients()
  84. if next(buf_clients) == nil then
  85. if #msg == 0 then
  86. return "LS Inactive"
  87. end
  88. return msg
  89. end
  90. local buf_ft = vim.bo.filetype
  91. local buf_client_names = {}
  92. -- add client
  93. local utils = require "lsp.utils"
  94. local active_client = utils.get_active_client_by_ft(buf_ft)
  95. for _, client in pairs(buf_clients) do
  96. if client.name ~= "null-ls" then
  97. table.insert(buf_client_names, client.name)
  98. end
  99. end
  100. vim.list_extend(buf_client_names, active_client or {})
  101. -- add formatter
  102. local formatters = require "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 "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. condition = conditions.hide_in_width,
  114. },
  115. location = { "location", condition = conditions.hide_in_width, color = {} },
  116. progress = { "progress", condition = 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. condition = conditions.hide_in_width,
  126. color = {},
  127. },
  128. encoding = {
  129. "o:encoding",
  130. upper = true,
  131. color = {},
  132. condition = conditions.hide_in_width,
  133. },
  134. filetype = { "filetype", condition = 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. left_padding = 0,
  145. right_padding = 0,
  146. color = { fg = colors.yellow, bg = colors.bg },
  147. condition = nil,
  148. },
  149. }