In the select menu there are no completions to align in a grid, so the better looking proportional font of --osd-font can be used by default. It is also easier to read for the visually impaired. The text width calculation is no longer performed if the console is only opened through select, it is only performed the first time something is completed. This avoids having to pass an argument to get_font() to make it use the monospace font regardless of selectable_items. Fixes #15176.
Showing the changes to player/lua/console.lua (1 of 2 files). Show all
Unified · Split
| @@ -15,17 +15,6 @@ · 14 unmodified lines | ||
| 15 | 15 | local utils = require 'mp.utils' |
| 16 | 16 | local assdraw = require 'mp.assdraw' |
| 17 | 17 | |
| 18 | −-- Default options | |
| 19 | −local opts = { | |
| 20 | − font = "", | |
| 21 | − font_size = 24, | |
| 22 | − border_size = 1.5, | |
| 23 | − scale_with_window = "auto", | |
| 24 | − case_sensitive = true, | |
| 25 | − history_dedup = true, | |
| 26 | − font_hw_ratio = 'auto', | |
| 27 | −} | |
| 28 | − | |
| 29 | 18 | local function detect_platform() |
| 30 | 19 | local platform = mp.get_property_native('platform') |
| 31 | 20 | if platform == 'darwin' or platform == 'windows' then |
| @@ -36,16 +25,18 @@ local function detect_platform() · 4 unmodified lines | ||
| 36 | 25 | return 'x11' |
| 37 | 26 | end |
| 38 | 27 | |
| 39 | −-- Pick a better default font for Windows and macOS | |
| 40 | 28 | local platform = detect_platform() |
| 41 | −if platform == 'windows' then | |
| 42 | − opts.font = 'Consolas' | |
| 43 | − opts.case_sensitive = false | |
| 44 | −elseif platform == 'darwin' then | |
| 45 | − opts.font = 'Menlo' | |
| 46 | −else | |
| 47 | − opts.font = 'monospace' | |
| 48 | −end | |
| 29 | + | |
| 30 | +-- Default options | |
| 31 | +local opts = { | |
| 32 | + font = "", | |
| 33 | + font_size = 16, | |
| 34 | + border_size = 1, | |
| 35 | + scale_with_window = "auto", | |
| 36 | + case_sensitive = platform ~= 'windows' and true or false, | |
| 37 | + history_dedup = true, | |
| 38 | + font_hw_ratio = 'auto', | |
| 39 | +} | |
| 49 | 40 | |
| 50 | 41 | -- Apply user-set options |
| 51 | 42 | require 'mp.options'.read_options(opts) |
| @@ -117,6 +108,28 @@ local default_item · 65 unmodified lines | ||
| 117 | 108 | local set_active |
| 118 | 109 | |
| 119 | 110 | |
| 111 | +local function get_font() | |
| 112 | + if opts.font ~= '' then | |
| 113 | + return opts.font | |
| 114 | + end | |
| 115 | + | |
| 116 | + if selectable_items and not searching_history then | |
| 117 | + return | |
| 118 | + end | |
| 119 | + | |
| 120 | + -- Pick a better default font for Windows and macOS | |
| 121 | + if platform == 'windows' then | |
| 122 | + return 'Consolas' | |
| 123 | + end | |
| 124 | + | |
| 125 | + if platform == 'darwin' then | |
| 126 | + return 'Menlo' | |
| 127 | + end | |
| 128 | + | |
| 129 | + return 'monospace' | |
| 130 | +end | |
| 131 | + | |
| 132 | + | |
| 120 | 133 | -- Naive helper function to find the next UTF-8 character in 'str' after 'pos' |
| 121 | 134 | -- by skipping continuation bytes. Assumes 'str' contains valid UTF-8. |
| 122 | 135 | local function next_utf8(str, pos) |
| @@ -184,7 +197,7 @@ local function normalized_text_width(text, size, horizontal) · 61 unmodified lines | ||
| 184 | 197 | for i = 1, repetitions_left do |
| 185 | 198 | size = size * 0.8 |
| 186 | 199 | local ass = assdraw.ass_new() |
| 187 | − ass.text = template:format(align, size, opts.font, rotation, text) | |
| 200 | + ass.text = template:format(align, size, get_font(), rotation, text) | |
| 188 | 201 | local _, _, x1, y1 = measure_bounds(ass.text) |
| 189 | 202 | -- Check if nothing got clipped |
| 190 | 203 | if x1 and x1 < osd_width and y1 < osd_height then |
| @@ -507,10 +520,12 @@ local function update() · 316 unmodified lines | ||
| 507 | 520 | screenx .. ',' .. screeny |
| 508 | 521 | local ass = assdraw.ass_new() |
| 509 | 522 | local has_shadow = mp.get_property('osd-border-style'):find('box$') == nil |
| 523 | + local font = get_font() | |
| 510 | 524 | local style = '{\\r' .. |
| 511 | 525 | '\\1a&H00&\\3a&H00&\\1c&Heeeeee&\\3c&H111111&' .. |
| 512 | 526 | (has_shadow and '\\4a&H99&\\4c&H000000&' or '') .. |
| 513 | − '\\fn' .. opts.font .. '\\fs' .. opts.font_size .. | |
| 527 | + (font and '\\fn' .. font or '') .. | |
| 528 | + '\\fs' .. opts.font_size .. | |
| 514 | 529 | '\\bord' .. opts.border_size .. '\\xshad0\\yshad1\\fsp0' .. |
| 515 | 530 | (selectable_items and '\\q2' or '\\q1') .. |
| 516 | 531 | '\\clip(' .. clipping_coordinates .. ')}' |
| @@ -534,20 +549,24 @@ local function update() · 17 unmodified lines | ||
| 534 | 549 | -- This will render at most screeny / font_size - 1 messages. |
| 535 | 550 | |
| 536 | 551 | local lines_max = calculate_max_log_lines() |
| 537 | − -- Estimate how many characters fit in one line | |
| 538 | − local width_max = math.floor((screenx - bottom_left_margin - | |
| 539 | − mp.get_property_native('osd-margin-x') * 2 * screeny / 720) / | |
| 540 | − opts.font_size * get_font_hw_ratio()) | |
| 552 | + local suggestion_ass = '' | |
| 553 | + if next(suggestion_buffer) then | |
| 554 | + -- Estimate how many characters fit in one line | |
| 555 | + local width_max = math.floor((screenx - bottom_left_margin - | |
| 556 | + mp.get_property_native('osd-margin-x') * 2 * screeny / 720) | |
| 557 | + / opts.font_size * get_font_hw_ratio()) | |
| 541 | 558 | |
| 542 | − local suggestions, rows = format_table(suggestion_buffer, width_max, lines_max) | |
| 543 | − local suggestion_ass = style .. styles.suggestion .. suggestions | |
| 559 | + local suggestions, rows = format_table(suggestion_buffer, width_max, lines_max) | |
| 560 | + lines_max = lines_max - rows | |
| 561 | + suggestion_ass = style .. styles.suggestion .. suggestions .. '\\N' | |
| 562 | + end | |
| 544 | 563 | |
| 545 | 564 | populate_log_with_matches() |
| 546 | 565 | |
| 547 | 566 | local log_ass = '' |
| 548 | 567 | local log_buffer = log_buffers[id] |
| 549 | 568 | local log_messages = #log_buffer |
| 550 | − local log_max_lines = math.max(0, lines_max - rows) | |
| 569 | + local log_max_lines = math.max(0, lines_max) | |
| 551 | 570 | if log_max_lines < log_messages then |
| 552 | 571 | log_messages = log_max_lines |
| 553 | 572 | end |
| @@ -560,9 +579,7 @@ local function update() · 6 unmodified lines | ||
| 560 | 579 | ass:an(1) |
| 561 | 580 | ass:pos(bottom_left_margin, screeny - bottom_left_margin - global_margins.b * screeny) |
| 562 | 581 | ass:append(log_ass .. '\\N') |
| 563 | − if #suggestions > 0 then | |
| 564 | − ass:append(suggestion_ass .. '\\N') | |
| 565 | − end | |
| 582 | + ass:append(suggestion_ass) | |
| 566 | 583 | ass:append(style .. ass_escape(prompt) .. ' ' .. before_cur) |
| 567 | 584 | ass:append(cglyph) |
| 568 | 585 | ass:append(style .. after_cur) |