From 3f9abc92d7eda77c16ef540a86764d8a499137eb Mon Sep 17 00:00:00 2001 From: siduck Date: Wed, 25 Dec 2024 12:47:51 +0530 Subject: [PATCH] feat(table): fit_w opt --- lua/volt/ui/init.lua | 1 + lua/volt/ui/table.lua | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/volt/ui/init.lua b/lua/volt/ui/init.lua index 5c4b4f5..11cb3c9 100644 --- a/lua/volt/ui/init.lua +++ b/lua/volt/ui/init.lua @@ -11,4 +11,5 @@ return { graphs = require "volt.ui.graphs", border = components.border, hpad = components.hpad, + line_w = components.line_w, } diff --git a/lua/volt/ui/table.lua b/lua/volt/ui/table.lua index 68d9727..4472f02 100644 --- a/lua/volt/ui/table.lua +++ b/lua/volt/ui/table.lua @@ -1,4 +1,5 @@ local get_column_widths = function(tb, w) + local fit_w = type(w) == "string" local maxrow = #tb[1] local sum = 0 local result = {} @@ -16,7 +17,7 @@ local get_column_widths = function(tb, w) sum = sum + maxlen end - local remaining_space = w - sum + local remaining_space = fit_w and sum or w - sum local ratio = math.floor(remaining_space / maxrow) local col_widths = vim.tbl_map(function(x) @@ -24,9 +25,11 @@ local get_column_widths = function(tb, w) return x + ratio - 2 end, result) - local last_item = col_widths[#col_widths] - -- -1 cuz last col has right border too - col_widths[#col_widths] = last_item + (w - sum) - 1 + if not fit_w then + local last_item = col_widths[#col_widths] + -- -1 cuz last col has right border too + col_widths[#col_widths] = last_item + (fit_w and sum or w - sum) - 1 + end return col_widths end