Comments (7)
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.
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 runstring.format
to format string, then echo the formatted string.
You can see the 'filetype' is not changed:
My LuaLs diagnostics shows there're type check errors, so I guess the 'type' and 'content' option are not accept by 'filetype' component:
from nougat.nvim.
thank you! It works great:
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.
I think I know now.
from nougat.nvim.
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.
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:
nougat.nvim/lua/nougat/nut/buf/filetype.lua
Lines 15 to 30 in 6024f75
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.
nut.buf.filetype
is actually a wrapper aroundnougat.item
.nut.buf.filetype
does not pass everything tonougat.item
, as you can see here:nougat.nvim/lua/nougat/nut/buf/filetype.lua
Lines 15 to 30 in 6024f75
content
andtype
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)
- [Wishlist] Nut for Nougat HOT 2
- Support breakpoints for responsive content
- Item Priority
- Stack trace for type mismatch HOT 4
- Use colorscheme patterns HOT 2
- Nut: LSP Server Names HOT 9
- Statusbar doesn't show on session restore. HOT 7
- :hammer_and_wrench: Show clock HOT 2
- :hammer_and_wrench: How to configure `lsp.servers` content? HOT 2
- quest: possibility to change colors for the modes and diagnostics? HOT 3
- quest: get the number of lines of a file? HOT 1
- Support vim-gitbranch/vim-gitgutter as git branch/status source HOT 5
- Color API Design: the `red` `yellow` API name seems confusing HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nougat.nvim.