Skip to content

Commit ac70597

Browse files
authored
[Fix] correctly expand root in themes_folders and font_folders (#175)
* fix: correctly expand root in config folders * small readme fix
1 parent 31b5dbc commit ac70597

4 files changed

Lines changed: 50 additions & 16 deletions

File tree

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -275,31 +275,31 @@ Above code will generate a solid white background.
275275
CodeSnap.nvim use gradient background by default, you can specify the gradient colors by setting `background.stops` to a table of colors, for example:
276276

277277
```lua
278-
"background": {
279-
"start": {
280-
"x": 0,
281-
"y": 0
278+
background = {
279+
start = {
280+
x = 0,
281+
y = 0
282282
},
283-
"end": {
284-
"x": "max",
285-
"y": "max"
283+
end = {
284+
x = "max",
285+
y = "max"
286286
},
287-
"stops": [
287+
stops = [
288288
{
289-
"position": 0,
290-
"color": "#EBECB2"
289+
position = 0,
290+
color = "#EBECB2"
291291
},
292292
{
293-
"position": 0.28,
294-
"color": "#F3B0F7"
293+
position = 0.28,
294+
color = "#F3B0F7"
295295
},
296296
{
297-
"position": 0.73,
298-
"color": "#92B5F0"
297+
position = 0.73,
298+
color = "#92B5F0"
299299
},
300300
{
301-
"position": 0.94,
302-
"color": "#AEF0F8"
301+
position = 0.94,
302+
color = "#AEF0F8"
303303
}
304304
]
305305
}

lua/codesnap/init.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local table_utils = require("codesnap.utils.table")
33
local module = require("codesnap.module")
44
local config_module = require("codesnap.config")
55
local modal = require("codesnap.modal")
6+
local path = require("codesnap.path")
67

78
-- Prepare the path of the Rust module
89
-- Try to fetch pre-built library first, then fallback to development build
@@ -15,6 +16,9 @@ local main = {
1516

1617
function main.setup(config)
1718
static.config = table_utils.merge_config(static.config, config == nil and {} or config)
19+
if static.config.snapshot_config then
20+
path.expand_paths_in_config(static.config.snapshot_config)
21+
end
1822
end
1923

2024
-- Save snapshot to specified save_path

lua/codesnap/path.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
local path_module = {}
2+
3+
local function expand_path(path)
4+
if type(path) ~= "string" then
5+
return path
6+
end
7+
if path:sub(1, 1) == "~" then
8+
local home = os.getenv("HOME") or os.getenv("USERPROFILE") or ""
9+
return home .. path:sub(2)
10+
end
11+
return path
12+
end
13+
14+
function path_module.expand_paths_in_config(config)
15+
if config.themes_folders and #config.themes_folders > 0 then
16+
config.themes_folders = vim.tbl_map(expand_path, config.themes_folders)
17+
end
18+
19+
if config.fonts_folders and #config.fonts_folders > 0 then
20+
config.fonts_folders = vim.tbl_map(expand_path, config.fonts_folders)
21+
end
22+
return config
23+
end
24+
25+
return path_module

lua/codesnap/utils/table.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ function table_utils.merge_config(t1, t2)
3535
t1[k] = t2[k]
3636
end
3737
end
38+
for k, v in pairs(t2) do
39+
if t1[k] == nil and v ~= nil then
40+
t1[k] = v
41+
end
42+
end
3843

3944
return t1
4045
end

0 commit comments

Comments
 (0)