Skip to content

Wrapping strings with multiple ascii color styling segements mangles string contents #4

@artur-martsinkovskyi

Description

@artur-martsinkovskyi

Describe the problem

This library(and the whole tty ecosystem) is awesome and I really like it, although I found a cornercase that also pollutes tty-box library of yours. I tried to use pastel colored strings inside the box and it failed with an error because it would not correctly process them. I will submit another issue and PR for tty-box on that problem. After I patched the problem with tty-box, I found that there was another problem lying in strings library. Strings that have multiple ascii color styling segments are getting trashed by Strings.wrap call, so they are displayed improperly in the box.

Why this is a valid usecase

I am using your library as a skeleton for my social simulation game-like console application. One of the parts of this application includes a console ncurses interface with a map to display current state of the world. Some of the information is better communicated to the user using color, so I'd like have an ability to color each tile independently which is now not possible.

Steps to reproduce the problem

Strings.wrap(Pastel.new.green("#") + Pastel.new.green("#"), 1) # =>
# #
# �
# [
# 3
# 2
# m
# #

Actual behaviour

Strings with multiple ascii color styling segments get mangled and unacceptable to use.

Expected behaviour

Strings with multiple ascii color styling segments are correctly wrapped as in the case with single segment with style encoding.

##Examples
screenshot from 2019-02-02 13-58-06

Describe your environment

  • OS version: Ubuntu 18.04.1
  • Ruby version: 2.5.1
  • Strings version: 0.4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions