Fix windows build problem: use std::getline

This commit is contained in:
notify 2024-07-03 10:32:35 +08:00
parent 60fc264285
commit 76c9b02623

View File

@ -14,6 +14,7 @@
#else #else
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <iostream>
#endif #endif
#include <QJsonDocument> #include <QJsonDocument>
@ -691,16 +692,15 @@ void Shell::run() {
#ifdef FK_USE_READLINE #ifdef FK_USE_READLINE
char *bytes = readline(prompt); char *bytes = readline(prompt);
#else #else
char *bytes = NULL; char *bytes;
size_t bufsize = 512;
printf("\rfk> "); printf("\rfk> ");
fflush(stdin); fflush(stdin);
int ret = getline(&bytes, &bufsize, stdin); std::string str;
if (ret == -1 || ret == 0) { std::getline(std::cin, str);
free(bytes); if (std::cin.fail()) {
bytes = NULL; bytes = NULL;
} else { } else {
bytes[strlen(bytes) - 1] = '\0'; // remove \n bytes = strdup(str.c_str());
} }
#endif #endif
handleLine(bytes); handleLine(bytes);