def update_line(old, ostart, new, current_line, omax, nmax, inv_botlin)
if @encoding == 'X'
old.force_encoding('ASCII-8BIT')
new.force_encoding('ASCII-8BIT')
end
if !@rl_byte_oriented
temp = @_rl_last_c_pos
else
temp = @_rl_last_c_pos - w_offset(@_rl_last_v_pos, @visible_wrap_offset)
end
if (temp == @_rl_screenwidth && @_rl_term_autowrap && !@_rl_horizontal_scroll_mode &&
@_rl_last_v_pos == current_line - 1)
if (!@rl_byte_oriented)
if (@_rl_wrapped_line[current_line] > 0)
_rl_clear_to_eol(@_rl_wrapped_line[current_line])
end
if new[0,1] != 0.chr
case @encoding
when 'E'
wc = new.scan(/./me)[0]
ret = wc.length
tempwidth = wc.length
when 'S'
wc = new.scan(/./ms)[0]
ret = wc.length
tempwidth = wc.length
when 'U'
wc = new.scan(/./mu)[0]
ret = wc.length
tempwidth = wc.unpack('U').first >= 0x1000 ? 2 : 1
when 'X'
wc = new[0..-1].force_encoding(@encoding_name)[0]
ret = wc.bytesize
tempwidth = wc.ord >= 0x1000 ? 2 : 1
else
ret = 1
tempwidth = 1
end
else
tempwidth = 0
end
if (tempwidth > 0)
bytes = ret
@rl_outstream.write(new[0,bytes])
@_rl_last_c_pos = tempwidth
@_rl_last_v_pos+=1
if old[ostart,1] != 0.chr
case @encoding
when 'E'
wc = old[ostart..-1].scan(/./me)[0]
ret = wc.length
when 'S'
wc = old[ostart..-1].scan(/./ms)[0]
ret = wc.length
when 'U'
wc = old[ostart..-1].scan(/./mu)[0]
ret = wc.length
when 'X'
wc = old[ostart..-1].force_encoding(@encoding_name)[0]
ret = wc.bytesize
end
else
ret = 0
end
if (ret != 0 && bytes != 0)
if ret != bytes
len = old[ostart..-1].index(0.chr,ret)
old[ostart+bytes,len-ret] = old[ostart+ret,len-ret]
end
old[ostart,bytes] = new[0,bytes]
end
else
@rl_outstream.write(' ')
@_rl_last_c_pos = 1
@_rl_last_v_pos+=1
if (old[ostart,1] != 0.chr && new[0,1] != 0.chr)
old[ostart,1] = new[0,1]
end
end
else
if (new[0,1] != 0.chr)
@rl_outstream.write(new[0,1])
else
@rl_outstream.write(' ')
end
@_rl_last_c_pos = 1
@_rl_last_v_pos+=1
if (old[ostart,1] != 0.chr && new[0,1] != 0.chr)
old[ostart,1] = new[0,1]
end
end
end
if (!@rl_byte_oriented)
temp = (omax < nmax) ? omax : nmax
if old[ostart,temp]==new[0,temp]
ofd = temp
nfd = temp
else
if (omax == nmax && new[0,omax]==old[ostart,omax])
ofd = omax
nfd = nmax
else
new_offset = 0
old_offset = ostart
ofd = 0
nfd = 0
while(ofd < omax && old[ostart+ofd,1] != 0.chr &&
_rl_compare_chars(old, old_offset, new, new_offset))
old_offset = _rl_find_next_mbchar(old, old_offset, 1, MB_FIND_ANY)
new_offset = _rl_find_next_mbchar(new, new_offset, 1, MB_FIND_ANY)
ofd = old_offset - ostart
nfd = new_offset
end
end
end
else
ofd = 0
nfd = 0
while(ofd < omax && old[ostart+ofd,1] != 0.chr && old[ostart+ofd,1] == new[nfd,1])
ofd += 1
nfd += 1
end
end
oe = old.index(0.chr,ostart+ofd) - ostart
if oe.nil? || oe>omax
oe = omax
end
ne = new.index(0.chr,nfd)
if ne.nil? || ne>omax
ne = nmax
end
if (ofd == oe && nfd == ne)
return
end
wsatend = true
if (!@rl_byte_oriented)
ols = _rl_find_prev_mbchar(old, ostart+oe, MB_FIND_ANY) - ostart
nls = _rl_find_prev_mbchar(new, ne, MB_FIND_ANY)
while ((ols > ofd) && (nls > nfd))
if (!_rl_compare_chars(old, ostart+ols, new, nls))
break
end
if (old[ostart+ols,1] == " ")
wsatend = false
end
ols = _rl_find_prev_mbchar(old, ols+ostart, MB_FIND_ANY) - ostart
nls = _rl_find_prev_mbchar(new, nls, MB_FIND_ANY)
end
else
ols = oe - 1
nls = ne - 1
while ((ols > ofd) && (nls > nfd) && old[ostart+ols,1] == new[nls,1])
if (old[ostart+ols,1] != " ")
wsatend = false
end
ols-=1
nls-=1
end
end
if (wsatend)
ols = oe
nls = ne
elsif (!_rl_compare_chars(old, ostart+ols, new, nls))
if (old[ostart+ols,1] != 0.chr)
if !@rl_byte_oriented
ols = _rl_find_next_mbchar(old, ostart+ols, 1, MB_FIND_ANY) - ostart
else
ols+=1
end
end
if (new[nls,1] != 0.chr )
if !@rl_byte_oriented
nls = _rl_find_next_mbchar(new, nls, 1, MB_FIND_ANY)
else
nls+=1
end
end
end
current_invis_chars = w_offset(current_line, @wrap_offset)
if (@_rl_last_v_pos != current_line)
_rl_move_vert(current_line)
if (@rl_byte_oriented && current_line == 0 && @visible_wrap_offset!=0)
@_rl_last_c_pos += @visible_wrap_offset
end
end
lendiff = @local_prompt_len
if (current_line == 0 && !@_rl_horizontal_scroll_mode &&
@_rl_term_cr && lendiff > @prompt_visible_length && @_rl_last_c_pos > 0 &&
ofd >= lendiff && @_rl_last_c_pos < prompt_ending_index())
@rl_outstream.write(@_rl_term_cr)
_rl_output_some_chars(@local_prompt,0,lendiff)
if !@rl_byte_oriented
@_rl_last_c_pos = _rl_col_width(@local_prompt, 0, lendiff) - @wrap_offset
@cpos_adjusted = true
else
@_rl_last_c_pos = lendiff
end
end
o_cpos = @_rl_last_c_pos
_rl_move_cursor_relative(ofd, old, ostart)
if (current_line == 0 && !@rl_byte_oriented &&
(@_rl_last_c_pos > 0 || o_cpos > 0) &&
@_rl_last_c_pos == @prompt_physical_chars)
@cpos_adjusted = true
end
lendiff = (nls - nfd) - (ols - ofd)
if !@rl_byte_oriented
col_lendiff = _rl_col_width(new, nfd, nls) - _rl_col_width(old, ostart+ofd, ostart+ols)
else
col_lendiff = lendiff
end
if (current_line == 0 && !@_rl_horizontal_scroll_mode &&
current_invis_chars != @visible_wrap_offset)
if !@rl_byte_oriented
lendiff += @visible_wrap_offset - current_invis_chars
col_lendiff += @visible_wrap_offset - current_invis_chars
else
lendiff += @visible_wrap_offset - current_invis_chars
col_lendiff = lendiff
end
end
temp = ne - nfd
if !@rl_byte_oriented
col_temp = _rl_col_width(new,nfd,ne)
else
col_temp = temp
end
if (col_lendiff > 0)
gl = current_line >= @_rl_vis_botlin && inv_botlin > @_rl_vis_botlin
if lendiff < 0
_rl_output_some_chars(new, nfd, temp)
@_rl_last_c_pos += _rl_col_width(new, nfd, nfd+temp)
if current_line == 0 && @wrap_offset && nfd <= @prompt_last_invisible
@_rl_last_c_pos -= @wrap_offset
@cpos_adjusted = true
end
return
elsif (@_rl_terminal_can_insert && ((2 * col_temp) >= col_lendiff || @_rl_term_IC) && (!@_rl_term_autowrap || !gl))
if (old[ostart+ols,1] != 0.chr && (!@_rl_horizontal_scroll_mode || @_rl_last_c_pos > 0 ||
lendiff <= @prompt_visible_length || current_invis_chars==0))
insert_some_chars(new[nfd..-1], lendiff, col_lendiff)
@_rl_last_c_pos += col_lendiff
elsif ((@rl_byte_oriented) && old[ostart+ols,1] == 0.chr && lendiff > 0)
_rl_output_some_chars(new,nfd, lendiff)
@_rl_last_c_pos += col_lendiff
else
_rl_output_some_chars(new,nfd, temp)
@_rl_last_c_pos += col_temp
if current_line == 0 && @wrap_offset && nfd <= @prompt_last_invisible
@_rl_last_c_pos -= @wrap_offset
@cpos_adjusted = true
end
return
end
temp = nls - nfd
if ((temp - lendiff) > 0)
_rl_output_some_chars(new,(nfd + lendiff),temp - lendiff)
@_rl_last_c_pos += _rl_col_width(new,nfd+lendiff, nfd+lendiff+temp-col_lendiff)
end
else
_rl_output_some_chars(new,nfd, temp)
@_rl_last_c_pos += col_temp
end
else
if (@_rl_term_dc && (2 * col_temp) >= -col_lendiff)
if (@_rl_horizontal_scroll_mode && @_rl_last_c_pos == 0 &&
-lendiff == @visible_wrap_offset)
col_lendiff = 0
end
if (col_lendiff!=0)
delete_chars(-col_lendiff)
end
temp = nls - nfd
if (temp > 0)
_rl_output_some_chars(new,nfd, temp)
if !@rl_byte_oriented
@_rl_last_c_pos += _rl_col_width(new,nfd,nfd+temp)
if current_line == 0 && @wrap_offset && nfd <= @prompt_last_invisible
@_rl_last_c_pos -= @wrap_offset
@cpos_adjusted = true
end
else
@_rl_last_c_pos += temp
end
end
else
if (temp > 0)
_rl_output_some_chars(new,nfd, temp)
@_rl_last_c_pos += col_temp
if !@rl_byte_oriented
if current_line == 0 && @wrap_offset && nfd <= @prompt_last_invisible
@_rl_last_c_pos -= @wrap_offset
@cpos_adjusted = true
end
end
end
lendiff = (oe) - (ne)
if !@rl_byte_oriented
col_lendiff = _rl_col_width(old, ostart, ostart+oe) - _rl_col_width(new, 0, ne)
else
col_lendiff = lendiff
end
if (col_lendiff!=0)
if (@_rl_term_autowrap && current_line < inv_botlin)
space_to_eol(col_lendiff)
else
_rl_clear_to_eol(col_lendiff)
end
end
end
end
end