Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused things from reline/unicode.rb #759

Merged
merged 4 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ def multiline_off
end
end

private def split_by_width(str, max_width, offset: 0)
Reline::Unicode.split_by_width(str, max_width, encoding, offset: offset)
private def split_line_by_width(str, max_width, offset: 0)
Reline::Unicode.split_line_by_width(str, max_width, encoding, offset: offset)
end

def current_byte_pointer_cursor
Expand Down Expand Up @@ -391,8 +391,8 @@ def wrapped_prompt_and_input_lines
if (cached = cached_wraps[[prompt, line]])
next cached
end
*wrapped_prompts, code_line_prompt = split_by_width(prompt, width).first.compact
wrapped_lines = split_by_width(line, width, offset: calculate_width(code_line_prompt, true)).first.compact
*wrapped_prompts, code_line_prompt = split_line_by_width(prompt, width)
wrapped_lines = split_line_by_width(line, width, offset: calculate_width(code_line_prompt, true))
wrapped_prompts.map { |p| [p, ''] } + [[code_line_prompt, wrapped_lines.first]] + wrapped_lines.drop(1).map { |c| ['', c] }
end
end
Expand Down Expand Up @@ -440,7 +440,7 @@ def render_line_differential(old_items, new_items)
def wrapped_cursor_position
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_line_before_cursor = split_line_by_width(' ' * prompt_width + line_before_cursor, screen_width)
wrapped_cursor_y = wrapped_prompt_and_input_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 All @@ -465,7 +465,7 @@ def render_finished
render_differential([], 0, 0)
lines = @buffer_of_lines.size.times.map do |i|
line = Reline::Unicode.strip_non_printing_start_end(prompt_list[i]) + modified_lines[i]
wrapped_lines, = split_by_width(line, screen_width)
wrapped_lines = split_line_by_width(line, screen_width)
wrapped_lines.last.empty? ? "#{line} " : line
end
@output.puts lines.map { |l| "#{l}\r\n" }.join
Expand Down Expand Up @@ -1582,7 +1582,7 @@ def finish
alias_method :backward_char, :ed_prev_char

private def vi_first_print(key)
@byte_pointer, = Reline::Unicode.vi_first_print(current_line)
@byte_pointer = Reline::Unicode.vi_first_print(current_line)
end

private def ed_move_to_beg(key)
Expand Down Expand Up @@ -1961,23 +1961,23 @@ def finish

private def em_next_word(key)
if current_line.bytesize > @byte_pointer
byte_size, _ = Reline::Unicode.em_forward_word(current_line, @byte_pointer)
byte_size = Reline::Unicode.em_forward_word(current_line, @byte_pointer)
@byte_pointer += byte_size
end
end
alias_method :forward_word, :em_next_word

private def ed_prev_word(key)
if @byte_pointer > 0
byte_size, _ = Reline::Unicode.em_backward_word(current_line, @byte_pointer)
byte_size = Reline::Unicode.em_backward_word(current_line, @byte_pointer)
@byte_pointer -= byte_size
end
end
alias_method :backward_word, :ed_prev_word

private def em_delete_next_word(key)
if current_line.bytesize > @byte_pointer
byte_size, _ = Reline::Unicode.em_forward_word(current_line, @byte_pointer)
byte_size = Reline::Unicode.em_forward_word(current_line, @byte_pointer)
line, word = byteslice!(current_line, @byte_pointer, byte_size)
set_current_line(line)
@kill_ring.append(word)
Expand All @@ -1987,7 +1987,7 @@ def finish

private def ed_delete_prev_word(key)
if @byte_pointer > 0
byte_size, _ = Reline::Unicode.em_backward_word(current_line, @byte_pointer)
byte_size = Reline::Unicode.em_backward_word(current_line, @byte_pointer)
line, word = byteslice!(current_line, @byte_pointer - byte_size, byte_size)
set_current_line(line, @byte_pointer - byte_size)
@kill_ring.append(word, true)
Expand Down Expand Up @@ -2027,7 +2027,7 @@ def finish

