aboutsummaryrefslogtreecommitdiff
path: root/copenai.c
blob: 2417fb2305654b25805dc41413936c8cf74de2c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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
*/