diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2019-05-31 06:03:18 +0900 |
---|---|---|
committer | Takashi Kokubun <takashikkbn@gmail.com> | 2019-05-31 06:54:00 +0900 |
commit | cb40a21da0687b5dd3cd251c9e66bb0edf67f2b9 (patch) | |
tree | a442d7f71100bd7547bb341371cb7d51e645bb33 /lib/reline | |
parent | 6e052817f95095217b67256aff48cedbd57717cf (diff) | |
download | ruby-cb40a21da0687b5dd3cd251c9e66bb0edf67f2b9.tar.gz |
Warn compile_error only when input is finished
Let's say we are in progress to write `"foo"`:
```
irb> "fo
```
at this moment, nothing is wrong.
It would be just a normal way to write `"foo"`.
Prior to this commit, the `fo` part was warned because of
5b64d7ac6e7cbf759b859428f125539e58bac0bd. But I think warning such a
normal input is not valuable for users.
However, we'd like to warn `:@1` or `@@1` which is also a syntax error.
Then this commit switches the syntax highlight based on whether the
input text is finished or not. When it's not finished yet, it does not
warn compile_error.
Diffstat (limited to 'lib/reline')
-rw-r--r-- | lib/reline/line_editor.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index a8a3f67474..acdc9a2f9c 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -436,6 +436,8 @@ class Reline::LineEditor line = modify_lines(whole_lines)[@line_index] if @is_multiline if finished? + # Always rerender on finish because output_modifier_proc may return a different output. + render_partial(prompt, prompt_width, line) scroll_down(1) Reline::IOGate.move_cursor_column(0) Reline::IOGate.erase_after_cursor @@ -498,7 +500,7 @@ class Reline::LineEditor private def modify_lines(before) return before if before.nil? || before.empty? - if after = @output_modifier_proc&.call("#{before.join("\n")}\n") + if after = @output_modifier_proc&.call("#{before.join("\n")}\n", complete: finished?) after.lines(chomp: true) else before |