components.lua 4.1 KB

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