aboutsummaryrefslogtreecommitdiff
path: root/plugins/nonicons.lua
diff options
context:
space:
mode:
authorGuldoman <giulio.lettieri@gmail.com>2024-02-28 23:52:50 +0100
committerGitHub <noreply@github.com>2024-02-28 23:52:50 +0100
commit189b293e70dfdd6f5cb78c1207d69c166f2c5785 (patch)
tree3699f5b90c69f6aaa3a1cfb3eb57e1d6e179366d /plugins/nonicons.lua
parent4b869e4931f1424f1302af7e0880762eacfbc1cd (diff)
downloadlite-xl-plugins-189b293e70dfdd6f5cb78c1207d69c166f2c5785.tar.gz
lite-xl-plugins-189b293e70dfdd6f5cb78c1207d69c166f2c5785.zip
Add Nonicons font as a library and make the `nonicons` plugin use it (#253)
Diffstat (limited to 'plugins/nonicons.lua')
-rw-r--r--plugins/nonicons.lua132
1 files changed, 66 insertions, 66 deletions
diff --git a/plugins/nonicons.lua b/plugins/nonicons.lua
index 9865e40..9489531 100644
--- a/plugins/nonicons.lua
+++ b/plugins/nonicons.lua
@@ -2,13 +2,14 @@
-- Author: Jipok
-- Doesn't work well with scaling mode == "ui"
-local core = require "core"
local common = require "core.common"
local config = require "core.config"
local style = require "core.style"
local TreeView = require "plugins.treeview"
local Node = require "core.node"
+local nonicons = require "libraries.font_nonicons"
+
-- Config
config.plugins.nonicons = common.merge({
use_default_dir_icons = false,
@@ -49,75 +50,74 @@ config.plugins.nonicons = common.merge({
}
}, config.plugins.nonicons)
-local icon_font = renderer.font.load(USERDIR.."/fonts/nonicons.ttf", 15 * SCALE)
-local chevron_width = icon_font:get_width("")
+local icon_font = renderer.font.load(nonicons.path, 15 * SCALE)
+local map = nonicons.utf8
+local chevron_width = icon_font:get_width(map["chevron-down-16"])
local previous_scale = SCALE
local extension_icons = {
- [".lua"] = { "#51a0cf", "" },
- [".md"] = { "#519aba", "" }, -- Markdown
- [".cpp"] = { "#519aba", "" },
- [".c"] = { "#599eff", "" },
- [".h"] = { "#599eff", "" },
- [".py"] = { "#3572A5", "" }, -- Python
- [".pyc"] = { "#519aba", "" }, [".pyd"] = { "#519aba", "" },
- [".php"] = { "#a074c4", "" },
- [".cs"] = { "#596706", "" }, -- C#
- [".conf"] = { "#6d8086", "" }, [".cfg"] = { "#6d8086", "" },
- [".toml"] = { "#6d8086", "" },
- [".yaml"] = { "#6d8086", "" }, [".yml"] = { "#6d8086", "" },
- [".json"] = { "#854CC7", "" },
- [".css"] = { "#563d7c", "" },
- [".html"] = { "#e34c26", "" },
- [".js"] = { "#cbcb41", "" }, -- JavaScript
- [".go"] = { "#519aba", "" },
- [".jpg"] = { "#a074c4", "" }, [".png"] = { "#a074c4", "" },
- [".sh"] = { "#4d5a5e", "" }, -- Shell
- [".java"] = { "#cc3e44", "" },
- [".scala"] = { "#cc3e44", "" },
- [".kt"] = { "#F88A02", "" }, -- Kotlin
- [".pl"] = { "#519aba", "" }, [".pm"] = { "#519aba", "" }, -- Perl
- [".r"] = { "#358a5b", "" },
- [".rake"] = { "#701516", "" },
- [".rb"] = { "#701516", "" }, -- Ruby
- [".rs"] = { "#dea584", "" }, -- Rust
- [".rss"] = { "#cc3e44", "" },
- [".sql"] = { "#dad8d8", "" },
- [".swift"] = { "#e37933", "" },
- [".ts"] = { "#519aba", "" }, -- TypeScript
- [".elm"] = { "#519aba", "" },
- [".diff"] = { "#41535b", "" },
- [".ex"] = { "#a074c4", "" }, [".exs"] = { "#a074c4", "" }, -- Elixir
+ [".lua"] = { "#51a0cf", "lua-16" },
+ [".md"] = { "#519aba", "markdown-16" }, -- Markdown
+ [".cpp"] = { "#519aba", "c-plusplus-16" },
+ [".c"] = { "#599eff", "c-16" },
+ [".h"] = { "#599eff", "heading-16" },
+ [".py"] = { "#3572A5", "python-16" }, -- Python
+ [".pyc"] = { "#519aba", "python-16" }, [".pyd"] = { "#519aba", "python-16" },
+ [".php"] = { "#a074c4", "php-16" },
+ [".cs"] = { "#596706", "c-sharp-16" }, -- C#
+ [".conf"] = { "#6d8086", "gear-16" }, [".cfg"] = { "#6d8086", "gear-16" },
+ [".toml"] = { "#6d8086", "toml-16" },
+ [".yaml"] = { "#6d8086", "yaml-16" }, [".yml"] = { "#6d8086", "yaml-16" },
+ [".json"] = { "#854CC7", "json-16" },
+ [".css"] = { "#563d7c", "css-16" },
+ [".html"] = { "#e34c26", "html-16" },
+ [".js"] = { "#cbcb41", "javascript-16" }, -- JavaScript
+ [".go"] = { "#519aba", "go-16" },
+ [".jpg"] = { "#a074c4", "image-16" }, [".png"] = { "#a074c4", "image-16" },
+ [".sh"] = { "#4d5a5e", "terminal-16" }, -- Shell
+ [".java"] = { "#cc3e44", "java-16" },
+ [".scala"] = { "#cc3e44", "scala-16" },
+ [".kt"] = { "#F88A02", "kotlin-16" }, -- Kotlin
+ [".pl"] = { "#519aba", "perl-16" }, [".pm"] = { "#519aba", "perl-16" }, -- Perl
+ [".r"] = { "#358a5b", "r-16" },
+ [".rake"] = { "#701516", "ruby-16" },
+ [".rb"] = { "#701516", "ruby-16" }, -- Ruby
+ [".rs"] = { "#dea584", "rust-16" }, -- Rust
+ [".rss"] = { "#cc3e44", "rss-16" },
+ [".sql"] = { "#dad8d8", "database-16" },
+ [".swift"] = { "#e37933", "swift-16" },
+ [".ts"] = { "#519aba", "typescript-16" }, -- TypeScript
+ [".elm"] = { "#519aba", "elm-16" },
+ [".diff"] = { "#41535b", "file-diff-16" },
+ [".ex"] = { "#a074c4", "elixir-16" }, [".exs"] = { "#a074c4", "elixir-16" }, -- Elixir
+ [".vim"] = { "#8f00ff", "vim-16" },
-- Following without special icon:
- [".awk"] = { "#4d5a5e", "" },
- [".nim"] = { "#F88A02", "" },
- [".zig"] = { "#cbcb41", "" },
- -- START: Adding per https://github.com/lite-xl/lite-xl-plugins/issues/144
- [".vim"] = { "#8f00ff", "" },
- [".j2"] = { "#ffff00", "" },
- [".ini"] = { "#ffffff", "" },
- [".fish"] = { "#ca2c92", "" },
- [".bash"] = { "#4169e1", "" },
- -- END: Adding per https://github.com/lite-xl/lite-xl-plugins/issues/144
+ [".awk"] = { "#4d5a5e", "code-16" },
+ [".nim"] = { "#F88A02", "code-16" },
+ [".zig"] = { "#cbcb41", "code-16" },
+ [".j2"] = { "#ffff00", "milestone-16" },
+ [".ini"] = { "#ffffff", "pencil-16" },
+ [".fish"] = { "#ca2c92", "terminal-16" },
+ [".bash"] = { "#4169e1", "terminal-16" },
}
local known_names_icons = {
- ["changelog"] = { "#657175", "" }, ["changelog.txt"] = { "#4d5a5e", "" },
- ["changelog.md"] = { "#519aba", "" },
- ["makefile"] = { "#6d8086", "" },
- ["dockerfile"] = { "#296478", "" },
- ["docker-compose.yml"] = { "#4289a1", "" },
- ["license"] = { "#d0bf41", "" },
- ["cmakelists.txt"] = { "#6d8086", "" },
- ["readme.md"] = { "#72b886", "" }, ["readme"] = { "#72b886", "" },
- ["init.lua"] = { "#2d6496", "" },
- ["setup.py"] = { "#559dd9", "" },
- ["build.zig"] = { "#6d8086", "" },
+ ["changelog"] = { "#657175", "history-16" }, ["changelog.txt"] = { "#4d5a5e", "history-16" },
+ ["changelog.md"] = { "#519aba", "history-16" },
+ ["makefile"] = { "#6d8086", "terminal-16" },
+ ["dockerfile"] = { "#296478", "docker-16" },
+ ["docker-compose.yml"] = { "#4289a1", "docker-16" },
+ ["license"] = { "#d0bf41", "file-badge-16" },
+ ["cmakelists.txt"] = { "#6d8086", "gear-16" },
+ ["readme.md"] = { "#72b886", "file-16" }, ["readme"] = { "#72b886", "file-16" },
+ ["init.lua"] = { "#2d6496", "lua-16" },
+ ["setup.py"] = { "#559dd9", "python-16" },
+ ["build.zig"] = { "#6d8086", "gear-16" },
}
-- Preparing colors
-for k, v in pairs(extension_icons) do
+for _, v in pairs(extension_icons) do
v[1] = { common.color(v[1]) }
end
-for k, v in pairs(known_names_icons) do
+for _, v in pairs(known_names_icons) do
v[1] = { common.color(v[1]) }
end
@@ -129,15 +129,15 @@ function TreeView:get_item_icon(item, active, hovered)
icon_font:set_size(
icon_font:get_size() * (SCALE / previous_scale)
)
- chevron_width = icon_font:get_width("")
+ chevron_width = icon_font:get_width(map["chevron-down-16"])
previous_scale = SCALE
end
if not config.plugins.nonicons.use_default_dir_icons then
- icon = "" -- unicode 61766
+ icon = map["file-16"] -- unicode 61766
font = icon_font
color = style.text
if item.type == "dir" then
- icon = item.expanded and "" or "" -- unicode U+F23C and U+F23B
+ icon = item.expanded and map["file-directory-open-fill-16"] or map["file-directory-fill-16"] -- unicode U+F23C and U+F23B
end
end
if config.plugins.nonicons.draw_treeview_icons then
@@ -147,7 +147,7 @@ function TreeView:get_item_icon(item, active, hovered)
end
if custom_icon ~= nil then
color = custom_icon[1]
- icon = custom_icon[2]
+ icon = map[custom_icon[2]]
font = icon_font
end
if active or hovered then
@@ -162,9 +162,9 @@ local TreeView_draw_item_chevron = TreeView.draw_item_chevron
function TreeView:draw_item_chevron(item, active, hovered, x, y, w, h)
if not config.plugins.nonicons.use_default_chevrons then
if item.type == "dir" then
- local chevron_icon = item.expanded and "" or ""
+ local chevron_icon = item.expanded and "chevron-down-16" or "chevron-right-16"
local chevron_color = hovered and style.accent or style.text
- common.draw_text(icon_font, chevron_color, chevron_icon, nil, x, y, 0, h)
+ common.draw_text(icon_font, chevron_color, map[chevron_icon], nil, x, y, 0, h)
end
return chevron_width + style.padding.x/4
end