feat: quickfix (#293)

* feat: quickfix (not implemented)

* [WIP]: Wed 09 Dec 2020 11:11:30 PM EST

* somewhat working linked list impl

* getting closer

* might be working

* might be working for real

* works and implemented basic example

* dont forget to close prompt

* fix descending and add more tests

* test fixes

* fix test

* more logging

* Fix some more tests

* Fix logging messing up tests

* fix: lint

* fix: multi select stuffs
This commit is contained in:
TJ DeVries
2021-01-11 13:29:37 -05:00
committed by GitHub
parent de80a9837c
commit 8783bea06e
19 changed files with 1152 additions and 369 deletions

View File

@@ -1,56 +1,75 @@
local scroller = {}
local calc_count_fn = function(sorting_strategy)
if sorting_strategy == 'ascending' then
return function(a, b) return math.min(a, b) end
else
return function(a, b, row)
if a == b or not row then
return math.max(a, b)
else
local x = a - b
if row < x then
return math.max(a, b) - 1, true
elseif row == a then
return x, true
else
return math.max(a, b)
end
local range_calculators = {
ascending = function(max_results, num_results)
return 0, math.min(max_results, num_results)
end,
descending = function(max_results, num_results)
return math.max(max_results - num_results, 0), max_results
end,
}
local scroll_calculators = {
cycle = function(range_fn)
return function(max_results, num_results, row)
local start, finish = range_fn(max_results, num_results)
if row >= finish then
return start
elseif row < start then
return finish - 1
end
return row
end
end,
limit = function(range_fn)
return function(max_results, num_results, row)
local start, finish = range_fn(max_results, num_results)
if row >= finish then
return finish - 1
elseif row < start then
return start
end
return row
end
end,
}
scroller.create = function(scroll_strategy, sorting_strategy)
local range_fn = range_calculators[sorting_strategy]
if not range_fn then
error(debug.traceback("Unknown sorting strategy: " .. sorting_strategy))
end
end
scroller.create = function(strategy, sorting_strategy)
local calc_count = calc_count_fn(sorting_strategy)
local scroll_fn = scroll_calculators[scroll_strategy]
if not scroll_fn then
error(debug.traceback("Unknown scroll strategy: " .. (scroll_strategy or '')))
end
if strategy == 'cycle' then
return function(max_results, num_results, row)
local count, b = calc_count(max_results, num_results, row)
if b then return count end
local calculator = scroll_fn(range_fn)
return function(max_results, num_results, row)
local result = calculator(max_results, num_results, row)
if row >= count then
return 0
elseif row < 0 then
return count - 1
end
return row
if result < 0 then
error(string.format(
"Must never return a negative row: { result = %s, args = { %s %s %s } }",
result, max_results, num_results, row
))
end
elseif strategy == 'limit' or strategy == nil then
return function(max_results, num_results, row)
local count = calc_count(max_results, num_results)
if row >= count then
return count - 1
elseif row < 0 then
return 0
end
return row
if result >= max_results then
error(string.format(
"Must never exceed max results: { result = %s, args = { %s %s %s } }",
result, max_results, num_results, row
))
end
else
error("Unsupported strategy: " .. strategy)
return result
end
end