private def em_capitol_case(key)
if current_line.bytesize > @byte_pointer
byte_size, _, new_str = Reline::Unicode.em_forward_word_with_capitalization(current_line, @byte_pointer)
byte_size, new_str = Reline::Unicode.em_forward_word_with_capitalization(current_line, @byte_pointer)
before = current_line.byteslice(0, @byte_pointer)
after = current_line.byteslice((@byte_pointer + byte_size)..-1)
set_current_line(before + new_str + after, @byte_pointer + new_str.bytesize)
Expand All @@ -2037,7 +2037,7 @@ def finish

private def em_lower_case(key)
if current_line.bytesize > @byte_pointer
byte_size, = Reline::Unicode.em_forward_word(current_line, @byte_pointer)
byte_size = Reline::Unicode.em_forward_word(current_line, @byte_pointer)
part = current_line.byteslice(@byte_pointer, byte_size).grapheme_clusters.map { |mbchar|
mbchar =~ /[A-Z]/ ? mbchar.downcase : mbchar
}.join
Expand All @@ -2050,7 +2050,7 @@ def finish

private def em_upper_case(key)
if current_line.bytesize > @byte_pointer
byte_size, = Reline::Unicode.em_forward_word(current_line, @byte_pointer)
byte_size = Reline::Unicode.em_forward_word(current_line, @byte_pointer)
part = current_line.byteslice(@byte_pointer, byte_size).grapheme_clusters.map { |mbchar|
mbchar =~ /[a-z]/ ? mbchar.upcase : mbchar
}.join
Expand All @@ -2063,7 +2063,7 @@ def finish

private def em_kill_region(key)
if @byte_pointer > 0
byte_size, _ = Reline::Unicode.em_big_backward_word(current_line, @byte_pointer)
byte_size = Reline::Unicode.em_big_backward_word(current_line, @byte_pointer)
line, deleted = byteslice!(current_line, @byte_pointer - byte_size, byte_size)
set_current_line(line, @byte_pointer - byte_size)
@kill_ring.append(deleted, true)
Expand Down Expand Up @@ -2094,7 +2094,7 @@ def finish

private def vi_next_word(key, arg: 1)
if current_line.bytesize > @byte_pointer
byte_size, _ = Reline::Unicode.vi_forward_word(current_line, @byte_pointer, @drop_terminate_spaces)
byte_size = Reline::Unicode.vi_forward_word(current_line, @byte_pointer, @drop_terminate_spaces)
@byte_pointer += byte_size
end
arg -= 1
Expand All @@ -2103,7 +2103,7 @@ def finish

private def vi_prev_word(key, arg: 1)
if @byte_pointer > 0
byte_size, _ = Reline::Unicode.vi_backward_word(current_line, @byte_pointer)
byte_size = Reline::Unicode.vi_backward_word(current_line, @byte_pointer)
@byte_pointer -= byte_size
end
arg -= 1
Expand All @@ -2112,7 +2112,7 @@ def finish

private def vi_end_word(key, arg: 1, inclusive: false)
if current_line.bytesize > @byte_pointer
byte_size, _ = Reline::Unicode.vi_forward_end_word(current_line, @byte_pointer)
byte_size = Reline::Unicode.vi_forward_end_word(current_line, @byte_pointer)
@byte_pointer += byte_size
end
arg -= 1
Expand All @@ -2127,7 +2127,7 @@ def finish

private def vi_next_big_word(key, arg: 1)
if current_line.bytesize > @byte_pointer
byte_size, _ = Reline::Unicode.vi_big_forward_word(current_line, @byte_pointer)
byte_size = Reline::Unicode.vi_big_forward_word(current_line, @byte_pointer)
@byte_pointer += byte_size
end
arg -= 1
Expand All @@ -2136,7 +2136,7 @@ def finish

private def vi_prev_big_word(key, arg: 1)
if @byte_pointer > 0
byte_size, _ = Reline::Unicode.vi_big_backward_word(current_line, @byte_pointer)
byte_size = Reline::Unicode.vi_big_backward_word(current_line, @byte_pointer)
@byte_pointer -= byte_size
end
arg -= 1
Expand All @@ -2145,7 +2145,7 @@ def finish

private def vi_end_big_word(key, arg: 1, inclusive: false)
if current_line.bytesize > @byte_pointer
byte_size, _ = Reline::Unicode.vi_big_forward_end_word(current_line, @byte_pointer)
byte_size = Reline::Unicode.vi_big_forward_end_word(current_line, @byte_pointer)
@byte_pointer += byte_size
end
arg -= 1
Expand Down
Loading
Loading