Skip to content

Commit

Permalink
The width of Block Elements in Unicode is East Asian Ambiguous
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Sep 6, 2021
1 parent a92b80e commit 05e8ab8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ def add_dialog_proc(name, p, context = nil)
bar_height = (bar_max_height * ((dialog.contents.size * 2).to_f / (dialog_render_info.contents.size * 2))).floor.to_i
position = ((bar_max_height - bar_height) * position_ratio).floor.to_i
end
block_elem_size = calculate_width('█')
dialog.contents.each_with_index do |item, i|
if i == pointer
bg_color = '45'
Expand All @@ -706,23 +707,23 @@ def add_dialog_proc(name, p, context = nil)
@output.write "\e[#{bg_color}m#{str}"
if dialog_render_info.scrollbar and dialog_render_info.contents.size > height
@output.write "\e[37m"
if position <= (i * 2) and (i * 2 + 1) < (position + bar_height)
if position <= (i * 2) and (i * 2 + block_elem_size) < (position + bar_height)
@output.write '█'
elsif position <= (i * 2) and (i * 2) < (position + bar_height)
@output.write '▀'
str += ''
elsif position <= (i * 2 + 1) and (i * 2) < (position + bar_height)
elsif position <= (i * 2 + block_elem_size) and (i * 2) < (position + bar_height)
@output.write '▄'
else
@output.write ' '
@output.write ' ' * block_elem_size
end
@output.write "\e[39m"
end
@output.write "\e[49m"
Reline::IOGate.move_cursor_column(dialog.column)
move_cursor_down(1) if i < (dialog.contents.size - 1)
end
dialog.width += 1 if dialog_render_info.scrollbar and dialog_render_info.contents.size > height
dialog.width += block_elem_size if dialog_render_info.scrollbar and dialog_render_info.contents.size > height
Reline::IOGate.move_cursor_column(cursor_column)
move_cursor_up(dialog.vertical_offset + dialog.contents.size - 1)
Reline::IOGate.show_cursor
Expand Down

0 comments on commit 05e8ab8

Please sign in to comment.