History

console.lua: use ${term-clip-cc} to clip lines

Instead of considering every non-ASCII character 2-cell wide, use this newly introduced property to let msg.c clip the select menu using all available with.

Guido Cella committed 2 years ago

Commit ba3b4ed1 parent bf025cd1 file · +5 −41Browse files

Showing the changes to player/lua/console.lua (1 of 1 file). Show all

Unified · Split

player/lua/console.lua+5−41
@@ -142,27 +142,6 @@ local function len_utf8(str) · 141 unmodified lines
142 return len142 return len
143end143end
144 144
145local function truncate_utf8(str, max_length)
146 local len = 0
147 local pos = 1
148 while pos <= #str do
149 local last_pos = pos
150 pos = next_utf8(str, pos)
151 len = len + 1
152 if pos > last_pos + 1 then
153 if len == max_length - 1 then
154 pos = last_pos
155 else
156 len = len + 1
157 end
158 end
159 if len == max_length - 1 then
160 return str:sub(1, pos - 1) .. '⋯'
161 end
162 end
163 return str
164end
165
166 145
167-- Functions to calculate the font width.146-- Functions to calculate the font width.
168local width_length_ratio = 0.5147local width_length_ratio = 0.5
@@ -371,22 +350,7 @@ local function fuzzy_find(needle, haystacks) · 202 unmodified lines
371 return result350 return result
372end351end
373 352
374local function calculate_max_terminal_width()353local function populate_log_with_matches()
375 local max_width = mp.get_property_native('term-size/w', 80)
376
377 -- The longest module name is vo/gpu-next/libplacebo.
378 if mp.get_property_native('msg-module') then
379 max_width = max_width - 24
380 end
381
382 if mp.get_property_native('msg-time') then
383 max_width = max_width - 13
384 end
385
386 return max_width
387end
388
389local function populate_log_with_matches(max_width)
390 if not selectable_items or selected_match == 0 then354 if not selectable_items or selected_match == 0 then
391 return355 return
392 end356 end
@@ -454,8 +418,7 @@ local function populate_log_with_matches(max_width) · 61 unmodified lines
454 418
455 for i = first_match_to_print, last_match_to_print do419 for i = first_match_to_print, last_match_to_print do
456 log[#log + 1] = {420 log[#log + 1] = {
457 text = (max_width and truncate_utf8(matches[i].text, max_width)421 text = matches[i].text,
458 or matches[i].text),
459 style = i == selected_match and styles.selected_suggestion or '',422 style = i == selected_match and styles.selected_suggestion or '',
460 terminal_style = i == selected_match and terminal_styles.selected_suggestion or '',423 terminal_style = i == selected_match and terminal_styles.selected_suggestion or '',
461 }424 }
@@ -478,11 +441,12 @@ local function print_to_terminal() · 16 unmodified lines
478 return441 return
479 end442 end
480 443
481 populate_log_with_matches(calculate_max_terminal_width())444 populate_log_with_matches()
482 445
483 local log = ''446 local log = ''
447 local clip = selectable_items and mp.get_property('term-clip-cc') or ''
484 for _, log_line in ipairs(log_buffers[id]) do448 for _, log_line in ipairs(log_buffers[id]) do
485 log = log .. log_line.terminal_style .. log_line.text .. '\027[0m\n'449 log = log .. clip .. log_line.terminal_style .. log_line.text .. '\027[0m\n'
486 end450 end
487 451
488 local suggestions = ''452 local suggestions = ''

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t