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

Not compatible with TTY::Link #17

Open
oleander opened this issue May 25, 2021 · 1 comment
Open

Not compatible with TTY::Link #17

oleander opened this issue May 25, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@oleander
Copy link

Great gem! I'm just having some small issues with TTY::Link:

require "tty/box"
require "tty/link"

link = TTY::Link.link_to("Link", "http://example.com")

box1 = TTY::Box.frame(title: { top_left: link }) do
  "<content>"
end

box2 = TTY::Box.frame(title: { top_left: "No link" }) do
  "<content>"
end

puts box1
puts box2

puts TTY::Box::VERSION
puts TTY::Link::VERSION

image

@piotrmurach
Copy link
Owner

Hi Linus 👋

Thanks for using tty-box and tty-link. Also thanks for reporting this issue.

The tty-link emits ANSI codes which are incorrectly taken into account when calculating total width, hence the 'abnormal' box size. The same would happen if you tried using a link inside the box content.

Under the covers the tty-box relies on strings and in particular strings-ansi gem to handle a box content formatting. To handle links width calculation, the strings-ansi needs to know how to remove link codes. I merged PR recently which adds support for this.

I still need to finish working on the strings-ansi gem. Unfortunately releasing it won't fix the issue as I'd need to address it in the tty-box gem next. Currently, I'm refactoring internals of tty-box to turn it into a class. The API won't change. However, it will be more flexible so you can retrieve information about box's content size etc.

box = TTY::Box.new("<content>")
box.content_width # width without any ANSI codes
# etc...

This is all to say that this won't be a 'quick fix. The strings-ansi powers a few tty components so I need to tread carefully. This comes under 'do my best' timeline.

@piotrmurach piotrmurach added the bug Something isn't working label May 25, 2021
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

2 participants