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

Output table padding formatter goes wrong with UTF8 characters #251

Closed
darkskiez opened this issue Mar 20, 2012 · 13 comments
Closed

Output table padding formatter goes wrong with UTF8 characters #251

darkskiez opened this issue Mar 20, 2012 · 13 comments
Assignees
Milestone

Comments

@darkskiez
Copy link

The padding of the |'s goes wrong for the chinese input example.

Feature: Multilingual

  Cucumber output pads columns example

  Scenario Outline: Language Example
    Given dummy step <language>

  Examples:
        | language  | labelled  |
        | English   | OK        |
        | 日本語    | 确定      |
        | Español   | Aceptar   |
@mattwynne
Copy link
Member

Which version of Ruby is this with?

@darkskiez
Copy link
Author

MRI 1.9.3p0

@dkowis
Copy link
Member

dkowis commented Apr 8, 2013

So I'm not sure how one expects Multibyte characters that don't fit the width of an ASCII Character to line up.
If all the characters were the same language, of course they'd line up, but I'm not sure there's any way to make them line up differently. I'll investigate a bit, but I'm sceptical.

Also, I assume this is for the pretty formatter output?

@ghost ghost assigned dkowis Apr 8, 2013
@dkowis
Copy link
Member

dkowis commented Apr 8, 2013

Yeah I'm of the mind that we shouldn't spend time trying to fix this. Anything we could do would be complicated. We'd have to some how compute the size of the character being displayed, not simply the amount of characters being displayed.

@mattwynne, thoughts?

@os97673
Copy link
Member

os97673 commented Apr 8, 2013

I'm second to @dkowis let'd do not spend time on this. It looks like a nice exercise in UTF area but adds nothing to Cucumber.
Though I will be happy to review PR for it ;)

@mattwynne @tooky do you agree?

@aslakhellesoy
Copy link
Contributor

Some multibyte characters have width != 1:

XY
确定

Knowing whether a character has double width or not requires separate code: http://stackoverflow.com/questions/3634627/how-to-know-the-preferred-display-width-in-columns-of-unicode-characters

Bikeshedding springs to mind :-)

@os97673
Copy link
Member

os97673 commented Apr 8, 2013

So, I'm closing the ticket.

@os97673 os97673 closed this as completed Apr 8, 2013
@mattwynne
Copy link
Member

A simple solution might be to offer a setting on the API that allows the user to specify double-width characters. That way if someone suffers from this, and they care enough about it, they can fix the problem by explicitly configuring Cucumber to display those characters as double-width.

e.g. in features/support/env.rb

Cucumber.configure do
  config.determine_console_character_width do |character|
    ['日', '本', '語'].include?(character) ? 2 : 1
  end
end

If nobody has called this configuration block, we assume everything is a 1.

It would be trivial to change Cucumber to use this lookup. That would also open up for someone to write a plugin that used one of the C libraries @aslakhellesoy referenced.

If anyone wants to write a PR for this, that's what I'd recommend they do.

@aslakhellesoy
Copy link
Contributor

I thought widths could be fractional, like 1.4.

@mattwynne
Copy link
Member

@aslakhellesoy ah, so that would make our implementation non-trivial. Is that what you're saying?

@aslakhellesoy
Copy link
Contributor

Yes. See the SO I linked to

@dkowis
Copy link
Member

dkowis commented Apr 8, 2013

Yeah, when I looked at it, it would end up being a fractional width, which is basically impossible to do on the console. The way I think, if you want to do mixed languages, you should probably output to something that deals with them better, rather than the console. The HTML formatter springs to mind. The pretty formatter is good enough in a pinch, but won't ever be perfect for stuff like this, IMHO.

mxygem added a commit that referenced this issue Aug 24, 2017
mxygem added a commit that referenced this issue Aug 24, 2017
* CHANGELOG updates for monorepo's #251
* Add pr and credit links
mxygem added a commit that referenced this issue Sep 7, 2017
* Formatting and things
* Added header from [#251](cucumber/common#251)
mxygem added a commit that referenced this issue Sep 14, 2017
* Formatting and link fixing for [#1182](cucumber/common#1182)
* Added header from [#251](cucumber/common#251)
@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants