-
Notifications
You must be signed in to change notification settings - Fork 90
Use IO's encoding instead of Encoding.default_external #765
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,17 +72,21 @@ def lines(screen_width) | |
|
||
MINIMUM_SCROLLBAR_HEIGHT = 1 | ||
|
||
def initialize(config, encoding) | ||
def initialize(config) | ||
@config = config | ||
@completion_append_character = '' | ||
@screen_size = [0, 0] # Should be initialized with actual winsize in LineEditor#reset | ||
reset_variables(encoding: encoding) | ||
reset_variables | ||
end | ||
|
||
def io_gate | ||
Reline::IOGate | ||
end | ||
|
||
def encoding | ||
io_gate.encoding | ||
end | ||
|
||
def set_pasting_state(in_pasting) | ||
# While pasting, text to be inserted is stored to @continuous_insertion_buffer. | ||
# After pasting, this buffer should be force inserted. | ||
|
@@ -138,7 +142,7 @@ def set_pasting_state(in_pasting) | |
|
||
def reset(prompt = '', encoding:) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parameter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💦 Thanks! Removed! |
||
@screen_size = Reline::IOGate.get_screen_size | ||
reset_variables(prompt, encoding: encoding) | ||
reset_variables(prompt) | ||
@rendered_screen.base_y = Reline::IOGate.cursor_pos.y | ||
if ENV.key?('RELINE_ALT_SCROLLBAR') | ||
@full_block = '::' | ||
|
@@ -150,7 +154,7 @@ def reset(prompt = '', encoding:) | |
@upper_half_block = '▀' | ||
@lower_half_block = '▄' | ||
@block_elem_width = 1 | ||
elsif @encoding == Encoding::UTF_8 | ||
elsif encoding == Encoding::UTF_8 | ||
@full_block = '█' | ||
@upper_half_block = '▀' | ||
@lower_half_block = '▄' | ||
|
@@ -219,10 +223,9 @@ def eof? | |
@eof | ||
end | ||
|
||
def reset_variables(prompt = '', encoding:) | ||
def reset_variables(prompt = '') | ||
@prompt = prompt.gsub("\n", "\\n") | ||
@mark_pointer = nil | ||
@encoding = encoding | ||
@is_multiline = false | ||
@finished = false | ||
@history_pointer = nil | ||
|
@@ -239,7 +242,7 @@ def reset_variables(prompt = '', encoding:) | |
@searching_prompt = nil | ||
@just_cursor_moving = false | ||
@eof = false | ||
@continuous_insertion_buffer = String.new(encoding: @encoding) | ||
@continuous_insertion_buffer = String.new(encoding: encoding) | ||
@scroll_partial_screen = 0 | ||
@drop_terminate_spaces = false | ||
@in_pasting = false | ||
|
@@ -259,7 +262,7 @@ def reset_variables(prompt = '', encoding:) | |
|
||
def reset_line | ||
@byte_pointer = 0 | ||
@buffer_of_lines = [String.new(encoding: @encoding)] | ||
@buffer_of_lines = [String.new(encoding: encoding)] | ||
@line_index = 0 | ||
@cache.clear | ||
@line_backup_in_history = nil | ||
|
@@ -275,7 +278,7 @@ def multiline_off | |
end | ||
|
||
private def insert_new_line(cursor_line, next_line) | ||
@buffer_of_lines.insert(@line_index + 1, String.new(next_line, encoding: @encoding)) | ||
@buffer_of_lines.insert(@line_index + 1, String.new(next_line, encoding: encoding)) | ||
@buffer_of_lines[@line_index] = cursor_line | ||
@line_index += 1 | ||
@byte_pointer = 0 | ||
|
@@ -298,7 +301,7 @@ def multiline_off | |
end | ||
|
||
private def split_by_width(str, max_width, offset: 0) | ||
Reline::Unicode.split_by_width(str, max_width, @encoding, offset: offset) | ||
Reline::Unicode.split_by_width(str, max_width, encoding, offset: offset) | ||
end | ||
|
||
def current_byte_pointer_cursor | ||
|
@@ -882,8 +885,8 @@ def editing_mode | |
perform_completion(list, true) if @config.show_all_if_ambiguous | ||
end | ||
if not just_show_list and target < completed | ||
@buffer_of_lines[@line_index] = (preposing + completed + completion_append_character.to_s + postposing).split("\n")[@line_index] || String.new(encoding: @encoding) | ||
line_to_pointer = (preposing + completed + completion_append_character.to_s).split("\n")[@line_index] || String.new(encoding: @encoding) | ||
@buffer_of_lines[@line_index] = (preposing + completed + completion_append_character.to_s + postposing).split("\n")[@line_index] || String.new(encoding: encoding) | ||
line_to_pointer = (preposing + completed + completion_append_character.to_s).split("\n")[@line_index] || String.new(encoding: encoding) | ||
@byte_pointer = line_to_pointer.bytesize | ||
end | ||
end | ||
|
@@ -1058,8 +1061,8 @@ def wrap_method_call(method_symbol, method_obj, key, with_operator = false) | |
private def normal_char(key) | ||
@multibyte_buffer << key.combined_char | ||
if @multibyte_buffer.size > 1 | ||
if @multibyte_buffer.dup.force_encoding(@encoding).valid_encoding? | ||
process_key(@multibyte_buffer.dup.force_encoding(@encoding), nil) | ||
if @multibyte_buffer.dup.force_encoding(encoding).valid_encoding? | ||
process_key(@multibyte_buffer.dup.force_encoding(encoding), nil) | ||
@multibyte_buffer.clear | ||
else | ||
# invalid | ||
|
@@ -1317,7 +1320,7 @@ def retrieve_completion_block(set_completion_quote_character = false) | |
if (lines.size - 1) > @line_index | ||
postposing = postposing + "\n" + lines[(@line_index + 1)..-1].join("\n") | ||
end | ||
[preposing.encode(@encoding), target.encode(@encoding), postposing.encode(@encoding)] | ||
[preposing.encode(encoding), target.encode(encoding), postposing.encode(encoding)] | ||
end | ||
|
||
def confirm_multiline_termination | ||
|
@@ -1329,7 +1332,7 @@ def insert_multiline_text(text) | |
save_old_buffer | ||
pre = @buffer_of_lines[@line_index].byteslice(0, @byte_pointer) | ||
post = @buffer_of_lines[@line_index].byteslice(@byte_pointer..) | ||
lines = (pre + Reline::Unicode.safe_encode(text, @encoding).gsub(/\r\n?/, "\n") + post).split("\n", -1) | ||
lines = (pre + Reline::Unicode.safe_encode(text, encoding).gsub(/\r\n?/, "\n") + post).split("\n", -1) | ||
lines << '' if lines.empty? | ||
@buffer_of_lines[@line_index, 1] = lines | ||
@line_index += lines.size - 1 | ||
|
@@ -1374,7 +1377,7 @@ def delete_text(start = nil, length = nil) | |
last += current_line.bytesize if last < 0 | ||
first += current_line.bytesize if first < 0 | ||
range = range.exclude_end? ? first...last : first..last | ||
line = current_line.bytes.reject.with_index{ |c, i| range.include?(i) }.map{ |c| c.chr(Encoding::ASCII_8BIT) }.join.force_encoding(@encoding) | ||
line = current_line.bytes.reject.with_index{ |c, i| range.include?(i) }.map{ |c| c.chr(Encoding::ASCII_8BIT) }.join.force_encoding(encoding) | ||
set_current_line(line) | ||
else | ||
set_current_line(current_line.byteslice(0, start)) | ||
|
@@ -1585,7 +1588,7 @@ def finish | |
alias_method :end_of_line, :ed_move_to_end | ||
|
||
private def generate_searcher(search_key) | ||
search_word = String.new(encoding: @encoding) | ||
search_word = String.new(encoding: encoding) | ||
multibyte_buf = String.new(encoding: 'ASCII-8BIT') | ||
hit_pointer = nil | ||
lambda do |key| | ||
|
@@ -1602,8 +1605,8 @@ def finish | |
search_key = key | ||
else | ||
multibyte_buf << key | ||
if multibyte_buf.dup.force_encoding(@encoding).valid_encoding? | ||
search_word << multibyte_buf.dup.force_encoding(@encoding) | ||
if multibyte_buf.dup.force_encoding(encoding).valid_encoding? | ||
search_word << multibyte_buf.dup.force_encoding(encoding) | ||
multibyte_buf.clear | ||
end | ||
end | ||
|
@@ -1763,7 +1766,7 @@ def finish | |
@history_pointer = history_pointer | ||
end | ||
@buffer_of_lines = buf.split("\n") | ||
@buffer_of_lines = [String.new(encoding: @encoding)] if @buffer_of_lines.empty? | ||
@buffer_of_lines = [String.new(encoding: encoding)] if @buffer_of_lines.empty? | ||
@line_index = line == :start ? 0 : line == :end ? @buffer_of_lines.size - 1 : line | ||
@byte_pointer = cursor == :start ? 0 : cursor == :end ? current_line.bytesize : cursor | ||
end | ||
|
@@ -2288,7 +2291,7 @@ def finish | |
} | ||
system("#{ENV['EDITOR']} #{path}") | ||
@buffer_of_lines = File.read(path).split("\n") | ||
@buffer_of_lines = [String.new(encoding: @encoding)] if @buffer_of_lines.empty? | ||
@buffer_of_lines = [String.new(encoding: encoding)] if @buffer_of_lines.empty? | ||
@line_index = 0 | ||
finish | ||
end | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change fails one of irb's test. Should be fixed by ruby/irb#1022