MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / put_codepoint

Function put_codepoint

common/console.cpp:295–354  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293 }
294
295 static int put_codepoint(const char* utf8_codepoint, size_t length, int expectedWidth) {
296#if defined(_WIN32)
297 CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
298 if (!GetConsoleScreenBufferInfo(hConsole, &bufferInfo)) {
299 // go with the default
300 return expectedWidth;
301 }
302 COORD initialPosition = bufferInfo.dwCursorPosition;
303 DWORD nNumberOfChars = length;
304 WriteConsole(hConsole, utf8_codepoint, nNumberOfChars, &nNumberOfChars, NULL);
305
306 CONSOLE_SCREEN_BUFFER_INFO newBufferInfo;
307 GetConsoleScreenBufferInfo(hConsole, &newBufferInfo);
308
309 // Figure out our real position if we're in the last column
310 if (utf8_codepoint[0] != 0x09 && initialPosition.X == newBufferInfo.dwSize.X - 1) {
311 DWORD nNumberOfChars;
312 WriteConsole(hConsole, &" \b", 2, &nNumberOfChars, NULL);
313 GetConsoleScreenBufferInfo(hConsole, &newBufferInfo);
314 }
315
316 int width = newBufferInfo.dwCursorPosition.X - initialPosition.X;
317 if (width < 0) {
318 width += newBufferInfo.dwSize.X;
319 }
320 return width;
321#else
322 // We can trust expectedWidth if we've got one
323 if (expectedWidth >= 0 || tty == nullptr) {
324 fwrite(utf8_codepoint, length, 1, out);
325 return expectedWidth;
326 }
327
328 fputs("\033[6n", tty); // Query cursor position
329 int x1;
330 int y1;
331 int x2;
332 int y2;
333 int results = 0;
334 results = fscanf(tty, "\033[%d;%dR", &y1, &x1);
335
336 fwrite(utf8_codepoint, length, 1, tty);
337
338 fputs("\033[6n", tty); // Query cursor position
339 results += fscanf(tty, "\033[%d;%dR", &y2, &x2);
340
341 if (results != 4) {
342 return expectedWidth;
343 }
344
345 int width = x2 - x1;
346 if (width < 0) {
347 // Calculate the width considering text wrapping
348 struct winsize w;
349 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
350 width += w.ws_col;
351 }
352 return width;

Callers 4

replace_lastFunction · 0.85
delete_at_cursorFunction · 0.85
set_line_contentsFunction · 0.85
readline_advancedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected