Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions DOCS/man/console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ PGDN
Ctrl+r
Search the command history. See `SELECT`_ for the key bindings in this mode.

Shift+UP
Scroll the log one line up.

Shift+DOWN
Scroll the log one line down.

INSERT
Toggle insert mode.

Expand Down
26 changes: 23 additions & 3 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ local searching_history = false
local history_paths = {}
local histories_to_save = {}

local MAX_LOG_LINES = 10000
local log_buffers = {}
local log_offset = 0
local key_bindings = {}
local dont_bind_up_down = false
local global_margins = { t = 0, b = 0 }
Expand Down Expand Up @@ -747,7 +749,9 @@ local function render()

local log_ass = ""
local log_buffer = log_buffers[id] or {}
for i = #log_buffer - math.min(max_lines, #log_buffer) + 1, #log_buffer do
log_offset = math.max(math.min(log_offset, #log_buffer - max_lines), 0)
for i = #log_buffer - math.min(max_lines, #log_buffer) - log_offset + 1,
#log_buffer - log_offset do
log_ass = log_ass .. style .. log_buffer[i].style ..
ass_escape(log_buffer[i].text) .. "\\N"
end
Expand Down Expand Up @@ -1314,6 +1318,15 @@ local function clear_log_buffer()
render()
end

local function scroll_log(amount)
if selectable_items then
return
end

log_offset = log_offset + amount
render()
end

-- Returns a string of UTF-8 text from the clipboard (or the primary selection)
local function get_clipboard(clip)
if platform == "x11" then
Expand Down Expand Up @@ -1479,6 +1492,8 @@ local function get_bindings()
{ "down", function() move_history(1) end },
{ "ctrl+n", function() move_history(1) end },
{ "wheel_down", function() move_history(1, true) end },
{ "shift+up", function() scroll_log(1) end },
{ "shift+down", function() scroll_log(-1) end },
{ "wheel_left", function() end },
{ "wheel_right", function() end },
{ "ctrl+left", prev_word },
Expand Down Expand Up @@ -1653,6 +1668,7 @@ mp.register_script_message("get-input", function (script_name, args)
selectable_items = nil
unbind_mouse()
id = args.id or script_name .. prompt
log_offset = 0
completion_buffer = {}
autoselect_completion = args.autoselect_completion

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

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

if #log_buffer > 100 then
if #log_buffer > MAX_LOG_LINES then
table.remove(log_buffer, 1)
end

if not open then
return
end

if log_offset > 0 then
log_offset = log_offset + 1
end

if not update_timer:is_enabled() then
render()
update_timer:resume()
Expand Down
Loading