Skip to content

Commit 05e8ab8

Browse files
committed
The width of Block Elements in Unicode is East Asian Ambiguous
1 parent a92b80e commit 05e8ab8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/reline/line_editor.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ def add_dialog_proc(name, p, context = nil)
692692
bar_height = (bar_max_height * ((dialog.contents.size * 2).to_f / (dialog_render_info.contents.size * 2))).floor.to_i
693693
position = ((bar_max_height - bar_height) * position_ratio).floor.to_i
694694
end
695+
block_elem_size = calculate_width('█')
695696
dialog.contents.each_with_index do |item, i|
696697
if i == pointer
697698
bg_color = '45'
@@ -706,23 +707,23 @@ def add_dialog_proc(name, p, context = nil)
706707
@output.write "\e[#{bg_color}m#{str}"
707708
if dialog_render_info.scrollbar and dialog_render_info.contents.size > height
708709
@output.write "\e[37m"
709-
if position <= (i * 2) and (i * 2 + 1) < (position + bar_height)
710+
if position <= (i * 2) and (i * 2 + block_elem_size) < (position + bar_height)
710711
@output.write '█'
711712
elsif position <= (i * 2) and (i * 2) < (position + bar_height)
712713
@output.write '▀'
713714
str += ''
714-
elsif position <= (i * 2 + 1) and (i * 2) < (position + bar_height)
715+
elsif position <= (i * 2 + block_elem_size) and (i * 2) < (position + bar_height)
715716
@output.write '▄'
716717
else
717-
@output.write ' '
718+
@output.write ' ' * block_elem_size
718719
end
719720
@output.write "\e[39m"
720721
end
721722
@output.write "\e[49m"
722723
Reline::IOGate.move_cursor_column(dialog.column)
723724
move_cursor_down(1) if i < (dialog.contents.size - 1)
724725
end
725-
dialog.width += 1 if dialog_render_info.scrollbar and dialog_render_info.contents.size > height
726+
dialog.width += block_elem_size if dialog_render_info.scrollbar and dialog_render_info.contents.size > height
726727
Reline::IOGate.move_cursor_column(cursor_column)
727728
move_cursor_up(dialog.vertical_offset + dialog.contents.size - 1)
728729
Reline::IOGate.show_cursor

0 commit comments

Comments
 (0)