Skip to content

Commit 134032e

Browse files
committed
feat: extract all icons to config
1 parent 131a107 commit 134032e

2 files changed

Lines changed: 74 additions & 40 deletions

File tree

lua/markit/config.lua

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
local M = {}
22

3+
---@class MarkitMarkIcons
4+
---@field buffer string
5+
---@field default string
6+
---@field global string
7+
---@field last_change string
8+
---@field last_insert string
9+
---@field last_jump string
10+
---@field numbered string
11+
---@field visual_end string
12+
---@field visual_start string
13+
14+
---@class MarkitIcons
15+
---@field content_separator string
16+
---@field default_bookmark string
17+
---@field error string
18+
---@field file string
19+
---@field line_separator string
20+
---@field target string
21+
---@field marks MarkitMarkIcons
22+
323
---@class MarkitBookmark
424
---@field sign string : Sign character to display (empty string to disable)
525
---@field virt_text string : Virtual text to show at end of line
626
---@field annotate boolean : Whether to prompt for annotation when setting bookmark
727

8-
---@class MarkitIcons
9-
---@field target string
10-
---@field line_separator string
11-
---@field content_separator string
12-
1328
---@class MarkitPreviewOptions
1429
---@field context_before integer : How many lines to show before marked line
1530
---@field context_after integer : How many lines to show after marked line
16-
---@field icons MarkitIcons : Table of icons
1731

