History

console.lua: fix highlighting the selected item with --msg-module

With --msg-module the select menu also highlights the "statusline" on the next line. Fix this by resetting the color before \n instead of after it. This requires changing all log code to not preemptively add a newline, which is actually simpler, though we have to modify the messages received with log-message which already contain a newline.

Guido Cella committed 2 years ago

Commit b98d4fd1 parent b4408211 file · +12 −11Browse files

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

Unified · Split

player/lua/console.lua+12−11
@@ -428,7 +428,7 @@ local function populate_log_with_matches(max_width) · 427 unmodified lines
428428
429429 if first_match_to_print > 1 then
430430 log[1] = {
431− text = '↑ (' .. (first_match_to_print - 1) .. ' hidden items)' .. '\n',
431+ text = '↑ (' .. (first_match_to_print - 1) .. ' hidden items)',
432432 style = styles.disabled,
433433 terminal_style = terminal_styles.disabled,
434434 }
@@ -437,7 +437,7 @@ local function populate_log_with_matches(max_width) · 2 unmodified lines
437437 for i = first_match_to_print, last_match_to_print do
438438 log[#log + 1] = {
439439 text = (max_width and truncate_utf8(matches[i].text, max_width)
440− or matches[i].text) .. '\n',
440+ or matches[i].text),
441441 style = i == selected_match and styles.selected_suggestion or '',
442442 terminal_style = i == selected_match and terminal_styles.selected_suggestion or '',
443443 }
@@ -445,7 +445,7 @@ local function populate_log_with_matches(max_width) · 1 unmodified line
445445
446446 if last_match_to_print < #matches then
447447 log[#log + 1] = {
448− text = '↓ (' .. (#matches - last_match_to_print) .. ' hidden items)' .. '\n',
448+ text = '↓ (' .. (#matches - last_match_to_print) .. ' hidden items)',
449449 style = styles.disabled,
450450 terminal_style = terminal_styles.disabled,
451451 }
@@ -463,7 +463,7 @@ local function print_to_terminal() · 11 unmodified lines
463463
464464 local log = ''
465465 for _, log_line in ipairs(log_buffers[id]) do
466− log = log .. log_line.terminal_style .. log_line.text .. '\027[0m'
466+ log = log .. log_line.terminal_style .. log_line.text .. '\027[0m\n'
467467 end
468468
469469 local suggestions = ''
@@ -563,7 +563,8 @@ local function update() · 93 unmodified lines
563563 log_messages = log_max_lines
564564 end
565565 for i = #log_buffer - log_messages + 1, #log_buffer do
566− log_ass = log_ass .. style .. log_buffer[i].style .. ass_escape(log_buffer[i].text)
566+ log_ass = log_ass .. style .. log_buffer[i].style ..
567+ ass_escape(log_buffer[i].text) .. '\\N'
567568 end
568569
569570 ass:new_event()
@@ -745,7 +746,7 @@ local function help_command(param) · 175 unmodified lines
745746 end
746747 end
747748 if not cmd then
748− log_add('No command matches "' .. param .. '"!\n', styles.error,
749+ log_add('No command matches "' .. param .. '"!', styles.error,
749750 terminal_styles.error)
750751 return
751752 end
@@ -761,7 +762,7 @@ local function help_command(param) · 9 unmodified lines
761762 output = output .. 'This command supports variable arguments.\n'
762763 end
763764 end
764− log_add(output)
765+ log_add(output:sub(1, -2))
765766 end
766767
767768 -- Run the current command and clear the line (Enter)
@@ -1738,7 +1739,7 @@ mp.register_script_message('log', function (message) · 970 unmodified lines
17381739
17391740 message = utils.parse_json(message)
17401741
1741− log_add(message.text .. '\n',
1742+ log_add(message.text,
17421743 message.error and styles.error or message.style,
17431744 message.error and terminal_styles.error or message.terminal_style)
17441745 end)
@@ -1753,13 +1754,13 @@ mp.register_script_message('set-log', function (log) · 8 unmodified lines
17531754
17541755 for i = 1, #log do
17551756 if type(log[i]) == 'table' then
1756− log[i].text = log[i].text .. '\n'
1757+ log[i].text = log[i].text
17571758 log[i].style = log[i].style or ''
17581759 log[i].terminal_style = log[i].terminal_style or ''
17591760 log_buffers[id][i] = log[i]
17601761 else
17611762 log_buffers[id][i] = {
1762− text = log[i] .. '\n',
1763+ text = log[i],
17631764 style = '',
17641765 terminal_style = '',
17651766 }
@@ -1830,7 +1831,7 @@ mp.register_event('log-message', function(e) · 64 unmodified lines
18301831 if e.level == 'trace' then return end
18311832
18321833 -- Use color for debug/v/warn/error/fatal messages.
1833− log_add('[' .. e.prefix .. '] ' .. e.text, styles[e.level],
1834+ log_add('[' .. e.prefix .. '] ' .. e.text:sub(1, -2), styles[e.level],
18341835 terminal_styles[e.level])
18351836 end)
18361837

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