Skip to content

Commit

Permalink
Remove unused code, tweak, add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Mar 19, 2024
1 parent f0f0afc commit 83232d0
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 21 deletions.
1 change: 1 addition & 0 deletions lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination)

if line_editor.eof?
line_editor.reset_line
# Return nil if the input is aborted by C-d.
nil
else
whole_buffer
Expand Down
8 changes: 4 additions & 4 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ module CompletionState
CompletionJourneyData = Struct.new(:preposing, :postposing, :list, :pointer)
MenuInfo = Struct.new(:target, :list)

PROMPT_LIST_CACHE_TIMEOUT = 0.5
MINIMUM_SCROLLBAR_HEIGHT = 1

def initialize(config, encoding)
Expand Down Expand Up @@ -390,8 +389,9 @@ def render_line_differential(old_items, new_items)

# Calculate cursor position in word wrapped content.
def wrapped_cursor_position
line = ' ' * calculate_width(prompt_list[@line_index], true) + whole_lines[@line_index].byteslice(0, @byte_pointer)
wrapped_line_before_cursor = split_by_width(line, screen_width).first.compact
prompt_width = calculate_width(prompt_list[@line_index], true)
line_before_cursor = whole_lines[@line_index].byteslice(0, @byte_pointer)
wrapped_line_before_cursor = split_by_width(' ' * prompt_width + line_before_cursor, screen_width).first.compact
wrapped_cursor_y = wrapped_lines[0...@line_index].sum(&:size) + wrapped_line_before_cursor.size - 1
wrapped_cursor_x = calculate_width(wrapped_line_before_cursor.last)
[wrapped_cursor_x, wrapped_cursor_y]
Expand Down Expand Up @@ -479,6 +479,7 @@ def render_differential

cursor_y = @rendered_screen.cursor_y
if new_lines != rendered_lines
# Hide cursor while rendering to avoid cursor flickering.
Reline::IOGate.hide_cursor
num_lines = [[new_lines.size, rendered_lines.size].max, screen_height].min
if @rendered_screen.base_y + num_lines > screen_height
Expand Down Expand Up @@ -1211,7 +1212,6 @@ def current_line
end

def set_current_line(line, byte_pointer = nil)
@modified = true
cursor = current_byte_pointer_cursor
@buffer_of_lines[@line_index] = line
if byte_pointer
Expand Down
2 changes: 1 addition & 1 deletion test/reline/test_line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_line_increase_decrease
end
end

def test_dialog_apear_disappear
def test_dialog_appear_disappear
assert_output '[COL_3]dialog' do
@line_editor.render_line_differential([[0, 1, 'a']], [[0, 1, 'a'], [3, 6, 'dialog']])
end
Expand Down
4 changes: 0 additions & 4 deletions test/reline/yamatanooroti/multiline_repl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ require 'optparse'
require_relative 'termination_checker'

opt = OptionParser.new
opt.on('--prompt-list-cache-timeout VAL') { |v|
Reline::LineEditor.__send__(:remove_const, :PROMPT_LIST_CACHE_TIMEOUT)
Reline::LineEditor::PROMPT_LIST_CACHE_TIMEOUT = v.to_f
}
opt.on('--dynamic-prompt') {
Reline.prompt_proc = proc { |lines|
lines.each_with_index.map { |l, i|
Expand Down
12 changes: 0 additions & 12 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -501,18 +501,6 @@ def test_binding_for_vi_movement_mode
EOC
end

def test_prompt_list_caching
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --prompt-list-cache-timeout 10 --dynamic-prompt}, startup_message: 'Multiline REPL.')
write("def hoge\n 3\nend")
close
assert_screen(<<~EOC)
Multiline REPL.
[0000]> def hoge
[0001]> 3
[0002]> end
EOC
end

def test_broken_prompt_list
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --broken-dynamic-prompt}, startup_message: 'Multiline REPL.')
write("def hoge\n 3\nend")
Expand Down

0 comments on commit 83232d0

Please sign in to comment.