diff --git a/libr/util/str.c b/libr/util/str.c index 939a15c3a9..23de059514 100644 --- a/libr/util/str.c +++ b/libr/util/str.c @@ -1524,21 +1524,24 @@ R_API char *r_str_ansi_crop(const char *str, ut32 x, ut32 y, ut32 x2, ut32 y2) { str++; ch++; cw = 0; - } else if (*str == 0x1b && *(str + 1) == '[') { - const char *ptr = str; - if ((r_end - r) > 2) { - /* copy 0x1b and [ */ - *r++ = *str++; - *r++ = *str++; - for (ptr = str; *ptr && *ptr != 'J' && *ptr != 'm' && *ptr != 'H'; ++ptr) { - *r++ = *ptr; - } - *r++ = *ptr++; - } - str = ptr; } else { if (ch >= y && ch < y2 && cw >= x && cw < x2) { - *r++ = *str; + if (*str == 0x1b && *(str + 1) == '[') { + const char *ptr = str; + if ((r_end - r) > 2) { + /* copy 0x1b and [ */ + *r++ = *str++; + *r++ = *str++; + for (ptr = str; *ptr && *ptr != 'J' && *ptr != 'm' && *ptr != 'H'; ++ptr) { + *r++ = *ptr; + } + *r++ = *ptr++; + } + str = ptr; + continue; + } else { + *r++ = *str; + } } /* skip until newline */