How to render text with RGB color in statusline? #78
-
Hi, this is the following question of the issue: #77, which could be off-topic of this plugin... Now I'm trying to implement the -- file type
stl:add_item(Item({
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.api.nvim_get_option_value("filetype", { buf = ctx.bufnr })
local ok, devicons = pcall(require, "nvim-web-devicons")
if not ok then
return ft or ""
end
local icon_text, icon_color = devicons.get_icon_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)
)
if icon_text and icon_color then
return tostring(icon_text) .. " " .. ft
else
return ft or ""
end
end,
})) I don't know how to render the RGB color code to statusline: If the color of the icon text is rendered, it should looks like: I googled some questions, but they all told me to define a syntax highlighting group first... I'm not sure is it already the best solution? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Nougat has a utility function for this: local get_hl_name = require("nougat.color").get_hl_name You can use it like this: stl:add_item({
hl = { bg = "yellow" },
content = function(item, ctx)
return core.highlight(get_hl_name({ fg = "red" }, item.hl or ctx.hl)) .. "CONTENT"
end
}) Here, Also for filetype icon, I just added You can use it like this: stl:add_item({
hl = { bg = color.bg1 },
prefix = " ",
content = {
nut.buf.filetype_icon({ suffix = " " }),
nut.buf.filetype({}),
},
suffix = " ",
}) |
Beta Was this translation helpful? Give feedback.
Nougat has a utility function for this:
You can use it like this:
Here,
{ fg = "red" }
is the highlight definition you want.item.hl or ctx.hl
is the fallback highlight definition for the current context.Also for filetype icon, I just added
nut.buf.filetype_icon
: #79You can use it like this: