components.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. local conditions = require "lvim.core.lualine.conditions"
  2. local colors = require "lvim.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. local statusline_hl = vim.api.nvim_get_hl_by_name("StatusLine", true)
  14. local cursorline_hl = vim.api.nvim_get_hl_by_name("CursorLine", true)
  15. local normal_hl = vim.api.nvim_get_hl_by_name("Normal", true)
  16. vim.api.nvim_set_hl(0, "SLGitIcon", { fg = "#E8AB53", bg = cursorline_hl.background })
  17. vim.api.nvim_set_hl(0, "SLBranchName", { fg = normal_hl.foreground, bg = cursorline_hl.background })
  18. vim.api.nvim_set_hl(0, "SLProgress", { fg = "#ECBE7B", bg = statusline_hl.background })
  19. local location_color = nil
  20. local branch = ""
  21. local separator = "│"
  22. if lvim.colorscheme == "tokyonight" then
  23. location_color = "SLBranchName"
  24. branch = "%#SLGitIcon#" .. "" .. "%*" .. "%#SLBranchName#"
  25. local status_ok, tnc = pcall(require, "tokyonight.colors")
  26. if status_ok then
  27. local tncolors = tnc.setup { transform = true }
  28. vim.api.nvim_set_hl(0, "SLSeparator", { fg = cursorline_hl.background, bg = tncolors.black })
  29. separator = "%#SLSeparator#" .. "│" .. "%*"
  30. end
  31. end
  32. return {
  33. mode = {
  34. function()
  35. return "  "
  36. end,
  37. padding = { left = 0, right = 0 },
  38. color = {},
  39. cond = nil,
  40. },
  41. branch = {
  42. "b:gitsigns_head",
  43. icon = branch,
  44. color = { gui = "bold" },
  45. },
  46. filename = {
  47. "filename",
  48. color = {},
  49. cond = nil,
  50. },
  51. diff = {
  52. "diff",
  53. source = diff_source,
  54. symbols = { added = " ", modified = " ", removed = " " },
  55. padding = { left = 2, right = 1 },
  56. diff_color = {
  57. added = { fg = colors.green },
  58. modified = { fg = colors.yellow },
  59. removed = { fg = colors.red },
  60. },
  61. cond = nil,
  62. },
  63. python_env = {
  64. function()
  65. local utils = require "lvim.core.lualine.utils"
  66. if vim.bo.filetype == "python" then
  67. local venv = os.getenv "CONDA_DEFAULT_ENV" or os.getenv "VIRTUAL_ENV"
  68. if venv then
  69. return string.format("  (%s)", utils.env_cleanup(venv))
  70. end
  71. end
  72. return ""
  73. end,
  74. color = { fg = colors.green },
  75. cond = conditions.hide_in_width,
  76. },
  77. diagnostics = {
  78. "diagnostics",
  79. sources = { "nvim_diagnostic" },
  80. symbols = { error = " ", warn = " ", info = " ", hint = " " },
  81. -- cond = conditions.hide_in_width,
  82. },
  83. treesitter = {
  84. function()
  85. return ""
  86. end,
  87. color = function()
  88. local buf = vim.api.nvim_get_current_buf()
  89. local ts = vim.treesitter.highlighter.active[buf]
  90. return { fg = ts and not vim.tbl_isempty(ts) and colors.green or colors.red }
  91. end,
  92. cond = conditions.hide_in_width,
  93. },
  94. lsp = {
  95. function(msg)
  96. msg = msg or "LS Inactive"
  97. local buf_clients = vim.lsp.buf_get_clients()
  98. if next(buf_clients) == nil then
  99. -- TODO: clean up this if statement
  100. if type(msg) == "boolean" or #msg == 0 then
  101. return "LS Inactive"
  102. end
  103. return msg
  104. end
  105. local buf_ft = vim.bo.filetype
  106. local buf_client_names = {}
  107. -- add client
  108. for _, client in pairs(buf_clients) do
  109. if client.name ~= "null-ls" then
  110. table.insert(buf_client_names, client.name)
  111. end
  112. end
  113. -- add formatter
  114. local formatters = require "lvim.lsp.null-ls.formatters"
  115. local supported_formatters = formatters.list_registered(buf_ft)
  116. vim.list_extend(buf_client_names, supported_formatters)
  117. -- add linter
  118. local linters = require "lvim.lsp.null-ls.linters"
  119. local supported_linters = linters.list_registered(buf_ft)
  120. vim.list_extend(buf_client_names, supported_linters)
  121. local unique_client_names = vim.fn.uniq(buf_client_names)
  122. return "[" .. table.concat(unique_client_names, ", ") .. "]"
  123. end,
  124. separator = separator,
  125. color = { gui = "bold" },
  126. cond = conditions.hide_in_width,
  127. },
  128. location = { "location", color = location_color },
  129. progress = {
  130. "progress",
  131. fmt = function()
  132. return "%P/%L"
  133. end,
  134. color = {},
  135. },
  136. spaces = {
  137. function()
  138. local shiftwidth = vim.api.nvim_buf_get_option(0, "shiftwidth")
  139. return " " .. shiftwidth
  140. end,
  141. separator = separator,
  142. padding = 1,
  143. },
  144. encoding = {
  145. "o:encoding",
  146. fmt = string.upper,
  147. color = {},
  148. cond = conditions.hide_in_width,
  149. },
  150. filetype = { "filetype", cond = nil, padding = { left = 1, right = 1 } },
  151. scrollbar = {
  152. function()
  153. local current_line = vim.fn.line "."
  154. local total_lines = vim.fn.line "$"
  155. local chars = { "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" }
  156. local line_ratio = current_line / total_lines
  157. local index = math.ceil(line_ratio * #chars)
  158. return chars[index]
  159. end,
  160. padding = { left = 0, right = 0 },
  161. color = "SLProgress",
  162. cond = nil,
  163. },
  164. }