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
Fixes #3520 - respect special chars width #218
Conversation
@@ -1,5 +1,6 @@ | |||
require 'table_print' | |||
require File.join(File.dirname(__FILE__), 'wrapper_formatter') | |||
require File.join(File.dirname(__FILE__), '../../../table_print/formatter') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly hate adding this ../../../
- any other way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't just 'table_print/formatter'
work? if the gem is available I'd expect it to work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some testing and the file formatter.rb
is actually not being found at all. I'd move it from lib
somewhere to 'lib/hammer_cli' and then just do
require 'hammer_cli/...'
It would be also great to try fix it in upstream - arches/table_print#2 </unwanted tip> |
This monkey patch is breaking tests. Anyhow, we should try and have this on table_print and not here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason the fix doesn't work for me. It seems the file with patch is not found and the require fails silently.
@@ -1,5 +1,6 @@ | |||
require 'table_print' | |||
require File.join(File.dirname(__FILE__), 'wrapper_formatter') | |||
require File.join(File.dirname(__FILE__), '../../../table_print/formatter') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some testing and the file formatter.rb
is actually not being found at all. I'd move it from lib
somewhere to 'lib/hammer_cli' and then just do
require 'hammer_cli/...'
@shlomizadok I discovered a few things while testing this PR: The tests are failing because they don't find the file with monkey patch. When I was testing it manually it was calculating length for chinese characters ok, but it failed for czech letters like "žščř". I found out that this is primarily because of false assumption in the original table_print code. The author expects every multibyte character to be rendered in two-columns, which is not correct (https://github.com/arches/table_print/blob/master/lib/table_print/formatter.rb#L44). So I wrote couple of tests and dug deeper into the topic. I realized it's much more complex than one would expect :) I ended up with horrible Pascal-like algorithm that calculates correct length and is able to truncate strings containing both colours and two-column characters. You can find it all here: Can you please review it? I'll be glad for any suggestions for making the algorithm cleaner and more readable. I wasn't able to improve it any further at the point I was writing it:) |
The unicode-display_width gem provides a standard way of determining the display length, I'd strongly recommend using this instead of reimplementing it:
|
Nice, it's surely better to use existing solution. |
Updated. Unfortunately it can't cope with colours so some custom code still remains. |
Merging that disqualifies me from doing the review :) May I ask somebody else? @mbacovsky or @ares ? |
@ares you're right, that was introduced after I switched to |
@ares updated in shlomizadok#2 |
I checkout your branch and it works just fine, 👍 ACK once Shlomi merges the PR, I guess some packaging will be required once this gets in. |
@ares only the unicode-display_width gem needs to get packaged and hammer updated, or am I missing something? :) |
That's what I meant, I just wanted to kindly remind authors to open packaging PRs :-) |
what's the status here? |
I found out we already have rpm package for unicode-display_width: We only need debs. |
@tstrachota the DEB PR is there and marked ready to merge. :) |
@mmoll nice! I completely missed that. Thank you! |
[test] |
The last thing blocking the merge is tests. @shlomizadok could you please rebase? It seems that jenkins fails to apply the patches. |
bc44366
to
0e71ab7
Compare
0e71ab7
to
ace478c
Compare
@tstrachota rebased :) |
💚 |
Merged, thanks @shlomizadok and @mmoll ! |
No description provided.