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
142142 return len
143143 end
144144
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−
166145
167146 -- Functions to calculate the font width.
168147 local width_length_ratio = 0.5
@@ -371,22 +350,7 @@ local function fuzzy_find(needle, haystacks) · 202 unmodified lines
371350 return result
372351 end
373352
374−local function calculate_max_terminal_width()
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)
353+local function populate_log_with_matches()
390354 if not selectable_items or selected_match == 0 then
391355 return
392356 end
@@ -454,8 +418,7 @@ local function populate_log_with_matches(max_width) · 61 unmodified lines
454418
455419 for i = first_match_to_print, last_match_to_print do
456420 log[#log + 1] = {
457− text = (max_width and truncate_utf8(matches[i].text, max_width)
458− or matches[i].text),
421+ text = matches[i].text,
459422 style = i == selected_match and styles.selected_suggestion or '',
460423 terminal_style = i == selected_match and terminal_styles.selected_suggestion or '',
461424 }
@@ -478,11 +441,12 @@ local function print_to_terminal() · 16 unmodified lines
478441 return
479442 end
480443
481− populate_log_with_matches(calculate_max_terminal_width())
444+ populate_log_with_matches()
482445
483446 local log = ''
447+ local clip = selectable_items and mp.get_property('term-clip-cc') or ''
484448 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'
486450 end
487451
488452 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