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

Completely support full-width characters in differential rendering #629

Closed

Conversation

tompng
Copy link
Member

@tompng tompng commented Jan 2, 2024

(Original pull request: #519)

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.

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]

# Padding space can have different background color
take_mbchar_range("#{RED_BACKGROUND}#{BLUE_BACKGROUND}#{GREEN_BACKGROUND}三", 1, 4, padding: true)
#=> "#{RED_BACKGROUND} #{BLUE_BACKGROUND}二#{GREEN_BACKGROUND} "

@tompng tompng force-pushed the differential_rendering_fullwidth branch from 714326e to 243afdb Compare January 4, 2024 17:20
@tompng tompng changed the title Completely support full-width support in differential rendering Completely support full-width characters in differential rendering Jan 5, 2024
@tompng tompng force-pushed the reline_0.5.0.pre branch 3 times, most recently from 83232d0 to 97d76d8 Compare March 19, 2024 13:12
@ima1zumi ima1zumi deleted the branch ruby:reline_0.5.0.pre March 19, 2024 14:17
@ima1zumi ima1zumi closed this Mar 19, 2024
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.

2 participants