summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2020-08-31 18:12:51 -0400
committerTJ DeVries <devries.timothyj@gmail.com>2020-08-31 18:12:51 -0400
commit8c5bf8c7467cf28da2ac5de4f2eaa966f02b2b48 (patch)
tree759150e002a4237cabea5469973323eb7d0cbe7c /lua
parente38589f265a276d431113efcef6fdb157120ce68 (diff)
wip: Messing around w/ ffi for some stuff
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/finders.lua19
-rw-r--r--lua/telescope/pickers.lua8
-rw-r--r--lua/telescope/utils.lua33
3 files changed, 48 insertions, 12 deletions
diff --git a/lua/telescope/finders.lua b/lua/telescope/finders.lua
index ae32370..b3c5022 100644
--- a/lua/telescope/finders.lua
+++ b/lua/telescope/finders.lua
@@ -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,
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua
index e75f43e..e6b3570 100644
--- a/lua/telescope/pickers.lua
+++ b/lua/telescope/pickers.lua
@@ -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
diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua
index eba24a6..2533c12 100644
--- a/lua/telescope/utils.lua
+++ b/lua/telescope/utils.lua
@@ -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