components.lua 4.4 KB

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