Skip to content

Commit

Permalink
Reline 0.5.0.pre (#614)
Browse files Browse the repository at this point in the history
* Re-architecture LineEditor's internal state and rendering

* Fix test related to LineEditor re-architecture

* Bump to 0.5.0.pre.1

* Hide cursor only when updating screen. Frequent hide&show makes cursor flickering.

* Simplify rerender call from reline.rb

* Simplify handle_cleared

It only need to clear screen. line_editor.rerender will be called later.

* Add description of updating pasting_state inserts continuous_insertion_buffer

* Use meaningful block parameter

Co-authored-by: Stan Lo <[email protected]>

* Fix use of `@cursor_y`

Fix bug updating `@cursor_y`. Do not use `@cursor_y` while updating dialog because it is not current cursor position but cursor position at last rendered time.

* Remove useless instance_variable_set in test

These instance variables are already removed from LineEditor

* Always initialize instance variables to avoid ruby 2.7 warning, remove unused instance variable

* Call update_dialogs from reline.rb before first render

* Combine state representing rendered screen information into `@rendered_screen`

* Rename editor_cursor_ to wrapped_cursor

It represents cursor position of word wrapped whole content

* Remove unused code, tweak, add comment

---------

Co-authored-by: Stan Lo <[email protected]>
  • Loading branch information
tompng and st0012 authored Mar 19, 2024
1 parent 7e2de64 commit 3fa3762
Show file tree
Hide file tree
Showing 11 changed files with 818 additions and 1,418 deletions.
37 changes: 17 additions & 20 deletions lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def initialize
@dialog_proc_list = {}
yield self
@completion_quote_character = nil
@bracketed_paste_finished = false
end

def io_gate
Expand Down Expand Up @@ -278,8 +277,13 @@ def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination)
Reline::HISTORY << whole_buffer
end

line_editor.reset_line if line_editor.whole_buffer.nil?
whole_buffer
if line_editor.eof?
line_editor.reset_line
# Return nil if the input is aborted by C-d.
nil
else
whole_buffer
end
end
end

Expand Down Expand Up @@ -326,7 +330,7 @@ def readline(prompt = '', add_hist = false)
line_editor.prompt_proc = prompt_proc
line_editor.auto_indent_proc = auto_indent_proc
line_editor.dig_perfect_match_proc = dig_perfect_match_proc
line_editor.pre_input_hook = pre_input_hook
pre_input_hook&.call
@dialog_proc_list.each_pair do |name_sym, d|
line_editor.add_dialog_proc(name_sym, d.dialog_proc, d.context)
end
Expand All @@ -337,30 +341,24 @@ def readline(prompt = '', add_hist = false)
io_gate.set_default_key_bindings(config)
end

line_editor.print_nomultiline_prompt(prompt)
line_editor.update_dialogs
line_editor.rerender

begin
line_editor.set_signal_handlers
prev_pasting_state = false
loop do
prev_pasting_state = io_gate.in_pasting?
read_io(config.keyseq_timeout) { |inputs|
line_editor.set_pasting_state(io_gate.in_pasting?)
inputs.each { |c|
line_editor.input_key(c)
line_editor.rerender
}
if @bracketed_paste_finished
line_editor.rerender_all
@bracketed_paste_finished = false
end
inputs.each { |key| line_editor.update(key) }
}
if prev_pasting_state == true and not io_gate.in_pasting? and not line_editor.finished?
line_editor.set_pasting_state(false)
prev_pasting_state = false
line_editor.rerender_all
if line_editor.finished?
line_editor.render_finished
break
else
line_editor.set_pasting_state(io_gate.in_pasting?)
line_editor.rerender
end
break if line_editor.finished?
end
io_gate.move_cursor_column(0)
rescue Errno::EIO
Expand Down Expand Up @@ -395,7 +393,6 @@ def readline(prompt = '', add_hist = false)
c = io_gate.getc(Float::INFINITY)
if c == -1
result = :unmatched
@bracketed_paste_finished = true
else
buffer << c
result = key_stroke.match_status(buffer)
Expand Down
2 changes: 1 addition & 1 deletion lib/reline/general_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def self.ungetc(c)
end

def self.get_screen_size
[1, 1]
[24, 80]
end

def self.cursor_pos
Expand Down
Loading

0 comments on commit 3fa3762

Please sign in to comment.