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.
Showing the changes to player/lua/console.lua (1 of 1 file). Show all
Unified · Split
| @@ -142,27 +142,6 @@ local function len_utf8(str) · 141 unmodified lines | |||
| 142 | return len | 142 | return len |
| 143 | end | 143 | end |
| 144 | 144 | ||
| 145 | local 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 | ||
| 164 | end | ||
| 165 | |||
| 166 | 145 | ||
| 167 | -- Functions to calculate the font width. | 146 | -- Functions to calculate the font width. |
| 168 | local width_length_ratio = 0.5 | 147 | local width_length_ratio = 0.5 |
| @@ -371,22 +350,7 @@ local function fuzzy_find(needle, haystacks) · 202 unmodified lines | |||
| 371 | return result | 350 | return result |
| 372 | end | 351 | end |
| 373 | 352 | ||
| 374 | local function calculate_max_terminal_width() | 353 | local 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 | ||
| 387 | end | ||
| 388 | |||
| 389 | local function populate_log_with_matches(max_width) | ||
| 390 | if not selectable_items or selected_match == 0 then | 354 | if not selectable_items or selected_match == 0 then |
| 391 | return | 355 | return |
| 392 | end | 356 | 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 do | 419 | 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 | return | 441 | return |
| 479 | end | 442 | 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]) do | 448 | 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 | end | 450 | end |
| 487 | 451 | ||
| 488 | local suggestions = '' | 452 | local suggestions = '' |