Skip to content

TTY::Box.frame with a static width fails if the text joins multiple Pastel styled strings #21

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

Open
adamstegman opened this issue Jun 3, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@adamstegman
Copy link

adamstegman commented Jun 3, 2023

Describe the problem

This sounds a lot like #5, but the error is different. When I frame a box with a static width and pass a string containing two pastel strings as the content, an IndexError is raised.

Steps to reproduce the problem

require "pastel"
require "tty-box"

pastel = Pastel.new
box = TTY::Box

print box.frame(
  "#{pastel.italic("TEXT TEXT TEXT TEXT")}; #{pastel.italic("TEXT TEXT TEXT TEXT")}",
  width: 40,
)

Actual behaviour

Error raised

/Users/adam/.gem/ruby/3.0.3/gems/strings-0.2.1/lib/strings/wrap.rb:158:in `insert': index 20 out of string (IndexError)
	from /Users/adam/.gem/ruby/3.0.3/gems/strings-0.2.1/lib/strings/wrap.rb:158:in `block in insert_ansi'
	from /Users/adam/.gem/ruby/3.0.3/gems/strings-0.2.1/lib/strings/wrap.rb:142:in `reverse_each'
	from /Users/adam/.gem/ruby/3.0.3/gems/strings-0.2.1/lib/strings/wrap.rb:142:in `insert_ansi'
	from /Users/adam/.gem/ruby/3.0.3/gems/strings-0.2.1/lib/strings/wrap.rb:111:in `format_line'
	from /Users/adam/.gem/ruby/3.0.3/gems/strings-0.2.1/lib/strings/wrap.rb:30:in `block in wrap'
	from /Users/adam/.gem/ruby/3.0.3/gems/strings-0.2.1/lib/strings/wrap.rb:29:in `map'
	from /Users/adam/.gem/ruby/3.0.3/gems/strings-0.2.1/lib/strings/wrap.rb:29:in `wrap'
	from /Users/adam/.gem/ruby/3.0.3/gems/tty-box-0.7.0/lib/tty/box.rb:337:in `block in format'
	from /Users/adam/.gem/ruby/3.0.3/gems/tty-box-0.7.0/lib/tty/box.rb:336:in `each'
	from /Users/adam/.gem/ruby/3.0.3/gems/tty-box-0.7.0/lib/tty/box.rb:336:in `each_with_object'
	from /Users/adam/.gem/ruby/3.0.3/gems/tty-box-0.7.0/lib/tty/box.rb:336:in `format'
	from /Users/adam/.gem/ruby/3.0.3/gems/tty-box-0.7.0/lib/tty/box.rb:219:in `frame'
	from test.rb:7:in `<main>'

Expected behaviour

The too-long string is wrapped inside the box, like an unstyled string

Describe your environment

  • OS version: macOS 13.3.1 (a)
  • Ruby version: 3.0.3p157
  • TTY::Box version: 0.7.0
@adamstegman adamstegman added the bug Something isn't working label Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant