aboutsummaryrefslogtreecommitdiff
path: root/copenai.c
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2025-06-21 20:33:46 +0100
committerIan C <ianc@noddybox.co.uk>2025-06-21 20:33:46 +0100
commitc018c7ea6d99ea9ece853758622c9f557f9af103 (patch)
tree0759c5e8f815e3a7aaa08b73ee1ded63cf831c14 /copenai.c
Initial skeleton.
Diffstat (limited to 'copenai.c')
-rw-r--r--copenai.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/copenai.c b/copenai.c
new file mode 100644
index 0000000..2417fb2
--- /dev/null
+++ b/copenai.c
@@ -0,0 +1,107 @@
+/*
+
+ copenai - Simple curses interface to an OpenAI server
+
+ Copyright (C) 2025 Ian Cowburn (ianc@noddybox.co.uk)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <unistd.h>
+
+#include <curses.h>
+#include <curl/curl.h>
+
+/* ---------------------------------------- VERSION INFO
+*/
+
+static const char *usage =
+"Version 1.0 development\n"
+"\n"
+"This program is distributed in the hope that it will be useful,\n"
+"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
+"GNU General Public License (Version 3) for more details.\n"
+"\n"
+"usage: copenai base_url\n";
+
+
+/* ---------------------------------------- INPUT WINDOW
+*/
+static void GetInput(WINDOW *w, int y, int x, int cols,
+ char *dest, size_t destlen)
+{
+ dest[0] = 0;
+}
+
+
+/* ---------------------------------------- MAIN CODE
+*/
+static void MainCode(const char *url, const char *apikey)
+{
+ int rows;
+ int cols;
+ WINDOW *input_window;
+ WINDOW *output_window;
+
+ getmaxyx(stdscr, rows, cols);
+
+ input_window = newwin(3, cols, 0, 0);
+ output_window = newwin(rows - 3, cols, 3, 0);
+
+ box(input_window, 0, 0);
+ wrefresh(input_window);
+}
+
+/* ---------------------------------------- MAIN
+*/
+int main(int argc, char *argv[])
+{
+ const char *url = argv[1];
+ const char *apikey = getenv("OPENAI_APIKEY");
+
+ if (!url)
+ {
+ fprintf(stderr, "%s", usage);
+ return EXIT_FAILURE;
+ }
+
+ if (!apikey)
+ {
+ fprintf(stderr, "Missing OPENAI_APIKEY from environment\n");
+ return EXIT_FAILURE;
+ }
+
+ initscr();
+ cbreak();
+ noecho();
+ keypad(stdscr,TRUE);
+
+ MainCode(url, apikey);
+
+ erase();
+ refresh();
+ endwin();
+
+ return EXIT_SUCCESS;
+}
+
+
+/*
+vim: ai sw=4 ts=8 expandtab
+*/