1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
local status_ok, telescope = pcall(require, "telescope")
if not status_ok then
return
end
local actions = require('telescope.actions')
local action_layout = require("telescope.actions.layout")
local function telescopew()
if vim.o.columns <= 80 then
return vim.o.columns
else
return 80
end
end
telescope.setup {
defaults = {
borderchars = {
prompt = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' };
results = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' };
preview = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' };
},
preview = {
-- add image previews via chafa
mime_hook = function(filepath, bufnr, opts)
local is_image = function(filepath)
local image_extensions = { -- supported image formats
'png',
'jpg',
'jpe',
'jpeg',
'webp',
'gif',
}
local split_path = vim.split(filepath:lower(), '.', { plain=true })
local extension = split_path[#split_path]
return vim.tbl_contains(image_extensions, extension)
end
if is_image(filepath) then
local term = vim.api.nvim_open_term(bufnr, {})
local function send_output(_, data, _ )
for _, d in ipairs(data) do
vim.api.nvim_chan_send(term, d..'\r\n')
end
end
vim.fn.jobstart({
'chafa',
'-C',
'on',
'--animate',
'off',
'-s',
(telescopew() - 10)..'x25',
'--clear',
filepath
}, { on_stdout = send_output, stdout_buffered = true, pty = true })
a.nvim_set_option_value("number", false, {buf = bufnr})
else
require("telescope.previewers.utils").set_preview_message(bufnr, opts.winid, "File cannot be previewed")
end
end
},
winblend = 0,
-- 'horizontal', 'vertical', 'bottom_pane', or 'cursor'
layout_strategy = 'vertical',
sorting_strategy = 'ascending',
layout_config = {
vertical = {
width = telescopew(),
prompt_position = "top",
}
},
mappings = {
i = {
["<esc>"] = actions.close,
['<C-h>'] = 'which_key',
['<C-j>'] = actions.move_selection_next,
['<C-k>'] = actions.move_selection_previous,
['<C-l>'] = actions.select_default,
['<C-u>'] = actions.preview_scrolling_up,
['<C-d>'] = actions.preview_scrolling_down,
["<C-p>"] = action_layout.toggle_preview
},
n = {
["gg"] = actions.move_to_top,
["G"] = actions.move_to_bottom,
},
},
}
}
telescope.load_extension('file_browser')
telescope.load_extension('ui-select')
telescope.load_extension('projects')
a.nvim_create_autocmd('User', {
pattern = 'TelescopePreviewerLoaded',
callback = function()
vim.opt.winblend = 0
end,
})
|