nvim-lualine / lualine.nvim

A blazing fast and easy to configure neovim statusline plugin written in pure lua.
MIT License
6.22k stars 468 forks source link

Feat: Component's icon accept function #1099

Open emxxjnm opened 1 year ago

emxxjnm commented 1 year ago

Requested feature

The component's icon accepts a function.

Motivation

python_env = {
  function()
    if vim.bo.filetype == "python" then
      local venv = vim.env.VIRTUAL_ENV
      if venv then
        local venv_name = fn.fnamemodify(venv, ":t")
        return string.format("(%s)", venv_name)
      end
    end
    return ""
  end,
  icon = function()
    local devicons = require("nvim-web-devicons")
    local icon, color = devicons.get_icon_color_by_filetype("python")
    return { icon, color = { fg = color } }
  end,
},
NGPONG commented 3 months ago

You can try this

  os = {
    function()
      return Tools.get_os()
    end,
    icon = setmetatable({}, {
      __index = function(_, k)
        local os = Tools.get_os()

        if k == 1 then
          return WBIcons.get_icons_by_operating_system()[os].icon
        elseif k == 'color' then
          return { fg = WBIcons.get_icons_by_operating_system()[os].color }
        end
      end
    }),
  },