components.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. local conditions = require "core.lualine.conditions"
  2. local colors = require "core.lualine.colors"
  3. return {
  4. vi_mode = {
  5. function()
  6. return " "
  7. end,
  8. left_padding = 0,
  9. right_padding = 0,
  10. condition = conditions.hide_in_width,
  11. },
  12. branch = {
  13. "branch",
  14. icon = " ",
  15. condition = function()
  16. return conditions.hide_in_width() and conditions.check_git_workspace()
  17. end,
  18. },
  19. diff = {
  20. "diff",
  21. symbols = { added = "  ", modified = "柳", removed = " " },
  22. color_added = { fg = colors.green },
  23. color_modified = { fg = colors.yellow },
  24. color_removed = { fg = colors.red },
  25. condition = conditions.hide_in_width,
  26. },
  27. python_env = {
  28. function()
  29. local utils = require "core.lualine.utils"
  30. if vim.bo.filetype == "python" then
  31. local venv = os.getenv "CONDA_DEFAULT_ENV"
  32. if venv then
  33. return string.format("  (%s)", utils.env_cleanup(venv))
  34. end
  35. venv = os.getenv "VIRTUAL_ENV"
  36. if venv then
  37. return string.format("  (%s)", utils.env_cleanup(venv))
  38. end
  39. return ""
  40. end
  41. return ""
  42. end,
  43. color = { fg = colors.green },
  44. condition = conditions.hide_in_width,
  45. },
  46. diagnostics = {
  47. "diagnostics",
  48. sources = { "nvim_lsp" },
  49. symbols = { error = " ", warn = " ", info = " ", hint = " " },
  50. condition = conditions.hide_in_width,
  51. },
  52. treesitter = {
  53. function()
  54. if next(vim.treesitter.highlighter.active) then
  55. return "  "
  56. end
  57. return ""
  58. end,
  59. color = { fg = colors.green },
  60. condition = conditions.hide_in_width,
  61. },
  62. lsp = {
  63. function(msg)
  64. msg = msg or "LSP Inactive"
  65. local buf_clients = vim.lsp.buf_get_clients()
  66. if next(buf_clients) == nil then
  67. return msg
  68. end
  69. local buf_ft = vim.bo.filetype
  70. local buf_client_names = {}
  71. -- add client
  72. local utils = require "lsp.utils"
  73. local active_client = utils.get_active_client_by_ft(buf_ft)
  74. for _, client in pairs(buf_clients) do
  75. if client.name ~= "null-ls" then
  76. table.insert(buf_client_names, client.name)
  77. end
  78. end
  79. vim.list_extend(buf_client_names, active_client or {})
  80. -- add formatter
  81. local formatters = require "lsp.null-ls.formatters"
  82. local supported_formatters = formatters.list_supported_names(buf_ft)
  83. vim.list_extend(buf_client_names, supported_formatters)
  84. -- add linter
  85. local linters = require "lsp.null-ls.linters"
  86. local supported_linters = linters.list_supported_names(buf_ft)
  87. vim.list_extend(buf_client_names, supported_linters)
  88. return table.concat(buf_client_names, ", ")
  89. end,
  90. condition = conditions.hide_in_width,
  91. icon = " ",
  92. color = { gui = "bold" },
  93. },
  94. location = { "location", condition = conditions.hide_in_width },
  95. progress = { "progress", condition = conditions.hide_in_width },
  96. spaces = {
  97. function()
  98. local label = "Spaces: "
  99. if not vim.api.nvim_buf_get_option(0, "expandtab") then
  100. label = "Tab size: "
  101. end
  102. return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " "
  103. end,
  104. condition = conditions.hide_in_width,
  105. },
  106. encoding = {
  107. "o:encoding",
  108. upper = true,
  109. condition = conditions.hide_in_width,
  110. },
  111. filetype = { "filetype", condition = conditions.hide_in_width },
  112. scrollbar = {
  113. function()
  114. local current_line = vim.fn.line "."
  115. local total_lines = vim.fn.line "$"
  116. local chars = { "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" }
  117. local line_ratio = current_line / total_lines
  118. local index = math.ceil(line_ratio * #chars)
  119. return chars[index]
  120. end,
  121. color = { fg = colors.yellow, bg = colors.bg },
  122. left_padding = 0,
  123. right_padding = 0,
  124. },
  125. }