70 lines
1.7 KiB
C
70 lines
1.7 KiB
C
/**
|
|
* \file main.c
|
|
* \author Arthur Barraux
|
|
* \brief Base file of Beluga text editor. Contain fonctions for terminal
|
|
* interactions. \version 0.1 \date 21 septembre 2024
|
|
*/
|
|
|
|
#define _DEFAULT_SOURCE
|
|
#define _BSD_SOURCE
|
|
#define _GNU_SOURCE
|
|
|
|
#include <libgen.h>
|
|
|
|
#include "include/buffer.h"
|
|
#include "include/split_screen.h"
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#include "include/data.h"
|
|
#include "include/init.h"
|
|
#include "include/input.h"
|
|
#include "include/editor_op.h"
|
|
#include "include/terminal.h"
|
|
#include "include/completion.h"
|
|
#include <signal.h>
|
|
|
|
|
|
struct editorConfig E;
|
|
|
|
int main(int argc, char *argv[]) {
|
|
// Get HOME with NULL check
|
|
const char *home = getenv("HOME");
|
|
if (!home) {
|
|
fprintf(stderr, "Error: HOME environment variable not set\n");
|
|
return 1;
|
|
}
|
|
|
|
// Allocate and build splash screen path safely
|
|
char *splash_screen;
|
|
if (asprintf(&splash_screen, "%s/.beluga/assets/beluga.txt", home) == -1) {
|
|
fprintf(stderr, "Error: Failed to allocate splash screen path\n");
|
|
return 1;
|
|
}
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
enableRawMode();
|
|
initEditor();
|
|
|
|
EditorPane *active = splitScreenGetActivePane();
|
|
struct buffer_t *buf;
|
|
|
|
appDebug("splash : %s\n", splash_screen);
|
|
active->buffer_id = bufferCreate(splash_screen, READ_ONLY);
|
|
|
|
if (argc >= 2) {
|
|
active->buffer_id = bufferCreate(argv[1], READ_AND_WRITE);
|
|
buf = &E.buffers[active->buffer_id];
|
|
appDebug("project root : %s\n", dirname(buf->fullname));
|
|
}
|
|
|
|
free(splash_screen); // Now guaranteed safe
|
|
|
|
editorSetStatusMessage("HELP: Ctrl-x Ctrl-s = save | Ctrl-x Ctrl-c = quit");
|
|
while (1) {
|
|
editorRefreshScreen();
|
|
editorProcessKeypress();
|
|
}
|
|
return 0;
|
|
}
|