Add ANSI escape sequences for inline styles #84
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In this pull request, several changes were made to simple_term_menu to improve support for inline ANSI colour and style sequences and to fix display errors when ANSI codes are inline used:
New function remove_ansi_sequences:
Function to recognise and remove different formats of ANSI escape sequences. This ensures that the width calculation of menu entries and title lines is carried out correctly without including the invisible ANSI characters.
New function check_ansi_reset:
Checks whether a menu entry contains ANSI reset sequences and returns True or False accordingly.
New function apply_inline_style:
Inserts highlight styles again after a detected ANSI reset. This allows specific parts of the menu to be coloured, while other parts are highlighted normally. For example, a menu entry such as "- (online) name" can be formatted so that "online" is highlighted in green and "name" is highlighted normally.
Added _codename_to_ansi for direct ANSI codes:
This list contains direct ANSI codes to enable apply_inline_style to insert the correct style after a reset.
Adjustments in print_menu_entries:
The function has been modified to support the new ANSI functions and to correctly perform the width calculations in the menu and title.