diff options
author | Guido Cella <guido@guidocella.xyz> | 2023-10-11 17:26:16 +0200 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2023-10-11 21:09:40 +0000 |
commit | 9c9ba3cf30d6f192a544cdfb262301b8aacc1b09 (patch) | |
tree | 7a3ad451b2a19f7d76caea6c9d5a6823f28a0750 | |
parent | 8134f18c28229c38102535baf210f77d0cd6feb0 (diff) | |
download | mpv-9c9ba3cf30d6f192a544cdfb262301b8aacc1b09.tar.bz2 mpv-9c9ba3cf30d6f192a544cdfb262301b8aacc1b09.tar.xz |
console.lua: print the log and input line to the terminal
-rw-r--r-- | player/lua/console.lua | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/player/lua/console.lua b/player/lua/console.lua index 978ba51b6c..a05c976031 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -212,10 +212,43 @@ function format_table(list, width_max, rows_max) return table.concat(rows, '\n'), rows_truncated end +local function print_to_terminal() + -- Clear the log after closing the console. + if not repl_active then + mp.osd_message('') + return + end + + local log = '' + for _, log_line in ipairs(log_buffer) do + log = log .. log_line.text + end + + local suggestions = table.concat(suggestion_buffer, '\t') + if suggestions ~= '' then + suggestions = suggestions .. '\n' + end + + local before_cur = line:sub(1, cursor - 1) + local after_cur = line:sub(cursor) + -- Ensure there is a character with inverted colors to print. + if after_cur == '' then + after_cur = ' ' + end + + mp.osd_message(log .. suggestions .. '> ' .. before_cur .. '\027[7m' .. + after_cur:sub(1, 1) .. '\027[0m' .. after_cur:sub(2), 999) +end + -- Render the REPL and console as an ASS OSD function update() pending_update = false + if not mp.get_property_native('vo-configured') then + print_to_terminal() + return + end + local dpi_scale = mp.get_property_native("display-hidpi-scale", 1.0) dpi_scale = dpi_scale * opts.scale |