135 lines
3.8 KiB
C
135 lines
3.8 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "draw.h"
|
|
#include "main.h"
|
|
#include "gui.h"
|
|
|
|
int main(int argc, char *argv[]) {
|
|
int use_tui = 0;
|
|
char* filename = NULL;
|
|
for (int i = 1; i < argc; i++) {
|
|
if (strcmp(argv[i], "-t") == 0) {
|
|
use_tui = 1;
|
|
} else if (filename == NULL && argv[i][0] != '-') {
|
|
filename = argv[i];
|
|
}
|
|
}
|
|
|
|
char* data = NULL;
|
|
size_t data_len = 0;
|
|
|
|
if (filename != NULL) {
|
|
// Read from file
|
|
FILE *f = fopen(filename, "rb");
|
|
if (f == NULL) {
|
|
perror("Error opening file");
|
|
return 1;
|
|
}
|
|
fseek(f, 0, SEEK_END);
|
|
data_len = ftell(f);
|
|
fseek(f, 0, SEEK_SET);
|
|
|
|
data = malloc(data_len + 1);
|
|
if (data == NULL) {
|
|
fprintf(stderr, "Memory allocation failed\n");
|
|
fclose(f);
|
|
return 1;
|
|
}
|
|
size_t read_bytes = fread(data, 1, data_len, f);
|
|
data[read_bytes] = '\0';
|
|
data_len = read_bytes;
|
|
fclose(f);
|
|
}
|
|
|
|
if (use_tui) {
|
|
char input[4096];
|
|
if (data == NULL) {
|
|
// Get input from user
|
|
drawEdges();
|
|
drawEmptyLines(1);
|
|
drawTitle(TITLE);
|
|
drawEmptyLines(1);
|
|
drawEdges();
|
|
|
|
getUserInput(input, "What's weighing on your soul?");
|
|
data = strdup(input);
|
|
data_len = strlen(data);
|
|
}
|
|
|
|
if (data == NULL || strlen(data) == 0) {
|
|
printf("The void remains silent. (No input provided)\n");
|
|
free(data);
|
|
return 0;
|
|
}
|
|
|
|
// Main interaction loop
|
|
int choice = -1;
|
|
while (choice != 0) {
|
|
printf("\033[H\033[J"); // Clear screen
|
|
drawEdges();
|
|
drawEmptyLines(1);
|
|
drawTitle("THE VOID AWAITS");
|
|
drawEmptyLines(1);
|
|
|
|
if (filename != NULL) {
|
|
char file_info[256];
|
|
snprintf(file_info, sizeof(file_info), "File: %s (%zu bytes)", filename, data_len);
|
|
drawTitle(file_info);
|
|
} else {
|
|
// Show a preview of the string
|
|
char preview[100];
|
|
strncpy(preview, data, 96);
|
|
preview[96] = '\0';
|
|
if (strlen(data) > 96) strcat(preview, "...");
|
|
drawTitle(preview);
|
|
}
|
|
|
|
drawEmptyLines(1);
|
|
drawEdges();
|
|
drawEmptyLines(1);
|
|
drawTitle("1. Scream it into the void (Standard)");
|
|
drawTitle("2. Let it burn (Fire)");
|
|
drawTitle("3. Let it dissolve (Acid)");
|
|
drawTitle("0. Keep it to yourself (Exit)");
|
|
drawEmptyLines(1);
|
|
drawEdges();
|
|
|
|
printf("Choose your release: ");
|
|
if (scanf("%d", &choice) != 1) {
|
|
while (getchar() != '\n'); // clear buffer
|
|
continue;
|
|
}
|
|
|
|
switch (choice) {
|
|
case 1:
|
|
screamIntoVoid(data);
|
|
choice = 0; // Exit after screaming
|
|
break;
|
|
case 2:
|
|
burnText(data);
|
|
choice = 0;
|
|
break;
|
|
case 3:
|
|
dissolveText(data);
|
|
choice = 0;
|
|
break;
|
|
case 0:
|
|
break;
|
|
default:
|
|
printf("Invalid choice.\n");
|
|
sleep_ms(1000);
|
|
break;
|
|
}
|
|
}
|
|
|
|
free(data);
|
|
return 0;
|
|
} else {
|
|
// Run GUI
|
|
int status = run_gui(argc, argv, data ? data : "");
|
|
free(data);
|
|
return status;
|
|
}
|
|
}
|