mps-youtube / yewtube

yewtube, forked from mps-youtube , is a Terminal based YouTube player and downloader. No Youtube API key required.
GNU General Public License v3.0
8.12k stars 642 forks source link

Misalignment due to East East Asian chars fix #1001

Closed gnojus closed 5 years ago

gnojus commented 5 years ago

Due to East East Asian chars being more than two columns wide on terminal, video list often was misaligned and looked like this:

mps_yt_1 (Whole table doesn't even fit into the terminal window)

Added util.correct_truncate method which truncates a string taking into account East Asian width chars. util.ea_pad' now pads correctly. Also content.generate_songlist_display and ListView.content functions now use custom string formatting instead of the default one and output correct table:

mps_yt_2

Note: the util.real_len function doesn't take into account Unicode emojis. Because of that, the table is still a bit misaligned (line 12 & 20). I suggest to let wcwidth in real_len function take care of it, it should solve the problem. If the additional dependency is okay.

gnojus commented 5 years ago

Any chance to get this at least reviewed?

tommysolsen commented 5 years ago

Thanks for this PR, Nojus!

gnojus commented 5 years ago

I'm glad that it got merged. What do you think about using wcwidth module?