Pywikibot includes lots of text messages (especially scripts) presented to the user on the console, and they may be divided into four categories with regards to console width:
- very short messages, unlikely to wrap except on very small devices
- no length limits, with long text wrapping onto the next line, and
- fixed width, and
- variable width with an attempt to limit the width in a sensible but unreliable way
As option 1 is very common, we should decide on a 'minimum width' that is acceptable for Pywikibot usage, and any message shorter than or equal to that is considered OK from a UI perspective.
Almost any attempt to provide a nice layout will fail when page titles are involved, as the page title can be 255 *bytes* of utf8, which can mean fewer characters in some scripts, but it means 255 characters of typical Latin script. An example of a very long redirect is https://en.wikipedia.org/w/index.php?title=To_authorize_the_President_to_extend_the_term_of_the_Agreement_for_Cooperation_between_the_Government_of_the_United_States_of_America_and_the_Government_of_the_Republic_of_Korea_Concerning_Civil_Uses_of_Nuclear_Energy&redirect=no. https://en.wikipedia.org/wiki/Suzukake_no_Ki_no_Michi_de_%22Kimi_no_Hohoemi_o_Yume_ni_Miru%22_to_Itte_Shimattara_Bokutachi_no_Kankei_wa_D%C5%8D_Kawatte_Shimau_no_ka,_Bokunari_ni_Nannichi_ka_Kangaeta_Ue_de_no_Yaya_Kihazukashii_Ketsuron_no_Y%C5%8D_na_Mono is the longest real page on English Wikipedia at 210 characters including at least two non-ASCII characters, so the actually number of bytes is slightly higher..
Pywikibot code prefers to display one page title per line, partially to address the variable width of page titles.
But if there is a prefix on each line, such as a numbered or ordered list, the wrapping of long titles is a small UI problem. If we also add leading whitespace (indents), then wrapping of long titles causes a 'well intended' text layout to break badly and create a UI mess.
We need a consistent approach for handling very long titles. The simplest approach that is almost perfect is to detect when a page title is too large for the screen and try to find a prefix substring that is sufficient to uniquely identify the page, e.g. [[abc foo s...]]
wcwidth can be used to accurately guess the width of a variable so that it can be trimmed at the correct position to not exceed the desired width.
In order to improve the level of 'sensible' width, we need to know what the width of the terminal is.
This was added in Python 3.3 shutil and a backport exists , but it hasnt been added to [[https://github.com/PythonCharmers/python-future/search?utf8=%E2%9C%93&q=get_terminal_size|python-future]] .
The current UI patch regarding length is https://gerrit.wikimedia.org/r/#/c/266587/ (warning about incoming links to page being deleted) . It is going down the path of option 4 - sensible but unreliable limits.