Code Monkey home page Code Monkey logo

Comments (7)

MunifTanjim avatar MunifTanjim commented on June 15, 2024 2

Example usage for the newly added filetype_icon:

local nut = {
  buf = {
    filetype = require("nougat.nut.buf.filetype").create,
    filetype_icon = require("nougat.nut.buf.filetype_icon").create,
  },
}

stl:add_item({
  hl = { bg = color.bg1 },
  prefix = " ",
  content = {
    nut.buf.filetype_icon({ suffix = " " }),
    nut.buf.filetype({}),
  },
  suffix = " ",
})

from nougat.nvim.

linrongbin16 avatar linrongbin16 commented on June 15, 2024 1

Hey @linrongbin16 , I think this is worth having in the built-in filetype component.

Not sure why you closed the issue... Did you think of any alternatives? 🤔

I read the item.content here: https://github.com/MunifTanjim/nougat.nvim/tree/main/lua/nougat/item#content, and item.type here: https://github.com/MunifTanjim/nougat.nvim/tree/main/lua/nougat/item#type.

I think if I set type to 'lua_expr' and content to be a lua function, so I can render the icon in the lua function?

I didn't test it yet.

And I think yes it's worth to provide filetype icon as a builtin feature.


update-1:

I think I failed to customize the 'type' and 'content' option in 'item'.

I configured the 'filetype' with:

-- file type
stl:add_item(nut.buf.filetype({
    hl = { bg = color.bg1 },
    sep_left = sep.left_lower_triangle_solid(true),
    prefix = " ",
    suffix = " ",
    type = "lua_expr",
    content = function(ctx)
        message.info("|nougat.filetype| ctx:%s", vim.inspect(ctx))
        local ft = vim.bo.filetype
        local ok, devicons = pcall(require, "nvim-web-devicons")
        if not ok then
            return ft or ""
        end
        local icon_text, icon_color =
            devicons.get_icon_cterm_color_by_filetype(ft)
        message.info(
            "|nougat.filetype| ctx:%s, icon_text:%s, icon_color:%s",
            vim.inspect(ctx),
            vim.inspect(icon_text),
            vim.inspect(icon_color)
        )
        return icon_text .. " " .. ft
    end,
}))

Note: the message.info is a builtin function in my nvim config, just think it's a helper that first run string.format to format string, then echo the formatted string.

You can see the 'filetype' is not changed:

image

My LuaLs diagnostics shows there're type check errors, so I guess the 'type' and 'content' option are not accept by 'filetype' component:

image

from nougat.nvim.

linrongbin16 avatar linrongbin16 commented on June 15, 2024 1

thank you! It works great:

image

I'm configure it with:

-- file type
stl:add_item(Item({
    hl = { bg = color.bg1 },
    sep_left = sep.left_lower_triangle_solid(true),
    prefix = " ",
    suffix = " ",
    content = {
        nut.buf.filetype_icon({ suffix = " " }),
        nut.buf.filetype({}),
    },
}))

from nougat.nvim.

linrongbin16 avatar linrongbin16 commented on June 15, 2024

I think I know now.

from nougat.nvim.

MunifTanjim avatar MunifTanjim commented on June 15, 2024

Hey @linrongbin16 , I think this is worth having in the built-in filetype component.

Not sure why you closed the issue... Did you think of any alternatives? 🤔

from nougat.nvim.

MunifTanjim avatar MunifTanjim commented on June 15, 2024

nut.buf.filetype is actually a wrapper around nougat.item. nut.buf.filetype does not pass everything to nougat.item, as you can see here:

function mod.create(config)
return Item({
priority = config.priority,
type = "vim_expr",
is_vimscript = true,
hidden = config.hidden,
hl = config.hl,
sep_left = config.sep_left,
prefix = config.prefix,
content = "&filetype",
suffix = config.suffix,
sep_right = config.sep_right,
on_click = config.on_click,
context = config.context,
})
end

content and type is always hardcoded.


My LuaLs diagnostics shows there're type check errors, so I guess the 'type' and 'content' option are not accept by 'filetype' component:

Yep, that's right. The built-in nut.buf.filetype component is not very configurable right now.


What you want to do is this:

local Item = require("nougat.item")

stl:add_item(Item({
    hl = { bg = color.bg1 },
    sep_left = sep.left_lower_triangle_solid(true),
    prefix = " ",
    suffix = " ",
    content = function(_, ctx)
        message.info("|nougat.filetype| ctx:%s", vim.inspect(ctx))
        local ft = vim.bo.filetype
        local ok, devicons = pcall(require, "nvim-web-devicons")
        if not ok then
            return ft or ""
        end
        local icon_text, icon_color =
            devicons.get_icon_cterm_color_by_filetype(ft)
        message.info(
            "|nougat.filetype| ctx:%s, icon_text:%s, icon_color:%s",
            vim.inspect(ctx),
            vim.inspect(icon_text),
            vim.inspect(icon_color)
        )
        return icon_text .. " " .. ft
    end,
}))

from nougat.nvim.

linrongbin16 avatar linrongbin16 commented on June 15, 2024

nut.buf.filetype is actually a wrapper around nougat.item. nut.buf.filetype does not pass everything to nougat.item, as you can see here:

function mod.create(config)
return Item({
priority = config.priority,
type = "vim_expr",
is_vimscript = true,
hidden = config.hidden,
hl = config.hl,
sep_left = config.sep_left,
prefix = config.prefix,
content = "&filetype",
suffix = config.suffix,
sep_right = config.sep_right,
on_click = config.on_click,
context = config.context,
})
end

content and type is always hardcoded.

My LuaLs diagnostics shows there're type check errors, so I guess the 'type' and 'content' option are not accept by 'filetype' component:

Yep, that's right. The built-in nut.buf.filetype component is not very configurable right now.

What you want to do is this:

local Item = require("nougat.item")

stl:add_item(Item({
    hl = { bg = color.bg1 },
    sep_left = sep.left_lower_triangle_solid(true),
    prefix = " ",
    suffix = " ",
    content = function(_, ctx)
        message.info("|nougat.filetype| ctx:%s", vim.inspect(ctx))
        local ft = vim.bo.filetype
        local ok, devicons = pcall(require, "nvim-web-devicons")
        if not ok then
            return ft or ""
        end
        local icon_text, icon_color =
            devicons.get_icon_cterm_color_by_filetype(ft)
        message.info(
            "|nougat.filetype| ctx:%s, icon_text:%s, icon_color:%s",
            vim.inspect(ctx),
            vim.inspect(icon_text),
            vim.inspect(icon_color)
        )
        return icon_text .. " " .. ft
    end,
}))

thank, will try later!

from nougat.nvim.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.