6 + transcript_share =
0.4,
8 + transcript_max =
100,
10 + stacked_share =
0.45,
12 + prompt_share =
0.15,
17 +local settings = function()
18 + local chosen
= vim.g.pivi_layout
19 + if type( chosen )
~= 'table' then return DEFAULTS
end 20 + return vim.tbl_extend(
'force', DEFAULTS, chosen )
23 +local clamp = function( value, low, high )
24 + return math.
max( low,
math.
min( high, value ) )
32 +local plan = function( columns, lines, chosen )
33 + chosen
= chosen
or settings()
35 + local wanted
= clamp(
36 + math.
floor( columns
* chosen.transcript_share
+ 0.5 ),
37 + chosen.transcript_min,
38 + chosen.transcript_max
41 + local prompt
= clamp(
42 + math.
floor( lines
* chosen.prompt_share
+ 0.5 ),
44 + math.
min( chosen.prompt_max,
math.
max( chosen.prompt_min, lines
- 4 ) )
48 + if columns
- wanted
- 1 >= chosen.source_min
then 49 + return {
orientation =
'beside',
width = wanted,
prompt = prompt, }
52 + local height
= clamp(
53 + math.
floor( lines
* chosen.stacked_share
+ 0.5 ),
54 + math.
min( chosen.stacked_min,
math.
max(
1, lines
- 4 ) ),
55 + math.
max(
1, lines
- 4 )
58 + return {
orientation =
'below',
height = height,
prompt = prompt, }
61 +local current = function()
62 + return plan( vim.o.columns, vim.o.lines )
65 +local size = function( win, chosen )
66 + if not vim.api.nvim_win_is_valid( win )
then return end 67 + if chosen.orientation
== 'beside' then 68 + pcall( vim.api.nvim_win_set_width, win, chosen.width )
69 + vim.wo[win].winfixwidth
= true 71 + pcall( vim.api.nvim_win_set_height, win, chosen.height )
72 + vim.wo[win].winfixheight
= true 76 +local owned = function( win )
77 + if not vim.api.nvim_win_is_valid( win )
then return false end 78 + local filetype
= vim.bo[vim.api.nvim_win_get_buf( win )].filetype
79 + return filetype
== 'pivi' or filetype
== 'pivi-input' 85 +local host = function()
86 + local win
= vim.api.nvim_get_current_win()
87 + if not owned( win )
then return win
end 89 + local widest, area
= nil,
-1 90 + for _, candidate
in ipairs( vim.api.nvim_tabpage_list_wins(
0 ) )
do 91 + if not owned( candidate )
and vim.api.nvim_win_get_config( candidate ).relative
== '' then 92 + local measure
= vim.api.nvim_win_get_width( candidate )
* vim.api.nvim_win_get_height( candidate )
93 + if measure
> area
then widest, area
= candidate, measure
end 96 + return widest
or win
102 +local open = function( bufnr )
103 + if not vim.api.nvim_buf_is_valid( bufnr )
then return nil end 105 + local working
= vim.api.nvim_get_current_win()
106 + local chosen
= current()
107 + local into
= host()
110 + local opened
= pcall( vim.api.nvim_win_call, into,
function()
111 + vim.cmd( chosen.orientation
== 'beside' and 'vsplit' or 'split' )
112 + win
= vim.api.nvim_get_current_win()
114 + if not opened
or not win
or not vim.api.nvim_win_is_valid( win )
then return nil end 116 + vim.api.nvim_win_set_buf( win, bufnr )
117 + size( win, chosen )
119 + if vim.api.nvim_win_is_valid( working )
then 120 + vim.api.nvim_set_current_win( working )
128 +local open_prompt = function( bufnr, beside )
129 + if not vim.api.nvim_buf_is_valid( bufnr )
then return nil end 131 + local chosen
= current()
133 + local into
= beside
and vim.api.nvim_win_is_valid( beside )
and beside
or host()
136 + local opened
= pcall( vim.api.nvim_win_call, into,
function()
138 + win
= vim.api.nvim_get_current_win()
141 + if not opened
or not win
or not vim.api.nvim_win_is_valid( win )
then return nil end 143 + vim.api.nvim_win_set_buf( win, bufnr )
144 + pcall( vim.api.nvim_win_set_height, win, chosen.prompt )
145 + vim.wo[win].winfixheight
= true 146 + vim.api.nvim_set_current_win( win )
150 +local windows = function()
151 + local found
= {
transcript = {},
prompt = {}, }
152 + for _, win
in ipairs( vim.api.nvim_list_wins() )
do 153 + local bufnr
= vim.api.nvim_win_get_buf( win )
154 + local filetype
= vim.bo[bufnr].filetype
155 + if filetype
== 'pivi' then 156 + table.
insert( found.transcript, win )
157 + elseif filetype
== 'pivi-input' then 158 + table.
insert( found.prompt, win )
165 +local apply = function()
166 + local chosen
= current()
167 + local found
= windows()
169 + for _, win
in ipairs( found.transcript )
do 170 + size( win, chosen )
172 + for _, win
in ipairs( found.prompt )
do 173 + pcall( vim.api.nvim_win_set_height, win, chosen.prompt )
178 + defaults = DEFAULTS,
179 + settings = settings,
184 + open_prompt = open_prompt,