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

Consider fullwidth characters for dialog rendering #519

Closed

Conversation

tompng
Copy link
Member

@tompng tompng commented Mar 17, 2023

When dialog is cleared, we need to restore the text that was hidden behind dialogs.

To implement restoring full width characters hidden behind dialog, take_range lacks of feature.
It does not provide where to render the string. column information is missing.

Reline::Unicode.take_range('一二三四五a', 2, 5) #=> '二三' # should render at column=2
Reline::Unicode.take_range('a一二三四五', 2, 5) #=> '二三' # should render at column=3

Sometimes we need other cut variation depending on adjacent dialog position.
The image below shows a variation of take_range('一二三四五六七八九', 5, 8, option)
dialog_restore

So I add Reline::Unicode.take_mbchar_range that has option cover_begin, cover_end, padding and make it return the actual cut position.

take_mbchar_range('一二三', 1, 4) #=> ['二', 2, 2]
take_mbchar_range('一二三', 1, 4, cover_begin: true) #=> ['一二', 0, 4]
take_mbchar_range('一二三', 1, 4, cover_end: true) #=> ['二三', 2, 4]
take_mbchar_range('一二三', 1, 4, padding: true) #=> [' 二 ', 1, 4]
take_mbchar_range('一二三', 1, 4, cover_begin: true, padding: true) #=> ['一二 ', 0, 5]
take_mbchar_range('一二三', 1, 4, cover_end: true, padding: true) #=> [' 二三', 1, 5]

@tompng tompng mentioned this pull request Mar 17, 2023
@tompng tompng force-pushed the rewrite_dialog_rendering_with_fullwidth_chars branch from 7a9540c to b845e96 Compare March 29, 2023 17:11
@tompng tompng force-pushed the rewrite_dialog_rendering_with_fullwidth_chars branch from b845e96 to d1efadd Compare May 1, 2023 13:02
@tompng tompng marked this pull request as ready for review May 1, 2023 13:37
@@ -193,16 +193,24 @@ def self.split_by_width(str, max_width, encoding = str.encoding)

# Take a chunk of a String cut by width with escape sequences.
def self.take_range(str, start_col, max_width)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is not used now, but I want to leave it as is because this method might be useful to use it from IRB for string truncation in the future.
If we are going to use it from IRB, we should not release Reline that does not have Reline::Unicode.take_range

@tompng tompng marked this pull request as draft November 3, 2023 08:54
@tompng
Copy link
Member Author

tompng commented Nov 3, 2023

TODO: rebase after #595

@tompng
Copy link
Member Author

tompng commented Jan 2, 2024

Closing this because I opened #629

@tompng tompng closed this Jan 2, 2024
@tompng tompng deleted the rewrite_dialog_rendering_with_fullwidth_chars branch March 24, 2024 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant