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
428 428
429 if first_match_to_print > 1 then429 if first_match_to_print > 1 then
430 log[1] = {430 log[1] = {
431 text = '↑ (' .. (first_match_to_print - 1) .. ' hidden items)' .. '\n',431 text = '↑ (' .. (first_match_to_print - 1) .. ' hidden items)',
432 style = styles.disabled,432 style = styles.disabled,
433 terminal_style = terminal_styles.disabled,433 terminal_style = terminal_styles.disabled,
434 }434 }
@@ -437,7 +437,7 @@ local function populate_log_with_matches(max_width) · 2 unmodified lines
437 for i = first_match_to_print, last_match_to_print do437 for i = first_match_to_print, last_match_to_print do
438 log[#log + 1] = {438 log[#log + 1] = {
439 text = (max_width and truncate_utf8(matches[i].text, max_width)439 text = (max_width and truncate_utf8(matches[i].text, max_width)
440 or matches[i].text) .. '\n',440 or matches[i].text),
441 style = i == selected_match and styles.selected_suggestion or '',441 style = i == selected_match and styles.selected_suggestion or '',
442 terminal_style = i == selected_match and terminal_styles.selected_suggestion or '',442 terminal_style = i == selected_match and terminal_styles.selected_suggestion or '',
443 }443 }
@@ -445,7 +445,7 @@ local function populate_log_with_matches(max_width) · 1 unmodified line
445 445
446 if last_match_to_print < #matches then446 if last_match_to_print < #matches then
447 log[#log + 1] = {447 log[#log + 1] = {
448 text = '↓ (' .. (#matches - last_match_to_print) .. ' hidden items)' .. '\n',448 text = '↓ (' .. (#matches - last_match_to_print) .. ' hidden items)',
449 style = styles.disabled,449 style = styles.disabled,
450 terminal_style = terminal_styles.disabled,450 terminal_style = terminal_styles.disabled,
451 }451 }
@@ -463,7 +463,7 @@ local function print_to_terminal() · 11 unmodified lines
463 463
464 local log = ''464 local log = ''
465 for _, log_line in ipairs(log_buffers[id]) do465 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'
467 end467 end
468 468
469 local suggestions = ''469 local suggestions = ''
@@ -563,7 +563,8 @@ local function update() · 93 unmodified lines
563 log_messages = log_max_lines563 log_messages = log_max_lines
564 end564 end
565 for i = #log_buffer - log_messages + 1, #log_buffer do565 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'
567 end568 end
568 569
569 ass:new_event()570 ass:new_event()
@@ -745,7 +746,7 @@ local function help_command(param) · 175 unmodified lines
745 end746 end
746 end747 end
747 if not cmd then748 if not cmd then
748 log_add('No command matches "' .. param .. '"!\n', styles.error,749 log_add('No command matches "' .. param .. '"!', styles.error,
749 terminal_styles.error)750 terminal_styles.error)
750 return751 return
751 end752 end
@@ -761,7 +762,7 @@ local function help_command(param) · 9 unmodified lines
761 output = output .. 'This command supports variable arguments.\n'762 output = output .. 'This command supports variable arguments.\n'
762 end763 end
763 end764 end
764 log_add(output)765 log_add(output:sub(1, -2))
765end766end
766 767
767-- Run the current command and clear the line (Enter)768-- Run the current command and clear the line (Enter)
@@ -1738,7 +1739,7 @@ mp.register_script_message('log', function (message) · 970 unmodified lines
1738 1739
1739 message = utils.parse_json(message)1740 message = utils.parse_json(message)
1740 1741
1741 log_add(message.text .. '\n',1742 log_add(message.text,
1742 message.error and styles.error or message.style,1743 message.error and styles.error or message.style,
1743 message.error and terminal_styles.error or message.terminal_style)1744 message.error and terminal_styles.error or message.terminal_style)
1744end)1745end)
@@ -1753,13 +1754,13 @@ mp.register_script_message('set-log', function (log) · 8 unmodified lines
1753 1754
1754 for i = 1, #log do1755 for i = 1, #log do
1755 if type(log[i]) == 'table' then1756 if type(log[i]) == 'table' then
1756 log[i].text = log[i].text .. '\n'1757 log[i].text = log[i].text
1757 log[i].style = log[i].style or ''1758 log[i].style = log[i].style or ''
1758 log[i].terminal_style = log[i].terminal_style or ''1759 log[i].terminal_style = log[i].terminal_style or ''
1759 log_buffers[id][i] = log[i]1760 log_buffers[id][i] = log[i]
1760 else1761 else
1761 log_buffers[id][i] = {1762 log_buffers[id][i] = {
1762 text = log[i] .. '\n',1763 text = log[i],
1763 style = '',1764 style = '',
1764 terminal_style = '',1765 terminal_style = '',
1765 }1766 }
@@ -1830,7 +1831,7 @@ mp.register_event('log-message', function(e) · 64 unmodified lines
1830 if e.level == 'trace' then return end1831 if e.level == 'trace' then return end
1831 1832
1832 -- Use color for debug/v/warn/error/fatal messages.1833 -- 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],
1834 terminal_styles[e.level])1835 terminal_styles[e.level])
1835end)1836end)
1836 1837

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