Skip to content

Commit b8b7b1d

Browse files
committed
console.lua: bind Shift+UP and DOWN to scroll the log
We don't know how many log lines wrap, so scrolling the log with page up and down with wrapped lines would skip lines, and those are also already bound to history navigation. This therefore only implements scrolling of one item at a time. While not perfect because when the item is wrapped it scrolls multiple lines, it is usable. The number of log lines kept in memory is increased from 100 to 10000. Closes #14718.
1 parent 194ce88 commit b8b7b1d

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

DOCS/man/console.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ PGDN
8181
Ctrl+r
8282
Search the command history. See `SELECT`_ for the key bindings in this mode.
8383

84+
Shift+UP
85+
Scroll the log one line up.
86+
87+
Shift+DOWN
88+
Scroll the log one line down.
89+
8490
INSERT
8591
Toggle insert mode.
8692

player/lua/console.lua

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ local searching_history = false
9090
local history_paths = {}
9191
local histories_to_save = {}
9292

93+
local MAX_LOG_LINES = 10000
9394
local log_buffers = {}
95+
local log_offset = 0
9496
local key_bindings = {}
9597
local dont_bind_up_down = false
9698
local global_margins = { t = 0, b = 0 }
@@ -747,7 +749,9 @@ local function render()
747749

748750
local log_ass = ""
749751
local log_buffer = log_buffers[id] or {}
750-
for i = #log_buffer - math.min(max_lines, #log_buffer) + 1, #log_buffer do
752+
log_offset = math.max(math.min(log_offset, #log_buffer - max_lines), 0)
753+
for i = #log_buffer - math.min(max_lines, #log_buffer) - log_offset + 1,
754+
#log_buffer - log_offset do
751755
log_ass = log_ass .. style .. log_buffer[i].style ..
752756
ass_escape(log_buffer[i].text) .. "\\N"
753757
end
@@ -1314,6 +1318,15 @@ local function clear_log_buffer()
13141318
render()
13151319
end
13161320

1321+
local function scroll_log(amount)
1322+
if selectable_items then
1323+
return
1324+
end
1325+
1326+
log_offset = log_offset + amount
1327+
render()
1328+
end
1329+
13171330
-- Returns a string of UTF-8 text from the clipboard (or the primary selection)
13181331
local function get_clipboard(clip)
13191332
if platform == "x11" then
@@ -1479,6 +1492,8 @@ local function get_bindings()
14791492
{ "down", function() move_history(1) end },
14801493
{ "ctrl+n", function() move_history(1) end },
14811494
{ "wheel_down", function() move_history(1, true) end },
1495+
{ "shift+up", function() scroll_log(1) end },
1496+
{ "shift+down", function() scroll_log(-1) end },
14821497
{ "wheel_left", function() end },
14831498
{ "wheel_right", function() end },
14841499
{ "ctrl+left", prev_word },
@@ -1653,6 +1668,7 @@ mp.register_script_message("get-input", function (script_name, args)
16531668
selectable_items = nil
16541669
unbind_mouse()
16551670
id = args.id or script_name .. prompt
1671+
log_offset = 0
16561672
completion_buffer = {}
16571673
autoselect_completion = args.autoselect_completion
16581674

@@ -1675,7 +1691,7 @@ mp.register_script_message("get-input", function (script_name, args)
16751691
mp.commandv("script-message-to", input_caller, "input-event", "opened")
16761692
end)
16771693

1678-
-- Add a line to the log buffer (which is limited to 100 lines)
1694+
-- Add a line to the log buffer
16791695
mp.register_script_message("log", function (message)
16801696
local log_buffer = log_buffers[id]
16811697
message = utils.parse_json(message)
@@ -1687,14 +1703,18 @@ mp.register_script_message("log", function (message)
16871703
message.terminal_style or "",
16881704
}
16891705

1690-
if #log_buffer > 100 then
1706+
if #log_buffer > MAX_LOG_LINES then
16911707
table.remove(log_buffer, 1)
16921708
end
16931709

16941710
if not open then
16951711
return
16961712
end
16971713

1714+
if log_offset > 0 then
1715+
log_offset = log_offset + 1
1716+
end
1717+
16981718
if not update_timer:is_enabled() then
16991719
render()
17001720
update_timer:resume()

0 commit comments

Comments
 (0)