| 2112 | } |
| 2113 | |
| 2114 | void nextPosition(const char* buf, size_t len, size_t& cpos, size_t& rows, size_t& cols, int plen, |
| 2115 | size_t ws_col) { |
| 2116 | if (isNewline(buf[cpos])) { |
| 2117 | // explicit newline! move to next line and insert a prompt |
| 2118 | rows++; |
| 2119 | cols = plen; |
| 2120 | cpos++; |
| 2121 | if (buf[cpos - 1] == '\r' && cpos < len && buf[cpos] == '\n') { |
| 2122 | cpos++; |
| 2123 | } |
| 2124 | return; |
| 2125 | } |
| 2126 | int sz; |
| 2127 | int char_render_width; |
| 2128 | if (Utf8Proc::utf8ToCodepoint(buf + cpos, sz) < 0) { |
| 2129 | char_render_width = 1; |
| 2130 | cpos++; |
| 2131 | } else { |
| 2132 | char_render_width = (int)Utf8Proc::renderWidth(buf, cpos); |
| 2133 | cpos = utf8proc_next_grapheme(buf, len, cpos); |
| 2134 | } |
| 2135 | if (cols + char_render_width > ws_col) { |
| 2136 | // exceeded l->cols, move to next row |
| 2137 | rows++; |
| 2138 | cols = char_render_width; |
| 2139 | } |
| 2140 | cols += char_render_width; |
| 2141 | } |
| 2142 | |
| 2143 | void positionToColAndRow(size_t target_pos, int& out_row, int& out_col, size_t& rows, size_t& cols, |
| 2144 | struct linenoiseState* l) { |
no test coverage detected