-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
console.lua: fix the max width calculation #14419
Conversation
Download the artifacts for this pull request: |
f366a4c
to
be2fd83
Compare
player/lua/console.lua
Outdated
@@ -546,7 +547,8 @@ local function update() | |||
|
|||
local lines_max = calculate_max_log_lines() | |||
-- Estimate how many characters fit in one line | |||
local width_max = math.ceil(screenx / opts.font_size * get_font_hw_ratio()) | |||
local width_max = math.floor((screenx - margin - mp.get_property_native('osd-margin-x')) / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't osd-margin-x
get subtracted from screenx before it gets divided by dpi_scale
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done that for the margin too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it doesn't seem right to substract the margins from the clip coordinates, so I divided them by the scale afterwards.
be2fd83
to
d21a4a0
Compare
Does |
d21a4a0
to
d47508a
Compare
Scaling |
f986171
to
cba7e52
Compare
That's not the issue. Did some logging.
That Figuring out what font is being used, it's
So I change console font to 'Fira Mono Medium' which has
So the console using |
Is this #14249 again? Does libass master fix it? Anyway |
Bingo. So the |
5b2dc12
to
43e154e
Compare
Good that we have those magic numbers hardcoded around the codebase and no one knows why they are needed, until digging into it. /s |
Something is still off in the calculation as the lines can still wrap. Also I don't understand why it doesn't seem to be affected by |
@guidocella |
I'm pretty sure that's because the resolution to use for the supplied ass is set in |
Yeah you should be able to reproduce it by making the window smaller.
It's because |
43e154e
to
d8fb0c7
Compare
Oh you meant why |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an improvement over the status quo, even if it's not perfect for everyone.
d8fb0c7
to
f20ddfa
Compare
Even if ass:pos() hardcodes the position at 6px from the left, we still need to subtract the left --osd-margin-x from the available text width. See how libass/ass_render.c:ass_render_event() subtracts it from max_text_width without checking if the event is positioned. The calculation is still not perfect as the width could be made a bit larger before the text wraps.
f20ddfa
to
4412633
Compare
In select mode and when printing the OSD, use \q2 to let libass clip lines longer than the OSD. This works around having to leave a large horizontal space unused due to libass subtracting the left margin from the max text width even though the ASS event is anchored to the bottom left. It also fixes truncating wide Unicode characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works well
b8216c1
to
82f2739
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No wrap suggestions in the terminal also work.
These are DEC private mode reset/set auto-wrap mode (DECAWM). mpv doesn't use terminal escape sequences "correctly" - it doesn't use terminfo or ncurses etc (which only use features supported by the terminal), which is why mpv should use only the most common escape sequences which are likely to work on most terminals out there. I don't think It's guaranteed that this sequence is supported by all terminals, and I don't think this is generally a commonly-used escape sequence elsewhere. At least I don't recall encountering it in the past. Off topic here, but same goes about using ALT-screen (iirc in sixel and/or tct), because it's not guaranteed to be supported or enabled on all terminals, for instance xterm on fedora by default doesn't have alt-screen AFAIK. So mpv should try to limit itself as much as possible only to very common terminal features and sequences. |
It did work in all terminals I tried including xterm. If it wasn't supported log lines would just be printed as they are. I don't think there is another sane way to predict terminal unicode width from Lua. |
According to https://invisible-island.net/xterm/ctlseqs/ctlseqs.html:
I think VT100 should be OK as a baseline, and is the default terminal assumed by most *nix TUI programs. It won't work on VT52 terminals but I doubt it's used in any meaningful capacity. However, this won't work with Windows console if VT processing is disabled. And even if VT processing is enabled, this auto-wrap mode code isn't listed on the MS documentation. It's only supported for recent terminal versions: microsoft/terminal#3943 (other codes like show/hide cursor are listed in the documentation) |
Is it worth keeping |
This prevents line wraps in select mode with terminal output which hide the top items (OSD output no longer uses truncate_utf8 since the previous commit). This is not ideal as even accented letters are assumed to be 2 cells wide. The alternative is using \e[?7l and \e[?7h to disable and enable text wrapping, but it won't work in Windows console with VT processing disabled.
82f2739
to
c60d3d1
Compare
Changed to assume all non-ASCII characters span 2 cells instead. |
It still clips graphical output. I liked clipping in the terminal too but we will probably integrate wcwidth in |
Ok, let's not worry too much about it. This has been merged into conhost in build 19603, which was 4 years ago. Sure we might left this one guy who uses 1507 and in the same time uses terminal... on Windows. I would argue that we can afford having this slightly broken. To trigger this you need to use non-ascii chars, use terminal and use old Windows build. Maybe there is one guy affected, but really... Non-VT mode is indeed a problem, but in this case we could fallback to wrapping. Either way, I don't think preventing terminal wrapping, really solves the issue, because msg.c code expect that and will clear wrong lines because of line count mismatch. So the proper fix is to have common code |
No description provided.