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_POST, 1L);
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;
}

View File

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