MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / readline_simple

Function readline_simple

common/console.cpp:455–490  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

453 }
454
455 static bool readline_simple(std::string & line, bool multiline_input) {
456#if defined(_WIN32)
457 std::wstring wline;
458 if (!std::getline(std::wcin, wline)) {
459 // Input stream is bad or EOF received
460 line.clear();
461 GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
462 return false;
463 }
464
465 int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wline[0], (int)wline.size(), NULL, 0, NULL, NULL);
466 line.resize(size_needed);
467 WideCharToMultiByte(CP_UTF8, 0, &wline[0], (int)wline.size(), &line[0], size_needed, NULL, NULL);
468#else
469 if (!std::getline(std::cin, line)) {
470 // Input stream is bad or EOF received
471 line.clear();
472 return false;
473 }
474#endif
475 if (!line.empty()) {
476 char last = line.back();
477 if (last == '/') { // Always return control on '/' symbol
478 line.pop_back();
479 return false;
480 }
481 if (last == '\\') { // '\\' changes the default action
482 line.pop_back();
483 multiline_input = !multiline_input;
484 }
485 }
486 line += '\n';
487
488 // By default, continue input if multiline_input is set
489 return multiline_input;
490 }
491
492 bool readline(std::string & line, bool multiline_input) {
493 set_display(user_input);

Callers 1

readlineFunction · 0.70

Calls 4

clearMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected