wip: Messing around w/ ffi for some stuff

This commit is contained in:
TJ DeVries
2020-08-31 18:12:51 -04:00
parent e38589f265
commit 8c5bf8c746
4 changed files with 63 additions and 12 deletions

View File

@@ -40,6 +40,7 @@ function Finder:new(opts)
local obj = setmetatable({
results = opts.results,
entry_maker = opts.entry_maker,
fn_command = opts.fn_command,
static = opts.static,
state = {},
@@ -95,24 +96,18 @@ function Finder:_find(prompt, process_result, process_complete)
-- TODO: Should consider ways to allow "transformers" to be run here.
-- So that a finder can choose to "transform" the text into something much more easily usable.
local entries_processed = 0
local on_output = function(_, line, _)
if not line then
return
end
if maximum_results then
entries_processed = entries_processed + 1
if entries_processed > maximum_results then
log.info("Shutting down job early...")
self.job:shutdown()
end
end
if vim.trim(line) ~= "" then
line = line:gsub("\n", "")
if self.entry_maker then
line = self.entry_maker(line)
end
process_result(line)
if self.static then
@@ -160,7 +155,7 @@ end
-- }
-- end
finders.new_oneshot_job = function(command_list)
finders.new_oneshot_job = function(command_list, entry_maker)
command_list = vim.deepcopy(command_list)
local command = table.remove(command_list, 1)
@@ -168,6 +163,8 @@ finders.new_oneshot_job = function(command_list)
return finders.new {
static = true,
entry_maker = entry_maker,
fn_command = function()
return {
command = command,

View File

@@ -68,6 +68,12 @@ function Picker:new(opts)
selection_strategy = opts.selection_strategy,
window = {
-- TODO: This won't account for different layouts...
height = get_default(opts.height, 0.8),
preview_width = get_default(opts.preview_width, 0.8),
results_width = get_default(opts.results_width, 0.8),
-- Border config
border = get_default(opts.border, {}),
borderchars = get_default(opts.borderchars, { '', '', '', '', '', '', '', ''}),
},
@@ -235,7 +241,7 @@ function Picker:find()
return
end
log.trace("Processing result... ", entry)
log.info("Processing result... ", entry)
local sort_ok, sort_score = nil, 0
if sorter then

View File

@@ -74,4 +74,37 @@ utils.new_ngram = function()
return require("telescope._private.NGram"):new()
end
-- TODO: Figure out how to do this... could include in plenary :)
-- NOTE: Don't use this yet. It will segfault sometimes.
--
-- opts.shorten_path and function(value)
-- local result = {
-- valid = true,
-- display = utils.path_shorten(value),
-- ordinal = value,
-- value = value
-- }
-- return result
-- end or nil)
utils.path_shorten = (function()
if jit then
local ffi = require('ffi')
ffi.cdef [[
typedef unsigned char char_u;
char_u *shorten_dir(char_u *str);
]]
return function(path)
local c_str = ffi.new("char[?]", #path)
ffi.copy(c_str, path)
return ffi.string(ffi.C.shorten_dir(c_str))
end
else
return function(path)
return path
end
end
end)()
return utils