-
Notifications
You must be signed in to change notification settings - Fork 88
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
Completely support full-width characters in differential rendering #654
Completely support full-width characters in differential rendering #654
Conversation
95220ed
to
75ca084
Compare
lib/reline/unicode.rb
Outdated
total_width += mbchar_width | ||
break if (start_col + max_width) < total_width | ||
chunk << gc if start_col < total_width | ||
break if !cover_end && total_width > start_col + width |
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.
Could you add comments to these conditional branches?
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 forgot to implement this.
# Red background あ
Reline::Unicode.take_mbchar_range "\e[41mあ", 1, 2, padding: true
# Red background whitespace + No background whitespace
["\e[41m \e[0m ", 1, 2]
I've updated the implementation and add comments
@@ -692,13 +697,6 @@ def add_dialog_proc(name, p, context = nil) | |||
|
|||
DIALOG_DEFAULT_HEIGHT = 20 | |||
|
|||
private def padding_space_with_escape_sequences(str, width) |
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'm curious, why did you combine calculating padding with take_mbchar_range
?
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.
Padding sometimes have background colors.
The last testcase I added is a good example.
assert_equal ["\e[41m \e[42mい\e[43m ", 1, 4], Reline::Unicode.take_mbchar_range("\e[41mあ\e[42mい\e[43mう\e[0m", 1, 4, padding: true)
So we can't add non-colored space as padding. Padding logic cannot be separated from take_mbchar_range
75ca084
to
a7c4064
Compare
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.
LGTM!
differential rendering (ruby/reline#654) * Add a cut variation of Reline::Unicode.take_range method take_mbchar_range * Consider fullwidth take_range in differential rendering ruby/reline@29714df09f
When dialog is cleared, we need to restore the text that was hidden behind dialogs.
To implement restoring full width characters hidden behind dialog,
Reline::Unicode.take_range
lacks of feature.It does not provide where to render the string. column information is missing.
Sometimes we need other cut variation depending on adjacent dialog position.
The image below shows a variation of
take_range('一二三四五六七八九', 5, 8, option)
So I add
Reline::Unicode.take_mbchar_range
that has optioncover_begin, cover_end, padding
and make it return the actual cut position.