diff options
| author | kylo252 <[email protected]> | 2021-10-10 21:07:41 +0200 | 
|---|---|---|
| committer | GitHub <[email protected]> | 2021-10-10 21:07:41 +0200 | 
| commit | 52b74557415eb757ad4b7481b0aec8a3f98dd58d (patch) | |
| tree | 9a05ec71a46c99fbdf8df0043be652b528c7c04e /lua/lvim/core/lualine/components.lua | |
| parent | e2c85df440564a62fd804555747b1652a6844a5e (diff) | |
feat: add an independent lvim namespace (#1699)
Diffstat (limited to 'lua/lvim/core/lualine/components.lua')
| -rw-r--r-- | lua/lvim/core/lualine/components.lua | 154 | 
1 files changed, 154 insertions, 0 deletions
| diff --git a/lua/lvim/core/lualine/components.lua b/lua/lvim/core/lualine/components.lua new file mode 100644 index 00000000..5c0fb84b --- /dev/null +++ b/lua/lvim/core/lualine/components.lua @@ -0,0 +1,154 @@ +local conditions = require "lvim.core.lualine.conditions" +local colors = require "lvim.core.lualine.colors" + +local function diff_source() +  local gitsigns = vim.b.gitsigns_status_dict +  if gitsigns then +    return { +      added = gitsigns.added, +      modified = gitsigns.changed, +      removed = gitsigns.removed, +    } +  end +end + +return { +  mode = { +    function() +      return " " +    end, +    padding = { left = 0, right = 0 }, +    color = {}, +    cond = nil, +  }, +  branch = { +    "b:gitsigns_head", +    icon = " ", +    color = { gui = "bold" }, +    cond = conditions.hide_in_width, +  }, +  filename = { +    "filename", +    color = {}, +    cond = nil, +  }, +  diff = { +    "diff", +    source = diff_source, +    symbols = { added = "  ", modified = "柳", removed = " " }, +    diff_color = { +      added = { fg = colors.green }, +      modified = { fg = colors.yellow }, +      removed = { fg = colors.red }, +    }, +    color = {}, +    cond = nil, +  }, +  python_env = { +    function() +      local utils = require "lvim.core.lualine.utils" +      if vim.bo.filetype == "python" then +        local venv = os.getenv "CONDA_DEFAULT_ENV" +        if venv then +          return string.format("  (%s)", utils.env_cleanup(venv)) +        end +        venv = os.getenv "VIRTUAL_ENV" +        if venv then +          return string.format("  (%s)", utils.env_cleanup(venv)) +        end +        return "" +      end +      return "" +    end, +    color = { fg = colors.green }, +    cond = conditions.hide_in_width, +  }, +  diagnostics = { +    "diagnostics", +    sources = { "nvim_lsp" }, +    symbols = { error = " ", warn = " ", info = " ", hint = " " }, +    color = {}, +    cond = conditions.hide_in_width, +  }, +  treesitter = { +    function() +      local b = vim.api.nvim_get_current_buf() +      if next(vim.treesitter.highlighter.active[b]) then +        return "  " +      end +      return "" +    end, +    color = { fg = colors.green }, +    cond = conditions.hide_in_width, +  }, +  lsp = { +    function(msg) +      msg = msg or "LS Inactive" +      local buf_clients = vim.lsp.buf_get_clients() +      if next(buf_clients) == nil then +        -- TODO: clean up this if statement +        if type(msg) == "boolean" or #msg == 0 then +          return "LS Inactive" +        end +        return msg +      end +      local buf_ft = vim.bo.filetype +      local buf_client_names = {} + +      -- add client +      for _, client in pairs(buf_clients) do +        if client.name ~= "null-ls" then +          table.insert(buf_client_names, client.name) +        end +      end + +      -- add formatter +      local formatters = require "lvim.lsp.null-ls.formatters" +      local supported_formatters = formatters.list_supported_names(buf_ft) +      vim.list_extend(buf_client_names, supported_formatters) + +      -- add linter +      local linters = require "lvim.lsp.null-ls.linters" +      local supported_linters = linters.list_supported_names(buf_ft) +      vim.list_extend(buf_client_names, supported_linters) + +      return table.concat(buf_client_names, ", ") +    end, +    icon = " ", +    color = { gui = "bold" }, +    cond = conditions.hide_in_width, +  }, +  location = { "location", cond = conditions.hide_in_width, color = {} }, +  progress = { "progress", cond = conditions.hide_in_width, color = {} }, +  spaces = { +    function() +      local label = "Spaces: " +      if not vim.api.nvim_buf_get_option(0, "expandtab") then +        label = "Tab size: " +      end +      return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " +    end, +    cond = conditions.hide_in_width, +    color = {}, +  }, +  encoding = { +    "o:encoding", +    fmt = string.upper, +    color = {}, +    cond = conditions.hide_in_width, +  }, +  filetype = { "filetype", cond = conditions.hide_in_width, color = {} }, +  scrollbar = { +    function() +      local current_line = vim.fn.line "." +      local total_lines = vim.fn.line "$" +      local chars = { "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" } +      local line_ratio = current_line / total_lines +      local index = math.ceil(line_ratio * #chars) +      return chars[index] +    end, +    padding = { left = 0, right = 0 }, +    color = { fg = colors.yellow, bg = colors.bg }, +    cond = nil, +  }, +} | 
