components.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. -- TODO: clean up this if statement
  86. if type(msg) == "boolean" or #msg == 0 then
  87. return "LS Inactive"
  88. end
  89. return msg
  90. end
  91. local buf_ft = vim.bo.filetype
  92. local buf_client_names = {}
  93. -- add client
  94. local utils = require "lsp.utils"
  95. local active_client = utils.get_active_client_by_ft(buf_ft)
  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. vim.list_extend(buf_client_names, active_client or {})
  102. -- add formatter
  103. local formatters = require "lsp.null-ls.formatters"
  104. local supported_formatters = formatters.list_supported_names(buf_ft)
  105. vim.list_extend(buf_client_names, supported_formatters)
  106. -- add linter
  107. local linters = require "lsp.null-ls.linters"
  108. local supported_linters = linters.list_supported_names(buf_ft)
  109. vim.list_extend(buf_client_names, supported_linters)
  110. return table.concat(buf_client_names, ", ")
  111. end,
  112. icon = " ",
  113. color = { gui = "bold" },
  114. condition = conditions.hide_in_width,
  115. },
  116. location = { "location", condition = conditions.hide_in_width, color = {} },
  117. progress = { "progress", condition = conditions.hide_in_width, color = {} },
  118. spaces = {
  119. function()
  120. local label = "Spaces: "
  121. if not vim.api.nvim_buf_get_option(0, "expandtab") then
  122. label = "Tab size: "
  123. end
  124. return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " "
  125. end,
  126. condition = conditions.hide_in_width,
  127. color = {},
  128. },
  129. encoding = {
  130. "o:encoding",
  131. upper = true,
  132. color = {},
  133. condition = conditions.hide_in_width,
  134. },
  135. filetype = { "filetype", condition = conditions.hide_in_width, color = {} },
  136. scrollbar = {
  137. function()
  138. local current_line = vim.fn.line "."
  139. local total_lines = vim.fn.line "$"
  140. local chars = { "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" }
  141. local line_ratio = current_line / total_lines
  142. local index = math.ceil(line_ratio * #chars)
  143. return chars[index]
  144. end,
  145. left_padding = 0,
  146. right_padding = 0,
  147. color = { fg = colors.yellow, bg = colors.bg },
  148. condition = nil,
  149. },
  150. }