18-
---@class markit.config
32+
---@class MarkitConfig
1933
---@field add_default_keybindings boolean : Whether to add comprehensive default keybindings
2034
---@field builtin_marks table : Which builtin marks to show in sign column
2135
---@field cyclic boolean : Whether movements cycle back to beginning/end of buffer
@@ -27,6 +41,8 @@ local M = {}
2741
---@field signs boolean : Whether to show signs in sign column
2842
---@field bookmarks MarkitBookmark[] : Array of bookmark group configurations
2943
---@field preview MarkitPreviewOptions : Config options for markit preview
44+
---@field icons MarkitIcons : List of icons used by Markit
45+
3046
M.config = {
3147
add_default_keybindings = true,
3248

@@ -39,23 +55,38 @@ M.config = {
3955
bookmark = 20,
4056
},
4157

42-
preview = {
43-
context_before = 10,
44-
context_after = 20,
45-
icons = {
46-
target = '',
47-
line_separator = '',
48-
content_separator = '',
49-
},
50-
},
51-
5258
cyclic = true,
5359
force_write_shada = false,
5460
refresh_interval = 150,
5561

5662
excluded_filetypes = {},
5763
excluded_buftypes = {},
5864

65+
preview = {
66+
context_before = 10,
67+
context_after = 20,
68+
},
69+
70+
icons = {
71+
content_separator = '',
72+
default_bookmark = '',
73+
error = '',
74+
file = '',
75+
line_separator = '',
76+
target = '',
77+
marks = {
78+
buffer = '',
79+
default = '',
80+
global = '',
81+
last_change = '',
82+
last_insert = '',
83+
last_jump = '',
84+
numbered = '',
85+
visual_end = '',
86+
visual_start = '',
87+
},
88+
},
89+
5990
bookmarks = {
6091
{ sign = '', virt_text = '', annotate = false },
6192
{ sign = '', virt_text = '', annotate = false },

lua/markit/picker.lua

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ local M = {}
66
---@param filepath string
77
---@return string icon, string? color
88
local function get_filetype_icon(filepath)
9+
local icons = require('markit.config').config.icons
910
if not filepath or filepath == '' then
10-
return '', nil
11+
return icons.file, nil
1112
end
1213

1314
local ext = vim.fn.fnamemodify(filepath, ':e'):lower()
@@ -21,35 +22,36 @@ local function get_filetype_icon(filepath)
2122
end
2223
end
2324

24-
return '', nil
25+
return icons.file, nil
2526
end
2627

2728
---Get mark type icon and description
2829
---@param mark string
2930
---@return string icon, string description
3031
local function get_mark_type_info(mark)
32+
local marks = require('markit.config').config.icons.marks
3133
if not mark then
32-
return '', 'Unknown'
34+
return marks.default, 'Unknown'
3335
end
3436

3537
if mark:match('[a-z]') then
36-
return '', 'Buffer Mark'
38+
return marks.buffer, 'Buffer Mark'
3739
elseif mark:match('[A-Z]') then
38-
return '', 'Global Mark'
40+
return marks.global, 'Global Mark'
3941
elseif mark:match('[0-9]') then
40-
return '', 'Numbered Mark'
42+
return marks.numbered, 'Numbered Mark'
4143
elseif mark == "'" then
42-
return '', 'Last Jump'
44+
return marks.last_jump, 'Last Jump'
4345
elseif mark == '^' then
44-
return '', 'Last Insert'
46+
return marks.last_insert, 'Last Insert'
4547
elseif mark == '.' then
46-
return '', 'Last Change'
48+
return marks.last_change, 'Last Change'
4749
elseif mark == '<' then
48-
return '', 'Visual Start'
50+
return marks.visual_start, 'Visual Start'
4951
elseif mark == '>' then
50-
return '', 'Visual End'
52+
return marks.visual_end, 'Visual End'
5153
else
52-
return '', 'Special Mark'
54+
return marks.default, 'Special Mark'
5355
end
5456
end
5557

@@ -62,7 +64,7 @@ local function get_bookmark_info(group_nr)
6264
local color = colors[group_nr + 1] or 'Default'
6365

6466
local bookmark_config = config.bookmarks[group_nr + 1]
65-
local icon = ''
67+
local icon = config.icons.default_bookmark
6668
if bookmark_config then
6769
icon = bookmark_config.sign
6870
end
@@ -102,7 +104,7 @@ end
102104
---@param mark_entry table
103105
---@return table
104106
local function marks_entry_maker(mark_entry)
105-
local icons = require('markit.config').config.preview.icons
107+
local icons = require('markit.config').config.icons
106108
local file_icon, file_color = get_filetype_icon(mark_entry.path)
107109
local mark_icon, mark_desc = get_mark_type_info(mark_entry.mark)
108110
local file_path = format_file_path(mark_entry.path, 25)
@@ -135,7 +137,7 @@ end
135137
---@param bookmark_entry table
136138
---@return table
137139
local function bookmarks_entry_maker(bookmark_entry)
138-
local icons = require('markit.config').config.preview.icons
140+
local icons = require('markit.config').config.icons
139141
local file_icon, file_color = get_filetype_icon(bookmark_entry.path)
140142
local bookmark_icon, bookmark_desc = get_bookmark_info(bookmark_entry.group)
141143
local file_path = format_file_path(bookmark_entry.path, 25)
@@ -200,19 +202,20 @@ end
200202
---@param entry table
201203
---@return string
202204
local function generate_preview(entry)
205+
local config = require('markit.config').config
206+
local icons = config.icons
203207
if not entry.path or entry.path == '' then
204-
return 'File Not Found\nThis mark/bookmark does not have an associated file.'
208+
return icons.error .. 'File Not Found\nThis mark/bookmark does not have an associated file.'
205209
end
206210

207211
local file_exists = vim.fn.filereadable(entry.path) == 1
208212
if not file_exists then
209-
return string.format(' File Not Found\nPath: %s', entry.path)
213+
return string.format('%s File Not Found\nPath: %s', icons.error, entry.path)
210214
end
211215

212-
local separator_width = 200
213-
local config = require('markit.config').config
214216
local context_after = config.preview.context_after
215217
local context_before = config.preview.context_before
218+
local content_separator = string.rep(icons.content_separator, 240)
216219

217220
local lines = {}
218221
local metadata = get_file_metadata(entry.path)
@@ -233,7 +236,7 @@ local function generate_preview(entry)
233236
local filetype = vim.filetype.match({ filename = entry.path }) or 'text'
234237

235238
table.insert(lines, string.format('# %s %s', file_icon, rel_path))
236-
table.insert(lines, string.rep('', separator_width))
239+
table.insert(lines, content_separator)
237240

238241
table.insert(
239242
lines,
@@ -270,19 +273,19 @@ local function generate_preview(entry)
270273
table.insert(lines, '')
271274

272275
table.insert(lines, string.format('Content (Lines %d-%d of %d):', start_line, end_line, total_lines))
273-
table.insert(lines, string.rep('', separator_width))
276+
table.insert(lines, content_separator)
274277
table.insert(lines, '```' .. filetype)
275278
local max_line_width = string.len(tostring(end_line))
276279
for i = start_line, end_line do
277280
local line_content = file_lines[i] or ''
278281
local is_target = (i == target_line)
279282
local line_num_str = string.format('%' .. max_line_width .. 'd', i)
280-
local prefix = is_target and '' or ''
283+
local prefix = is_target and icons.target or icons.line_separator
281284
local line_display = string.format('%s%s %s', prefix, line_num_str, line_content)
282285
table.insert(lines, line_display)
283286
end
284287
table.insert(lines, '```')
285-
table.insert(lines, string.rep('', separator_width))
288+
table.insert(lines, content_separator)
286289

287290
return table.concat(lines, '\n')
288291
end

0 commit comments

Comments
 (0)