# File lib/rbreadline.rb, line 1531 def _rl_move_cursor_relative(new, data, start=0) woff = w_offset(@_rl_last_v_pos, @wrap_offset) cpos = @_rl_last_c_pos if !@rl_byte_oriented dpos = _rl_col_width(data, start, start+new) # Use NEW when comparing against the last invisible character in the # prompt string, since they're both buffer indices and DPOS is a desired # display position. if (new > @prompt_last_invisible) # XXX - don't use woff here dpos -= woff # Since this will be assigned to _rl_last_c_pos at the end (more # precisely, _rl_last_c_pos == dpos when this function returns), # let the caller know. @cpos_adjusted = true end else dpos = new end # If we don't have to do anything, then return. if (cpos == dpos) return end if @hConsoleHandle csbi = 0.chr * 24 @GetConsoleScreenBufferInfo.Call(@hConsoleHandle,csbi) x,y = csbi[4,4].unpack('SS') x = dpos @SetConsoleCursorPosition.Call(@hConsoleHandle,y*65536+x) @_rl_last_c_pos = dpos return end # It may be faster to output a CR, and then move forwards instead # of moving backwards. # i == current physical cursor position. if !@rl_byte_oriented i = @_rl_last_c_pos else i = @_rl_last_c_pos - woff end if (dpos == 0 || cr_faster(dpos, @_rl_last_c_pos) || (@_rl_term_autowrap && i == @_rl_screenwidth)) @rl_outstream.write(@_rl_term_cr) cpos = @_rl_last_c_pos = 0 end if (cpos < dpos) # Move the cursor forward. We do it by printing the command # to move the cursor forward if there is one, else print that # portion of the output buffer again. Which is cheaper? # The above comment is left here for posterity. It is faster # to print one character (non-control) than to print a control # sequence telling the terminal to move forward one character. # That kind of control is for people who don't know what the # data is underneath the cursor. # However, we need a handle on where the current display position is # in the buffer for the immediately preceding comment to be true. # In multibyte locales, we don't currently have that info available. # Without it, we don't know where the data we have to display begins # in the buffer and we have to go back to the beginning of the screen # line. In this case, we can use the terminal sequence to move forward # if it's available. if !@rl_byte_oriented if (@_rl_term_forward_char) @rl_outstream.write(@_rl_term_forward_char * (dpos-cpos)) else @rl_outstream.write(@_rl_term_cr) @rl_outstream.write(data[start,new]) end else @rl_outstream.write(data[start+cpos,new-cpos]) end elsif (cpos > dpos) _rl_backspace(cpos - dpos) end @_rl_last_c_pos = dpos end