@@ -72,17 +72,21 @@ def lines(screen_width)
72
72
73
73
MINIMUM_SCROLLBAR_HEIGHT = 1
74
74
75
- def initialize ( config , encoding )
75
+ def initialize ( config )
76
76
@config = config
77
77
@completion_append_character = ''
78
78
@screen_size = [ 0 , 0 ] # Should be initialized with actual winsize in LineEditor#reset
79
- reset_variables ( encoding : encoding )
79
+ reset_variables
80
80
end
81
81
82
82
def io_gate
83
83
Reline ::IOGate
84
84
end
85
85
86
+ def encoding
87
+ io_gate . encoding
88
+ end
89
+
86
90
def set_pasting_state ( in_pasting )
87
91
# While pasting, text to be inserted is stored to @continuous_insertion_buffer.
88
92
# After pasting, this buffer should be force inserted.
@@ -136,9 +140,9 @@ def set_pasting_state(in_pasting)
136
140
end
137
141
end
138
142
139
- def reset ( prompt = '' , encoding : )
143
+ def reset ( prompt = '' )
140
144
@screen_size = Reline ::IOGate . get_screen_size
141
- reset_variables ( prompt , encoding : encoding )
145
+ reset_variables ( prompt )
142
146
@rendered_screen . base_y = Reline ::IOGate . cursor_pos . y
143
147
if ENV . key? ( 'RELINE_ALT_SCROLLBAR' )
144
148
@full_block = '::'
@@ -150,7 +154,7 @@ def reset(prompt = '', encoding:)
150
154
@upper_half_block = '▀'
151
155
@lower_half_block = '▄'
152
156
@block_elem_width = 1
153
- elsif @ encoding == Encoding ::UTF_8
157
+ elsif encoding == Encoding ::UTF_8
154
158
@full_block = '█'
155
159
@upper_half_block = '▀'
156
160
@lower_half_block = '▄'
@@ -219,10 +223,9 @@ def eof?
219
223
@eof
220
224
end
221
225
222
- def reset_variables ( prompt = '' , encoding : )
226
+ def reset_variables ( prompt = '' )
223
227
@prompt = prompt . gsub ( "\n " , "\\ n" )
224
228
@mark_pointer = nil
225
- @encoding = encoding
226
229
@is_multiline = false
227
230
@finished = false
228
231
@history_pointer = nil
@@ -239,7 +242,7 @@ def reset_variables(prompt = '', encoding:)
239
242
@searching_prompt = nil
240
243
@just_cursor_moving = false
241
244
@eof = false
242
- @continuous_insertion_buffer = String . new ( encoding : @ encoding)
245
+ @continuous_insertion_buffer = String . new ( encoding : encoding )
243
246
@scroll_partial_screen = 0
244
247
@drop_terminate_spaces = false
245
248
@in_pasting = false
@@ -259,7 +262,7 @@ def reset_variables(prompt = '', encoding:)
259
262
260
263
def reset_line
261
264
@byte_pointer = 0
262
- @buffer_of_lines = [ String . new ( encoding : @ encoding) ]
265
+ @buffer_of_lines = [ String . new ( encoding : encoding ) ]
263
266
@line_index = 0
264
267
@cache . clear
265
268
@line_backup_in_history = nil
@@ -275,7 +278,7 @@ def multiline_off
275
278
end
276
279
277
280
private def insert_new_line ( cursor_line , next_line )
278
- @buffer_of_lines . insert ( @line_index + 1 , String . new ( next_line , encoding : @ encoding) )
281
+ @buffer_of_lines . insert ( @line_index + 1 , String . new ( next_line , encoding : encoding ) )
279
282
@buffer_of_lines [ @line_index ] = cursor_line
280
283
@line_index += 1
281
284
@byte_pointer = 0
@@ -298,7 +301,7 @@ def multiline_off
298
301
end
299
302
300
303
private def split_by_width ( str , max_width , offset : 0 )
301
- Reline ::Unicode . split_by_width ( str , max_width , @ encoding, offset : offset )
304
+ Reline ::Unicode . split_by_width ( str , max_width , encoding , offset : offset )
302
305
end
303
306
304
307
def current_byte_pointer_cursor
@@ -882,8 +885,8 @@ def editing_mode
882
885
perform_completion ( list , true ) if @config . show_all_if_ambiguous
883
886
end
884
887
if not just_show_list and target < completed
885
- @buffer_of_lines [ @line_index ] = ( preposing + completed + completion_append_character . to_s + postposing ) . split ( "\n " ) [ @line_index ] || String . new ( encoding : @ encoding)
886
- line_to_pointer = ( preposing + completed + completion_append_character . to_s ) . split ( "\n " ) [ @line_index ] || String . new ( encoding : @ encoding)
888
+ @buffer_of_lines [ @line_index ] = ( preposing + completed + completion_append_character . to_s + postposing ) . split ( "\n " ) [ @line_index ] || String . new ( encoding : encoding )
889
+ line_to_pointer = ( preposing + completed + completion_append_character . to_s ) . split ( "\n " ) [ @line_index ] || String . new ( encoding : encoding )
887
890
@byte_pointer = line_to_pointer . bytesize
888
891
end
889
892
end
@@ -1058,8 +1061,8 @@ def wrap_method_call(method_symbol, method_obj, key, with_operator = false)
1058
1061
private def normal_char ( key )
1059
1062
@multibyte_buffer << key . combined_char
1060
1063
if @multibyte_buffer . size > 1
1061
- if @multibyte_buffer . dup . force_encoding ( @ encoding) . valid_encoding?
1062
- process_key ( @multibyte_buffer . dup . force_encoding ( @ encoding) , nil )
1064
+ if @multibyte_buffer . dup . force_encoding ( encoding ) . valid_encoding?
1065
+ process_key ( @multibyte_buffer . dup . force_encoding ( encoding ) , nil )
1063
1066
@multibyte_buffer . clear
1064
1067
else
1065
1068
# invalid
@@ -1317,7 +1320,7 @@ def retrieve_completion_block(set_completion_quote_character = false)
1317
1320
if ( lines . size - 1 ) > @line_index
1318
1321
postposing = postposing + "\n " + lines [ ( @line_index + 1 ) ..-1 ] . join ( "\n " )
1319
1322
end
1320
- [ preposing . encode ( @ encoding) , target . encode ( @ encoding) , postposing . encode ( @ encoding) ]
1323
+ [ preposing . encode ( encoding ) , target . encode ( encoding ) , postposing . encode ( encoding ) ]
1321
1324
end
1322
1325
1323
1326
def confirm_multiline_termination
@@ -1329,7 +1332,7 @@ def insert_multiline_text(text)
1329
1332
save_old_buffer
1330
1333
pre = @buffer_of_lines [ @line_index ] . byteslice ( 0 , @byte_pointer )
1331
1334
post = @buffer_of_lines [ @line_index ] . byteslice ( @byte_pointer ..)
1332
- lines = ( pre + Reline ::Unicode . safe_encode ( text , @ encoding) . gsub ( /\r \n ?/ , "\n " ) + post ) . split ( "\n " , -1 )
1335
+ lines = ( pre + Reline ::Unicode . safe_encode ( text , encoding ) . gsub ( /\r \n ?/ , "\n " ) + post ) . split ( "\n " , -1 )
1333
1336
lines << '' if lines . empty?
1334
1337
@buffer_of_lines [ @line_index , 1 ] = lines
1335
1338
@line_index += lines . size - 1
@@ -1374,7 +1377,7 @@ def delete_text(start = nil, length = nil)
1374
1377
last += current_line . bytesize if last < 0
1375
1378
first += current_line . bytesize if first < 0
1376
1379
range = range . exclude_end? ? first ...last : first ..last
1377
- line = current_line . bytes . reject . with_index { |c , i | range . include? ( i ) } . map { |c | c . chr ( Encoding ::ASCII_8BIT ) } . join . force_encoding ( @ encoding)
1380
+ line = current_line . bytes . reject . with_index { |c , i | range . include? ( i ) } . map { |c | c . chr ( Encoding ::ASCII_8BIT ) } . join . force_encoding ( encoding )
1378
1381
set_current_line ( line )
1379
1382
else
1380
1383
set_current_line ( current_line . byteslice ( 0 , start ) )
@@ -1585,7 +1588,7 @@ def finish
1585
1588
alias_method :end_of_line , :ed_move_to_end
1586
1589
1587
1590
private def generate_searcher ( search_key )
1588
- search_word = String . new ( encoding : @ encoding)
1591
+ search_word = String . new ( encoding : encoding )
1589
1592
multibyte_buf = String . new ( encoding : 'ASCII-8BIT' )
1590
1593
hit_pointer = nil
1591
1594
lambda do |key |
@@ -1602,8 +1605,8 @@ def finish
1602
1605
search_key = key
1603
1606
else
1604
1607
multibyte_buf << key
1605
- if multibyte_buf . dup . force_encoding ( @ encoding) . valid_encoding?
1606
- search_word << multibyte_buf . dup . force_encoding ( @ encoding)
1608
+ if multibyte_buf . dup . force_encoding ( encoding ) . valid_encoding?
1609
+ search_word << multibyte_buf . dup . force_encoding ( encoding )
1607
1610
multibyte_buf . clear
1608
1611
end
1609
1612
end
@@ -1763,7 +1766,7 @@ def finish
1763
1766
@history_pointer = history_pointer
1764
1767
end
1765
1768
@buffer_of_lines = buf . split ( "\n " )
1766
- @buffer_of_lines = [ String . new ( encoding : @ encoding) ] if @buffer_of_lines . empty?
1769
+ @buffer_of_lines = [ String . new ( encoding : encoding ) ] if @buffer_of_lines . empty?
1767
1770
@line_index = line == :start ? 0 : line == :end ? @buffer_of_lines . size - 1 : line
1768
1771
@byte_pointer = cursor == :start ? 0 : cursor == :end ? current_line . bytesize : cursor
1769
1772
end
@@ -2288,7 +2291,7 @@ def finish
2288
2291
}
2289
2292
system ( "#{ ENV [ 'EDITOR' ] } #{ path } " )
2290
2293
@buffer_of_lines = File . read ( path ) . split ( "\n " )
2291
- @buffer_of_lines = [ String . new ( encoding : @ encoding) ] if @buffer_of_lines . empty?
2294
+ @buffer_of_lines = [ String . new ( encoding : encoding ) ] if @buffer_of_lines . empty?
2292
2295
@line_index = 0
2293
2296
finish
2294
2297
end
0 commit comments