text wrapping

This commit is contained in:
2025-04-11 12:19:32 -05:00
parent 9a88b36638
commit b93392a01a

View File

@@ -61,6 +61,22 @@ void Ollama::run() {
ImGui::InputText("url: ", &url); ImGui::InputText("url: ", &url);
static const std::string replace = "\\n";
static const std::string replace_by = "\n";
static std::string print = jsonObj["response"].dump(); print = jsonObj["response"].dump();
static auto pos = print.find(replace); pos = print.find(replace);
while (pos != std::string::npos) {
// Replace the substring with the specified string
print.replace(pos, replace.size(), replace_by);
// Find the next occurrence of the substring
pos = print.find(replace,
pos + replace_by.size());
}
print = "\n\n\n" + print + "\n\n\n";
ImGui::TextWrapped("%s", print.c_str());
ImGui::InputTextMultiline("prompt: ", &s); ImGui::InputTextMultiline("prompt: ", &s);
if(ImGui::Button("send")) { if(ImGui::Button("send")) {
@@ -77,8 +93,7 @@ void Ollama::run() {
result = std::async(curl_easy_perform, curl); result = std::async(curl_easy_perform, curl);
inFlight = true; inFlight = true;
} }
ImGui::Text("%s", jsonObj["response"].dump().c_str());
ImGui::Text("ms per frame: %f", 1000 / io.Framerate); ImGui::Text("ms per frame: %f", 1000 / io.Framerate);
ImGui::End(); ImGui::End();
@@ -90,6 +105,8 @@ void Ollama::run() {
CURLcode code = result.get(); CURLcode code = result.get();
response = oss.str(); response = oss.str();
oss.str(""); oss.str("");
if(code != CURLE_OK) { if(code != CURLE_OK) {
std::cerr << "curl_easy_perform() failed!: " << curl_easy_strerror(code) << std::endl; std::cerr << "curl_easy_perform() failed!: " << curl_easy_strerror(code) << std::endl;
app->stopModule(getName()); app->stopModule(getName());