From 8faca9f9c458c5b3b73ae3003bd587d51c6741ce Mon Sep 17 00:00:00 2001 From: Benny Powers Date: Thu, 23 Feb 2023 12:09:06 +0200 Subject: [PATCH] feat: allow term window_options to be a function following on from #185 , this allows users to calculate terminal window options like height and width dynamically --- lua/alpha/term.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lua/alpha/term.lua b/lua/alpha/term.lua index fababb4..702d292 100644 --- a/lua/alpha/term.lua +++ b/lua/alpha/term.lua @@ -3,12 +3,18 @@ local alpha = require("alpha") local M = {} function M.open_window(el) - local width = el.width - local height = el.height + local window_config = el.opts and el.opts.window_config or {} + if type(window_config) == 'function' then + window_config = window_config() + end + + local width = window_config.width or el.width + local height = window_config.height or el.height + local row = math.floor(height / 5) local col = math.floor((vim.o.columns - width) / 2) - local opts = vim.tbl_extend("keep", (el.opts and el.opts.window_config) or {}, { + local opts = vim.tbl_extend("keep", window_config, { relative = "editor", row = row, col = col,