From 9c9ba3cf30d6f192a544cdfb262301b8aacc1b09 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Wed, 11 Oct 2023 17:26:16 +0200 Subject: console.lua: print the log and input line to the terminal --- player/lua/console.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'player/lua/console.lua') 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 -- cgit v1.2.3