feat: borders and no previews for rocker
This commit is contained in:
@@ -11,13 +11,7 @@ local sorters = require('telescope.sorters')
|
|||||||
|
|
||||||
local builtin = {}
|
local builtin = {}
|
||||||
|
|
||||||
local ifnil = function(x, was_nil, was_not_nil)
|
local ifnil = function(x, was_nil, was_not_nil) if x == nil then return was_nil else return was_not_nil end end
|
||||||
if x == nil then
|
|
||||||
return was_nil
|
|
||||||
else
|
|
||||||
return was_not_nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
builtin.git_files = function(opts)
|
builtin.git_files = function(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
@@ -52,6 +46,9 @@ builtin.git_files = function(opts)
|
|||||||
prompt = 'Simple File',
|
prompt = 'Simple File',
|
||||||
finder = file_finder,
|
finder = file_finder,
|
||||||
sorter = file_sorter,
|
sorter = file_sorter,
|
||||||
|
|
||||||
|
border = opts.border,
|
||||||
|
borderchars = opts.borderchars,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -207,6 +204,36 @@ builtin.quickfix = function()
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
builtin.grep_string = function(opts)
|
||||||
|
opts = opts or {}
|
||||||
|
|
||||||
|
local search = opts.search or vim.fn.expand("<cword>")
|
||||||
|
|
||||||
|
local grepper = finders.new {
|
||||||
|
maximum_results = 10000,
|
||||||
|
|
||||||
|
-- TODO: We can optimize these.
|
||||||
|
-- static = true,
|
||||||
|
|
||||||
|
fn_command = function()
|
||||||
|
return {
|
||||||
|
command = 'rg',
|
||||||
|
args = {"--vimgrep", search},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
local file_picker = pickers.new {
|
||||||
|
previewer = previewers.vimgrep
|
||||||
|
}
|
||||||
|
|
||||||
|
file_picker:find {
|
||||||
|
prompt = 'Live Grep',
|
||||||
|
finder = grepper,
|
||||||
|
sorter = sorters.get_norcalli_sorter(),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return builtin
|
return builtin
|
||||||
|
|||||||
@@ -65,6 +65,11 @@ keymap["enter"] = function(prompt_bufnr, results_bufnr)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO: This is not great.
|
||||||
|
if type(value) == "table" then
|
||||||
|
value = entry.display
|
||||||
|
end
|
||||||
|
|
||||||
local sections = vim.split(value, ":")
|
local sections = vim.split(value, ":")
|
||||||
|
|
||||||
local filename = sections[1]
|
local filename = sections[1]
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ local Previewer = require('telescope.previewers').Previewer
|
|||||||
|
|
||||||
local pickers = {}
|
local pickers = {}
|
||||||
|
|
||||||
|
local ifnil = function(x, was_nil, was_not_nil) if x == nil then return was_nil else return was_not_nil end end
|
||||||
|
|
||||||
-- Picker takes a function (`get_window_options`) that returns the configurations required for three windows:
|
-- Picker takes a function (`get_window_options`) that returns the configurations required for three windows:
|
||||||
-- prompt
|
-- prompt
|
||||||
-- results
|
-- results
|
||||||
@@ -45,18 +47,26 @@ function Picker:new(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Picker:get_window_options(max_columns, max_lines, prompt_title, find_options)
|
function Picker:get_window_options(max_columns, max_lines, prompt_title, find_options)
|
||||||
|
|
||||||
|
local popup_border = ifnil(find_options.border, {}, find_options.border)
|
||||||
|
|
||||||
local preview = {
|
local preview = {
|
||||||
border = {},
|
border = popup_border,
|
||||||
|
borderchars = find_options.borderchars or nil,
|
||||||
enter = false,
|
enter = false,
|
||||||
highlight = false
|
highlight = false
|
||||||
}
|
}
|
||||||
|
|
||||||
local results = {
|
local results = {
|
||||||
border = {},
|
border = popup_border,
|
||||||
|
borderchars = find_options.borderchars or nil,
|
||||||
enter = false,
|
enter = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
local prompt = {
|
local prompt = {
|
||||||
title = prompt_title,
|
title = prompt_title,
|
||||||
border = {},
|
border = popup_border,
|
||||||
|
borderchars = find_options.borderchars or nil,
|
||||||
enter = true
|
enter = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,6 +131,8 @@ function Picker:find(opts)
|
|||||||
opts.preview_cutoff = 120
|
opts.preview_cutoff = 120
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.borderchars = opts.borderchars or { '─', '│', '─', '│', '┌', '┐', '┘', '└'}
|
||||||
|
|
||||||
local finder = opts.finder
|
local finder = opts.finder
|
||||||
assert(finder, "Finder is required to do picking")
|
assert(finder, "Finder is required to do picking")
|
||||||
|
|
||||||
@@ -275,16 +287,15 @@ function Picker:find(opts)
|
|||||||
state.set_status(prompt_bufnr, {
|
state.set_status(prompt_bufnr, {
|
||||||
prompt_bufnr = prompt_bufnr,
|
prompt_bufnr = prompt_bufnr,
|
||||||
prompt_win = prompt_win,
|
prompt_win = prompt_win,
|
||||||
prompt_border_win = prompt_opts.border.win_id,
|
prompt_border_win = prompt_opts.border and prompt_opts.border.win_id,
|
||||||
|
|
||||||
results_bufnr = results_bufnr,
|
results_bufnr = results_bufnr,
|
||||||
results_win = results_win,
|
results_win = results_win,
|
||||||
results_border_win = results_opts.border.win_id,
|
results_border_win = results_opts.border and results_opts.border.win_id,
|
||||||
|
|
||||||
preview_bufnr = preview_bufnr,
|
preview_bufnr = preview_bufnr,
|
||||||
preview_win = preview_win,
|
preview_win = preview_win,
|
||||||
preview_border_win = preview_opts and preview_opts.border.win_id,
|
preview_border_win = preview_opts.border and preview_opts.border.win_id,
|
||||||
|
|
||||||
picker = self,
|
picker = self,
|
||||||
previewer = self.previewer,
|
previewer = self.previewer,
|
||||||
finder = finder,
|
finder = finder,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ local previewers = {}
|
|||||||
local Previewer = {}
|
local Previewer = {}
|
||||||
Previewer.__index = Previewer
|
Previewer.__index = Previewer
|
||||||
|
|
||||||
local bat_options = "--style=grid --paging=always --wrap=never"
|
local bat_options = " --style=grid --paging=always "
|
||||||
-- --terminal-width=%s
|
-- --terminal-width=%s
|
||||||
|
|
||||||
function Previewer:new(opts)
|
function Previewer:new(opts)
|
||||||
@@ -71,7 +71,7 @@ previewers.vim_buffer_or_bat = previewers.new {
|
|||||||
|
|
||||||
local file_name = vim.split(value, ":")[1]
|
local file_name = vim.split(value, ":")[1]
|
||||||
|
|
||||||
log.info("Previewing File: %s", file_name)
|
log.trace("Previewing File: %s", file_name)
|
||||||
|
|
||||||
-- vim.fn.termopen(
|
-- vim.fn.termopen(
|
||||||
-- string.format("bat --color=always --style=grid %s"),
|
-- string.format("bat --color=always --style=grid %s"),
|
||||||
@@ -151,9 +151,11 @@ previewers.vimgrep = previewers.new {
|
|||||||
|
|
||||||
vim.api.nvim_win_set_buf(status.preview_win, bufnr)
|
vim.api.nvim_win_set_buf(status.preview_win, bufnr)
|
||||||
|
|
||||||
|
local termopen_command = string.format(self.state.command_string, filename, lnum, start, finish)
|
||||||
|
|
||||||
-- HACK! Requires `termopen` to accept buffer argument.
|
-- HACK! Requires `termopen` to accept buffer argument.
|
||||||
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.preview_win))
|
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.preview_win))
|
||||||
vim.fn.termopen(string.format(self.state.command_string, filename, lnum, start, finish))
|
vim.fn.termopen(termopen_command)
|
||||||
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.prompt_win))
|
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.prompt_win))
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -185,9 +187,11 @@ previewers.qflist = previewers.new {
|
|||||||
|
|
||||||
vim.api.nvim_win_set_buf(status.preview_win, bufnr)
|
vim.api.nvim_win_set_buf(status.preview_win, bufnr)
|
||||||
|
|
||||||
|
local termopen_command = string.format(self.state.command_string, filename, lnum, start, finish)
|
||||||
|
|
||||||
-- HACK! Requires `termopen` to accept buffer argument.
|
-- HACK! Requires `termopen` to accept buffer argument.
|
||||||
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.preview_win))
|
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.preview_win))
|
||||||
vim.fn.termopen(string.format(self.state.command_string, filename, lnum, start, finish))
|
vim.fn.termopen(termopen_command)
|
||||||
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.prompt_win))
|
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.prompt_win))
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user