Text wraps in a terrible, horrible way

This commit is contained in:
Bill Rossi 2025-01-07 21:09:12 -05:00
parent b994cb895d
commit 3ab709d1c5

View File

@ -3,6 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
void draw_log(Log* log) { void draw_log(Log* log) {
for(int line_num = 0; line_num < log->line_count; line_num++) { for(int line_num = 0; line_num < log->line_count; line_num++) {
@ -23,11 +24,21 @@ Log *create_log(void) {
return log; return log;
} }
#define MAX(a, b) a > b ? a : b
#define MIN(a, b) a < b ? a : b
#define LINE_LENGTH 60
void push_line_to_log(Log* log, char* line) { void push_line_to_log(Log* log, char* line) {
int line_length = MIN(strlen(line), LINE_LENGTH);
log->lines = realloc(log->lines, (log->line_count + 1) * sizeof(char*));
log->lines[log->line_count] = malloc(line_length + 1);
memcpy(log->lines[log->line_count], line, line_length);
log->lines[log->line_count][line_length] = '\0';
log->line_count++; log->line_count++;
log->lines = realloc(log->lines, log->line_count * sizeof(char*));
log->lines[log->line_count - 1] = malloc(strlen(line) + 1); if (strlen(line) > LINE_LENGTH) {
strcpy(log->lines[log->line_count - 1], line); push_line_to_log(log, line + LINE_LENGTH);
}
} }
void free_log(Log* log) { void free_log(Log* log) {