terminaltables icon indicating copy to clipboard operation
terminaltables copied to clipboard

Add API for truncating/fitting/handling long titles.

Open Robpol86 opened this issue 8 years ago • 0 comments

Implement table.title_cb which accepts a function/lambda that handles titles that won't fit in the top border.

Function signature expected:

:param str title: The title to overlay on the top border.
:param int max_len: Maximum number of characters that can be shown right now.

:return: Processed title and its length.
:rtype: (str, int)

Must return title that will fit in the border (else the table will appear broken/misaligned/wrapped) as well as the length of the string.

Length values are for visible characters. When using CJK (Chinese/Japanese/Korean) characters some may be len() of 1 but take up 2 visible spaces in terminals. Hence API expects function to return title length in case the function truncates the string and the last character is one short of the maximum width available due to it being a CJK character.

e.g. terminal with 7 spaces available for the title and the title is "世界你好" That's 8 visible spaces so if the function truncates it to "世界你" API expects length of 6 to be returned.

Robpol86 avatar May 22 '16 05:05 Robpol86