Compare commits

..

7 Commits

Author SHA1 Message Date
a3b3a9b6e8 use strings and forkpty 2025-04-12 17:16:40 -05:00
e1b93ea51b async 2025-04-12 15:10:13 -05:00
2261abfe36 debug 2025-04-12 13:59:02 -05:00
143d998654 spellcheck 2025-04-12 13:57:26 -05:00
3e3b87d62e TerminalEmbed 2025-04-12 13:44:34 -05:00
259cc9a3fa build 2025-04-12 13:31:36 -05:00
de559f67a4 Terminal 2025-04-12 13:29:50 -05:00
7 changed files with 255 additions and 5 deletions

View File

@@ -27,7 +27,7 @@
''; '';
}; };
ImguiEmbed = pkgs.stdenvNoCC.mkDerivation { ImguiEmbed = pkgs.stdenvNoCC.mkDerivation {
name = "Archimedes"; name = "Archimedes";
@@ -53,12 +53,52 @@
modules/ImguiModule/src/*.cpp \ modules/ImguiModule/src/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \ $imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \ $imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER_OPENGL \
-DWINDOW_GLFW \
-I src -I include -I $imgui -I . \
-lGL -lglfw -lGLEW \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
TerminalEmbed = pkgs.stdenvNoCC.mkDerivation {
name = "Archimedes";
src = ./.;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
];
buildPhase = ''
clang++ \
src/example_apps/TerminalEmbed/*.cpp \
modules/Terminal/src/*.cpp \
modules/WindowModule/src/*.cpp \
modules/ImguiModule/src/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \ $imgui/*.cpp \
-DRENDERER_OPENGL \ -DRENDERER_OPENGL \
-DWINDOW_GLFW \ -DWINDOW_GLFW \
-DGUIMODULE \
-DTESTIMGUI_STATIC \
-DWINDOWMODULE_STATIC \
-I src -I include -I $imgui -I . \ -I src -I include -I $imgui -I . \
-lGL -lglfw -lGLEW \ -lGL -lglfw -lGLEW \
-Wall \ -Wall \

View File

@@ -145,6 +145,49 @@
}; };
Terminal = pkgs.stdenvNoCC.mkDerivation {
name = "Terminal";
src = ./.;
inherit imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
];
buildPhase = ''
clang++ \
modules/Terminal/src/*.cpp \
modules/ImguiModule/src/*.cpp \
modules/WindowModule/src/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER_OPENGL \
-DWINDOW_GLFW \
-DTERMINAL_DYNAMIC \
-fpic -shared \
-I src -I include -I $imgui -I . \
-lGL -lglfw -lGLEW \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
Ollama = pkgs.stdenvNoCC.mkDerivation { Ollama = pkgs.stdenvNoCC.mkDerivation {
name = "Ollama"; name = "Ollama";

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

@@ -0,0 +1,89 @@
#include <errno.h>
#include <unistd.h>
#include <pty.h>
#include <fcntl.h>
#include "Terminal.h"
#include "modules/ImguiModule/src/ImguiModule.h"
Terminal::Terminal(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
name = "Terminal";
ImguiModule* im = new ImguiModule(a, nullptr);
deps[im->getName()] = im;
}
Terminal::~Terminal() {
}
void Terminal::onLoad() {
ImguiModule* im = (ImguiModule*) moduleInstances["ImguiModule"];
if(!im) {
std::cout << "No ImguiModule for Terminal!\n";
std::abort();
}
ImGui::SetCurrentContext(im->getContext());
child_pid = forkpty(&master, nullptr, nullptr, nullptr);
if(!child_pid) {
char* const* args = nullptr;
execvp("bash", args);
}
//fcntl(master, F_SETFL, fcntl(master, F_GETFL, 0) | O_NONBLOCK);
/*
if (master >= 0)
(void)write(master, "ls\n", 3);
*/
}
void Terminal::run() {
static fd_set fds;
static int rc;
static char opArr[150];
static std::string input, output;
static timeval to; to = { 0, 0 };
FD_ZERO(&fds);
FD_SET(master, &fds);
rc = select(master + 1, &fds, NULL, NULL, &to);
switch(rc) {
case -1:
std::cerr << "Error " << errno << " on select()\n";
exit(1);
default:
if(FD_ISSET(master, &fds)) {
rc = read(master, opArr, 150);
if(rc < 0) {
//error on read
app->stopModule(getName());
} else {
if(input == "clear") output = "";
output += opArr;
}
}
}
ImGui::Begin("Terminal Module");
ImGui::TextWrapped("%s", output.c_str());
ImGui::InputText("input", &input);
if(ImGui::Button("send")) {
(void)write(master, (input + "\n").c_str(), input.length() + 1);
}
ImGui::End();
}

View File

@@ -0,0 +1,20 @@
#include "Archimedes.h"
class Terminal : public Archimedes::Module {
public:
Terminal(Archimedes::App*, void*);
~Terminal();
void onLoad();
void run();
private:
int child_pid, master;
};
#ifdef TERMINAL_DYNAMIC
#define MODULE_TYPE Terminal
#include "endModule.h"
#endif

View File

@@ -0,0 +1,31 @@
#include "TerminalEmbed.h"
void TerminalEmbed::run() {
for(auto m : runOrder)
modules[m]->onLoad();
// Main loop
while (!done && !runOrder.empty()) {
for(auto m : runOrder) {
modules[m]->run();
}
for(auto m : toClose) {
unload(m);
}
toClose.clear();
for(auto m : toOpen) {
if(std::holds_alternative<std::string>(m)) {
load(std::get<std::string>(m))->onLoad();
} else {
load(std::get<Archimedes::Module*>(m))->onLoad();
}
}
toOpen.clear();
}
}

View File

@@ -0,0 +1,27 @@
#define ENTRYPOINT
#include "Archimedes.h"
#include "modules/Terminal/src/Terminal.h"
class TerminalEmbed : public Archimedes::App {
private:
void printHelp() {};
public:
TerminalEmbed() {
Archimedes::Module* m = (Archimedes::Module*) new Terminal(Get(), nullptr);
load(m);
};
~TerminalEmbed() {};
void handleArgs(const int& argc, char* argv[]) {};
void run();
};
#define APP_TYPE TerminalEmbed
#include "endApp.h"