This commit is contained in:
2025-04-12 15:10:13 -05:00
parent 2261abfe36
commit e1b93ea51b
2 changed files with 41 additions and 28 deletions

View File

@@ -90,7 +90,7 @@ void Ollama::run() {
//curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L); //curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
curl_easy_setopt(curl, CURLOPT_POST, 1L); curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, sendObj.dump().c_str()); curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, sendObj.dump().c_str());
result = std::async(curl_easy_perform, curl); result = std::async(std::launch::async, curl_easy_perform, curl);
inFlight = true; inFlight = true;
} }

View File

@@ -120,45 +120,58 @@ void Terminal::onLoad() {
void Terminal::run() { void Terminal::run() {
static char input[150]; static char input[150] = "";
static char output[150]; static std::vector<char> output(150);
static std::string op = "";
static int returnCode; static int returnCode;
static timeval timeout; timeout = { 0, 0 }; static std::future<int> rc;
fd_set fd_in; static fd_set fd_in;
// Wait for data from standard input and master side of PTY // Wait for data from standard input and master side of PTY
FD_ZERO(&fd_in); FD_ZERO(&fd_in);
FD_SET(master, &fd_in); FD_SET(master, &fd_in);
returnCode = select(master + 1, &fd_in, NULL, NULL, &timeout); //returnCode = select(master + 1, &fd_in, NULL, NULL, NULL);
switch(returnCode) { rc = std::async(std::launch::async, [this](fd_set* f) -> int {
case -1: fprintf(stderr, "Error %d on select()\n", errno); return select(master + 1, f, NULL, NULL, NULL);
exit(1); }, &fd_in);
default: { if(rc.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
// If data on master side of PTY switch(rc.get()) {
if (FD_ISSET(master, &fd_in)) { case -1: fprintf(stderr, "Error %d on select()\n", errno);
returnCode = read(master, output, sizeof(output)); exit(1);
if (returnCode > 0) {
} else { default: {
if (returnCode < 0) { // If data on master side of PTY
fprintf(stderr, "Error %d on read master PTY\n", errno); if(FD_ISSET(master, &fd_in)) {
exit(1); returnCode = read(master, output.data(), 150);
} if (returnCode > 0) {
} write(1, output.data(), returnCode);
} op += "\n";
} op += output.data();
} // End switch op += "\n";
output.clear();
} else {
if (returnCode < 0) {
fprintf(stderr, "Error %d on read master PTY\n", errno);
exit(1);
}
}
}
}
} // End switch
}
ImGui::Begin("Terminal Module"); ImGui::Begin("Terminal Module");
ImGui::Text("%s", output); ImGui::TextWrapped("%s", op.c_str());
ImGui::SameLine();
ImGui::InputText("input", input, 150); ImGui::InputText("input", input, 150);
if(ImGui::Button("send")) if(ImGui::Button("send")) {
write(master, input, returnCode); static std::string s; s = input; s += "\n";
write(master, s.c_str(), s.length());
}
ImGui::End(); ImGui::End();