Skip to content

Commit

Permalink
cataimgui::TextColoredParagraph can now handle a < followed by a tag
Browse files Browse the repository at this point in the history
This crops up in help.json a few times where it represents a building
rather than the start of a tag.
  • Loading branch information
db48x committed Dec 14, 2024
1 parent eba840f commit 0109244
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,18 @@ void TextColoredParagraph( nc_color default_color, const std::string_view str,
std::vector<uint32_t> colors = std::vector<uint32_t>( 1, u32_from_color( default_color ) );
while( std::string::npos != ( e = str.find( '<', s ) ) ) {
TextEx( str.substr( s, e - s ), wrap_width, colors.back() );
size_t ce = str.find( '>', e );
size_t ce = str.find_first_of( "<>", e + 1 );
if( std::string::npos != ce ) {
std::string_view tagname = str.substr( e, ce - e + 1 );
// back up by one if we find the start of another tag instead of the end of this one
// an annoying example from help.json: "<color_light_green>^>v<</color>"
if( str[ ce ] == '<' ) {
ce -= 1;
}
std::string_view tagname = str.substr( e, len );

Check failure on line 306 in src/text.cpp

View workflow job for this annotation

GitHub Actions / build (src)

use of undeclared identifier 'len' [clang-diagnostic-error]

Check failure on line 306 in src/text.cpp

View workflow job for this annotation

GitHub Actions / Basic Build and Test (Clang 10, Ubuntu, Curses)

use of undeclared identifier 'len'
if( "<num>" == tagname && value.has_value() ) {
TextSegmentEx( value.value(), wrap_width, true );
} else {
color_tag_parse_result tag = get_color_from_tag( str.substr( e, ce - e + 1 ) );
color_tag_parse_result tag = get_color_from_tag( tagname );
switch( tag.type ) {
case color_tag_parse_result::open_color_tag:
colors.push_back( u32_from_color( tag.color ) );
Expand Down

0 comments on commit 0109244

Please sign in to comment.