Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
artur-martsinkovskyi opened this issue Feb 2, 2019 · 2 comments

Comments

@artur-martsinkovskyi
Copy link

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
@piotrmurach
Copy link
Owner

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!

@artur-martsinkovskyi
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants