Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lua/input/config.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
local config = {}

---@class input.width_options
---@field prefer number
---@field min_value number[]
---@field max_value number[]

---@class input.options
---@class input.config
---@field icon string
---@field default_prompt string
---@field win_options vim.wo
---@field buf_options vim.bo
---@field win_config vim.api.keyset.win_config
---@field width_options input.width_options
local config = {}

---@type input.config
local defaults = {
icon = "",
default_prompt = "Input",
Expand Down Expand Up @@ -45,11 +46,10 @@ local defaults = {
},
}

---@type input.options
local options = vim.deepcopy(defaults)

---Extend default with user's config.
---@param opts input.options
---@param opts input.config
function config.extend(opts)
if not opts or vim.tbl_isempty(opts) then
return
Expand Down
4 changes: 4 additions & 0 deletions lua/input/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
local M = {}

---@param opts? vim.ui.input.Opts
---@param on_confirm fun(input?: string)
local function input(opts, on_confirm)
opts = (opts and not vim.tbl_isempty(opts)) and opts or vim.empty_dict()

local config = require "input.config"
local utils = require "input.utils"
local win_config = config.win_config
Expand Down
15 changes: 13 additions & 2 deletions lua/input/utils.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---Thanks: https://github.com/stevearc/dressing.nvim/blob/master/lua/dressing/util.lua
local M = {}

---@param value number
---@param max_value number
---@return number
local function calculate_float(value, max_value)
if value then
local _, p = math.modf(value)
Expand All @@ -13,6 +16,11 @@ local function calculate_float(value, max_value)
return value
end

---@param value number[]
---@param max_value number
---@param aggregator fun(x: number, ...: number)
---@param limit number
---@return number
local function calculate_list(value, max_value, aggregator, limit)
local result = limit

Expand All @@ -23,6 +31,9 @@ local function calculate_list(value, max_value, aggregator, limit)
return result
end

---@param relative "cursor"|"editor"|"laststatus"|"mouse"|"tabline"|"win"
---@param winid? integer
---@return integer
local function get_max_width(relative, winid)
return relative == "editor" and vim.o.columns or vim.api.nvim_win_get_width(winid or 0)
end
Expand All @@ -48,7 +59,7 @@ local function calculate_size(current_size, size_options, total_size)
end

---Calculate width.
---@param relative "cursor"|"editor"
---@param relative "cursor"|"editor"|"laststatus"|"mouse"|"tabline"|"win"
---@param current_size number
---@param width_options input.width_options
---@return integer
Expand All @@ -57,7 +68,7 @@ function M.calculate_width(relative, current_size, width_options)
end

---Get max string width.
---@param lines table<string>
---@param lines string[]
---@return integer
function M.get_max_strwidth(lines)
local max = 0
Expand Down
Loading