Wrapping strings with multiple ascii color styling segements mangles string contents
artur-martsinkovskyi opened this issue · 2 comments
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.
Describe your environment
- OS version: Ubuntu 18.04.1
- Ruby version: 2.5.1
- Strings version: 0.4.1
Hi Artur,
Thanks for using tty gems!
It would be really sweet if you had time to work on fixing this bug in strings
. Also, please open an issue on tty-box
project as well.
This is really cool that you're building a console game! Are you planning to open source it? I'd like to see how you're using tty libraries and generally coding the game. I'm currently working on a console game myself, which is the reason why I've created tty-box
package!
Yes, I am going to outsource it, it is my masters degree thesis, actually. It may be a bit hard to resolve the issue with plain strings, maybe udecorated versions would fit more into the essence of the issue of printing decorated strings inside the box.