Compare commits
7 Commits
b93392a01a
...
a3b3a9b6e8
| Author | SHA1 | Date | |
|---|---|---|---|
| a3b3a9b6e8 | |||
| e1b93ea51b | |||
| 2261abfe36 | |||
| 143d998654 | |||
| 3e3b87d62e | |||
| 259cc9a3fa | |||
| de559f67a4 |
@@ -27,7 +27,7 @@
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
|
||||
ImguiEmbed = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Archimedes";
|
||||
@@ -53,12 +53,52 @@
|
||||
modules/ImguiModule/src/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.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 \
|
||||
-DRENDERER_OPENGL \
|
||||
-DWINDOW_GLFW \
|
||||
-DGUIMODULE \
|
||||
-DTESTIMGUI_STATIC \
|
||||
-DWINDOWMODULE_STATIC \
|
||||
-I src -I include -I $imgui -I . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
|
||||
43
flake.nix
43
flake.nix
@@ -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 {
|
||||
|
||||
name = "Ollama";
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
89
modules/Terminal/src/Terminal.cpp
Normal file
89
modules/Terminal/src/Terminal.cpp
Normal 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();
|
||||
}
|
||||
20
modules/Terminal/src/Terminal.h
Normal file
20
modules/Terminal/src/Terminal.h
Normal 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
|
||||
31
src/example_apps/TerminalEmbed/TerminalEmbed.cpp
Normal file
31
src/example_apps/TerminalEmbed/TerminalEmbed.cpp
Normal 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
27
src/example_apps/TerminalEmbed/TerminalEmbed.h
Normal file
27
src/example_apps/TerminalEmbed/TerminalEmbed.h
Normal 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"
|
||||
Reference in New Issue
Block a user