Skip to content

Commit

Permalink
[ruby/reline] Better fix for non-UTF-8 default external encoding
Browse files Browse the repository at this point in the history
Previous fix didn't show the cursor or dialogs.  This allows the
dialogs to continue to work.

ruby/reline@651c5f63cc
  • Loading branch information
jeremyevans authored and matzbot committed Oct 8, 2021
1 parent eb4682b commit 55d7f63
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/reline/line_editor.rb
Expand Up @@ -624,7 +624,6 @@ def add_dialog_proc(name, p, context = nil)

DIALOG_DEFAULT_HEIGHT = 20
private def render_dialog(cursor_column)
return unless Encoding.default_external == Encoding::UTF_8
@dialogs.each do |dialog|
render_each_dialog(dialog, cursor_column)
end
Expand Down Expand Up @@ -717,6 +716,13 @@ def add_dialog_proc(name, p, context = nil)
reset_dialog(dialog, old_dialog)
move_cursor_down(dialog.vertical_offset)
Reline::IOGate.move_cursor_column(dialog.column)
if Encoding.default_external == Encoding::UTF_8
full_block = '█'
upper_half_block = '▀'
lower_half_block = '▄'
else
full_block = upper_half_block = lower_half_block = ''
end
dialog.contents.each_with_index do |item, i|
if i == pointer
bg_color = '45'
Expand All @@ -733,12 +739,12 @@ def add_dialog_proc(name, p, context = nil)
if dialog.scrollbar_pos and (dialog.scrollbar_pos != old_dialog.scrollbar_pos or dialog.column != old_dialog.column)
@output.write "\e[37m"
if dialog.scrollbar_pos <= (i * 2) and (i * 2 + 1) < (dialog.scrollbar_pos + bar_height)
@output.write '█'
@output.write full_block
elsif dialog.scrollbar_pos <= (i * 2) and (i * 2) < (dialog.scrollbar_pos + bar_height)
@output.write '▀'
@output.write upper_half_block
str += ''
elsif dialog.scrollbar_pos <= (i * 2 + 1) and (i * 2) < (dialog.scrollbar_pos + bar_height)
@output.write '▄'
@output.write lower_half_block
else
@output.write ' ' * @block_elem_width
end
Expand Down

0 comments on commit 55d7f63

Please sign in to comment.