diff options
| author | TJ DeVries <devries.timothyj@gmail.com> | 2020-09-12 23:15:07 -0400 |
|---|---|---|
| committer | TJ DeVries <devries.timothyj@gmail.com> | 2020-09-12 23:15:10 -0400 |
| commit | ebd090c0fe8a3f5acff0897d8724ac0f281db9d2 (patch) | |
| tree | 92ceb719c0f6a02ce55dcc2be79d58327323de3a /lua/telescope/config/resolve.lua | |
| parent | a2acd607b023ab93a611677e0a3a07331f05a28d (diff) | |
wip: some more musings on resolving height and width
Diffstat (limited to 'lua/telescope/config/resolve.lua')
| -rw-r--r-- | lua/telescope/config/resolve.lua | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/lua/telescope/config/resolve.lua b/lua/telescope/config/resolve.lua index 5aa9c84..b00d66c 100644 --- a/lua/telescope/config/resolve.lua +++ b/lua/telescope/config/resolve.lua @@ -87,21 +87,41 @@ local get_default = require('telescope.utils').get_default local resolver = {} -local percentage_resolver = function(selector, percentage) - assert(percentage <= 1) - assert(percentage >= 0) +local _resolve_map = { + -- Percentages + [function(val) return type(val) == 'number' and val > 0 and val <= 1 end] = function(selector, val) + return function(...) + return math.floor(val * select(selector, ...)) + end + end, + + -- Numbers + [function(val) return type(val) == 'number' and val > 1 end] = function(selector, val) + return function(...) + return math.min(val, select(selector, ...)) + end + end, + +} - return function(...) - return percentage * select(selector, ...) +resolver.resolve_height = function(val) + for k, v in pairs(_resolve_map) do + if k(val) then + return v(3, val) + end end -end -resolver.resolve_percentage_height = function(percentage) - return percentage_resolver(3, percentage) + error('invalid configuration option for height:' .. tostring(val)) end -resolver.resolve_percentage_width = function(percentage) - return percentage_resolver(2, percentage) +resolver.resolve_width = function(val) + for k, v in pairs(_resolve_map) do + if k(val) then + return v(2, val) + end + end + + error('invalid configuration option for height:' .. tostring(val)) end --- Win option always returns a table with preview, results, and prompt. |
