wip: Messing around w/ ffi for some stuff
This commit is contained in:
@@ -40,6 +40,7 @@ function Finder:new(opts)
|
|||||||
local obj = setmetatable({
|
local obj = setmetatable({
|
||||||
results = opts.results,
|
results = opts.results,
|
||||||
|
|
||||||
|
entry_maker = opts.entry_maker,
|
||||||
fn_command = opts.fn_command,
|
fn_command = opts.fn_command,
|
||||||
static = opts.static,
|
static = opts.static,
|
||||||
state = {},
|
state = {},
|
||||||
@@ -95,24 +96,18 @@ function Finder:_find(prompt, process_result, process_complete)
|
|||||||
|
|
||||||
-- TODO: Should consider ways to allow "transformers" to be run here.
|
-- 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.
|
-- 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, _)
|
local on_output = function(_, line, _)
|
||||||
if not line then
|
if not line then
|
||||||
return
|
return
|
||||||
end
|
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
|
if vim.trim(line) ~= "" then
|
||||||
line = line:gsub("\n", "")
|
line = line:gsub("\n", "")
|
||||||
|
|
||||||
|
if self.entry_maker then
|
||||||
|
line = self.entry_maker(line)
|
||||||
|
end
|
||||||
|
|
||||||
process_result(line)
|
process_result(line)
|
||||||
|
|
||||||
if self.static then
|
if self.static then
|
||||||
@@ -160,7 +155,7 @@ end
|
|||||||
-- }
|
-- }
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
finders.new_oneshot_job = function(command_list)
|
finders.new_oneshot_job = function(command_list, entry_maker)
|
||||||
command_list = vim.deepcopy(command_list)
|
command_list = vim.deepcopy(command_list)
|
||||||
|
|
||||||
local command = table.remove(command_list, 1)
|
local command = table.remove(command_list, 1)
|
||||||
@@ -168,6 +163,8 @@ finders.new_oneshot_job = function(command_list)
|
|||||||
return finders.new {
|
return finders.new {
|
||||||
static = true,
|
static = true,
|
||||||
|
|
||||||
|
entry_maker = entry_maker,
|
||||||
|
|
||||||
fn_command = function()
|
fn_command = function()
|
||||||
return {
|
return {
|
||||||
command = command,
|
command = command,
|
||||||
|
|||||||
@@ -68,6 +68,12 @@ function Picker:new(opts)
|
|||||||
selection_strategy = opts.selection_strategy,
|
selection_strategy = opts.selection_strategy,
|
||||||
|
|
||||||
window = {
|
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, {}),
|
border = get_default(opts.border, {}),
|
||||||
borderchars = get_default(opts.borderchars, { '─', '│', '─', '│', '┌', '┐', '┘', '└'}),
|
borderchars = get_default(opts.borderchars, { '─', '│', '─', '│', '┌', '┐', '┘', '└'}),
|
||||||
},
|
},
|
||||||
@@ -235,7 +241,7 @@ function Picker:find()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
log.trace("Processing result... ", entry)
|
log.info("Processing result... ", entry)
|
||||||
|
|
||||||
local sort_ok, sort_score = nil, 0
|
local sort_ok, sort_score = nil, 0
|
||||||
if sorter then
|
if sorter then
|
||||||
|
|||||||
@@ -74,4 +74,37 @@ utils.new_ngram = function()
|
|||||||
return require("telescope._private.NGram"):new()
|
return require("telescope._private.NGram"):new()
|
||||||
end
|
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
|
return utils
|
||||||
|
|||||||
15
scratch/nvim_ffi.lua
Normal file
15
scratch/nvim_ffi.lua
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
local ffi = require("ffi")
|
||||||
|
-- ffi.load("/home/tj/build/neovim/build/include/eval/funcs.h.generated.h")
|
||||||
|
|
||||||
|
ffi.cdef [[
|
||||||
|
typedef unsigned char char_u;
|
||||||
|
char_u *shorten_dir(char_u *str);
|
||||||
|
]]
|
||||||
|
|
||||||
|
local text = "scratch/file.lua"
|
||||||
|
local c_str = ffi.new("char[?]", #text)
|
||||||
|
ffi.copy(c_str, text)
|
||||||
|
|
||||||
|
print(vim.inspect(ffi.string(ffi.C.shorten_dir(c_str))))
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user