@@ -150,11 +150,14 @@ function ass_escape(str)
150
150
return str
151
151
end
152
152
153
- -- Takes a list of strings and a max width in characters
154
- -- returns a string containing the formatted table
155
- function format_table (list , width_max )
153
+ -- Takes a list of strings, a max width in characters and
154
+ -- optionally a max row count.
155
+ -- The result contains at least one column.
156
+ -- Rows are cut off from the top if rows_max is specified.
157
+ -- returns a string containing the formatted table and the row count
158
+ function format_table (list , width_max , rows_max )
156
159
if # list == 0 then
157
- return ' '
160
+ return ' ' , 0
158
161
end
159
162
160
163
local spaces_min = 2
@@ -198,7 +201,7 @@ function format_table(list, width_max)
198
201
for row = 1 , rows_needed do
199
202
result = result .. list [row ] .. ' \n '
200
203
end
201
- return result
204
+ return result , rows_needed
202
205
end
203
206
204
207
local spaces = math.floor ((width_max - width_total ) / (columns_needed - 1 ))
@@ -209,7 +212,9 @@ function format_table(list, width_max)
209
212
for column = 1 , columns_needed - 1 do
210
213
column_widths [column ] = column_widths [column ] + spaces
211
214
end
212
- for row = 1 , rows_needed do
215
+ -- cut off rows
216
+ local start = rows_max and math.max (1 , rows_needed - rows_max + 1 ) or 1
217
+ for row = start , rows_needed do
213
218
local row_text = ' '
214
219
for column = 1 , columns_needed do
215
220
local i = row + (column - 1 ) * rows_needed
@@ -219,7 +224,7 @@ function format_table(list, width_max)
219
224
end
220
225
result = result .. row_text .. ' \n '
221
226
end
222
- return result
227
+ return result , rows_needed
223
228
end
224
229
225
230
-- Render the REPL and console as an ASS OSD
@@ -265,26 +270,29 @@ function update()
265
270
local before_cur = ass_escape (line :sub (1 , cursor - 1 ))
266
271
local after_cur = ass_escape (line :sub (cursor ))
267
272
268
- -- Render log messages as ASS. This will render at most screeny / font_size
269
- -- messages.
273
+ -- Render log messages as ASS.
274
+ -- This will render at most screeny / font_size - 1 messages.
275
+
276
+ -- lines above the prompt
277
+ -- subtract 1.5 to account for the input line
278
+ local screeny_factor = 1 - global_margin_top - global_margin_bottom
279
+ local lines_max = math.ceil (screeny * screeny_factor / opts .font_size - 1.5 )
280
+ -- Estimate how many characters fit in one line
281
+ local width_max = math.ceil (screenx / opts .font_size * opts .font_hw_ratio )
282
+
283
+ local suggestions , rows = format_table (suggestion_buffer , width_max , lines_max )
284
+ local suggestion_ass = style .. styles .suggestion .. ass_escape (suggestions )
285
+
270
286
local log_ass = ' '
271
287
local log_messages = # log_buffer
272
- local screeny_factor = (1 - global_margin_top - global_margin_bottom )
273
- -- subtract 1.5 to account for the input line
274
- local log_max_lines = screeny * screeny_factor / opts .font_size - 1.5
275
- log_max_lines = math.ceil (log_max_lines )
288
+ local log_max_lines = math.max (0 , lines_max - rows )
276
289
if log_max_lines < log_messages then
277
290
log_messages = log_max_lines
278
291
end
279
292
for i = # log_buffer - log_messages + 1 , # log_buffer do
280
293
log_ass = log_ass .. style .. log_buffer [i ].style .. ass_escape (log_buffer [i ].text )
281
294
end
282
295
283
- -- estimate how many characters fit in a line
284
- local width_max = math.ceil (screenx / opts .font_size * opts .font_hw_ratio )
285
- local table_string = ass_escape (format_table (suggestion_buffer , width_max ))
286
- local suggestion_ass = style .. styles .suggestion .. table_string
287
-
288
296
ass :new_event ()
289
297
ass :an (1 )
290
298
ass :pos (2 , screeny - 2 - global_margin_bottom * screeny )
0 commit comments