ruby-changes:58288
From: aycabta <ko1@a...>
Date: Thu, 17 Oct 2019 16:36:23 +0900 (JST)
Subject: [ruby-changes:58288] 60a0c20cb6 (master): Refactor prompt generation logic
https://git.ruby-lang.org/ruby.git/commit/?id=60a0c20cb6 From 60a0c20cb637ac3b2edc561dbc5888fae290b0e6 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Thu, 17 Oct 2019 16:35:11 +0900 Subject: Refactor prompt generation logic diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 65ad21f..3a7ba3e 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -60,11 +60,20 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L60 reset_variables end - private def check_multiline_prompt(buffer, prompt, special_prompt) + private def check_multiline_prompt(buffer, prompt) + special_prompt = nil + if @vi_arg + prompt = "(arg: #{@vi_arg}) " + @rerender_all = true + elsif @searching_prompt + prompt = @searching_prompt + @rerender_all = true + else + prompt = @prompt + end 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_list.map!{ prompt } if @vi_arg or @searching_prompt prompt = prompt_list[@line_index] prompt_width = calculate_width(prompt, true) [prompt, prompt_width, prompt_list] @@ -90,22 +99,9 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L99 @rerender_all = true rerender else - special_prompt = nil - if @vi_arg - prompt = "(arg: #{@vi_arg}) " - prompt_width = calculate_width(prompt) - special_prompt = prompt - elsif @searching_prompt - prompt = @searching_prompt - prompt_width = calculate_width(prompt) - special_prompt = prompt - else - prompt = @prompt - prompt_width = calculate_width(prompt, true) - end back = 0 new_buffer = whole_lines - prompt, prompt_width, prompt_list = check_multiline_prompt(new_buffer, prompt, special_prompt) + prompt, prompt_width, prompt_list = check_multiline_prompt(new_buffer, 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) @@ -320,24 +316,11 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L316 move_cursor_up(@highest_in_all - 1 - @first_line_started_from) @menu_info = nil end - special_prompt = nil - if @vi_arg - prompt = "(arg: #{@vi_arg}) " - prompt_width = calculate_width(prompt) - special_prompt = prompt - elsif @searching_prompt - prompt = @searching_prompt - prompt_width = calculate_width(prompt) - special_prompt = prompt - else - prompt = @prompt - prompt_width = calculate_width(prompt, true) - end + prompt, prompt_width, prompt_list = check_multiline_prompt(whole_lines, prompt) if @cleared Reline::IOGate.clear_screen @cleared = false back = 0 - 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] @@ -363,7 +346,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L346 else new_lines = whole_lines end - prompt, prompt_width, prompt_list = check_multiline_prompt(new_lines, prompt, special_prompt) + prompt, prompt_width, prompt_list = check_multiline_prompt(new_lines, prompt) all_height = new_lines.inject(0) { |result, line| result + calculate_height_by_width(prompt_width + calculate_width(line)) # TODO prompt_list } @@ -427,7 +410,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L410 Reline::IOGate.move_cursor_column(0) back = 0 new_buffer = whole_lines - prompt, prompt_width, prompt_list = check_multiline_prompt(new_buffer, prompt, special_prompt) + prompt, prompt_width, prompt_list = check_multiline_prompt(new_buffer, 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) @@ -479,7 +462,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L462 end line = modify_lines(whole_lines)[@line_index] if @is_multiline - prompt, prompt_width, prompt_list = check_multiline_prompt(whole_lines, prompt, special_prompt) + prompt, prompt_width, prompt_list = check_multiline_prompt(whole_lines, 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/