ruby-changes:58282
From: aycabta <ko1@a...>
Date: Thu, 17 Oct 2019 02:20:05 +0900 (JST)
Subject: [ruby-changes:58282] db84123600 (master): Calculate prompt width correctly
https://git.ruby-lang.org/ruby.git/commit/?id=db84123600 From db84123600a2112063441dec4411ab5af6c3a78e Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Thu, 17 Oct 2019 02:19:01 +0900 Subject: Calculate prompt width correctly diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 5ba7039..65ad21f 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -64,11 +64,13 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L64 if @prompt_proc prompt_list = @prompt_proc.(buffer) prompt_list[@line_index] = special_prompt if special_prompt + prompt_list.map!{ special_prompt } if @searching_prompt prompt = prompt_list[@line_index] prompt_width = calculate_width(prompt, true) - [prompt, prompt_list] + [prompt, prompt_width, prompt_list] else - [prompt, nil] + prompt_width = calculate_width(prompt, true) + [prompt, prompt_width, nil] end end @@ -103,7 +105,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L105 end back = 0 new_buffer = whole_lines - prompt, prompt_list = check_multiline_prompt(new_buffer, prompt, special_prompt) + prompt, prompt_width, prompt_list = check_multiline_prompt(new_buffer, prompt, special_prompt) new_buffer.each_with_index do |line, index| prompt_width = calculate_width(prompt_list[index], true) if @prompt_proc width = prompt_width + calculate_width(line) @@ -335,7 +337,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L337 Reline::IOGate.clear_screen @cleared = false back = 0 - prompt, prompt_list = check_multiline_prompt(whole_lines, prompt, special_prompt) + prompt, prompt_width, prompt_list = check_multiline_prompt(whole_lines, prompt, special_prompt) modify_lines(whole_lines).each_with_index do |line, index| if @prompt_proc pr = prompt_list[index] @@ -361,7 +363,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L363 else new_lines = whole_lines end - prompt, prompt_list = check_multiline_prompt(new_lines, prompt, special_prompt) + prompt, prompt_width, prompt_list = check_multiline_prompt(new_lines, prompt, special_prompt) all_height = new_lines.inject(0) { |result, line| result + calculate_height_by_width(prompt_width + calculate_width(line)) # TODO prompt_list } @@ -425,7 +427,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L427 Reline::IOGate.move_cursor_column(0) back = 0 new_buffer = whole_lines - prompt, prompt_list = check_multiline_prompt(new_buffer, prompt, special_prompt) + prompt, prompt_width, prompt_list = check_multiline_prompt(new_buffer, prompt, special_prompt) new_buffer.each_with_index do |line, index| prompt_width = calculate_width(prompt_list[index], true) if @prompt_proc width = prompt_width + calculate_width(line) @@ -477,7 +479,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L479 end line = modify_lines(whole_lines)[@line_index] if @is_multiline - prompt, prompt_list = check_multiline_prompt(whole_lines, prompt, special_prompt) + prompt, prompt_width, prompt_list = check_multiline_prompt(whole_lines, prompt, special_prompt) if finished? # Always rerender on finish because output_modifier_proc may return a different output. render_partial(prompt, prompt_width, line) -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/