From 3ab709d1c5f97327e2ec31a7e8e91e11e75ca33a Mon Sep 17 00:00:00 2001
From: Bill Rossi <bassguitarbill@gmail.com>
Date: Tue, 7 Jan 2025 21:09:12 -0500
Subject: [PATCH] Text wraps in a terrible, horrible way

---
 01_text_adventure/log.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/01_text_adventure/log.c b/01_text_adventure/log.c
index 1a043b1..2a4d85f 100644
--- a/01_text_adventure/log.c
+++ b/01_text_adventure/log.c
@@ -3,6 +3,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <stdio.h>
 
 void draw_log(Log* log) {
   for(int line_num = 0; line_num < log->line_count; line_num++) {
@@ -23,11 +24,21 @@ Log *create_log(void) {
   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) {
+  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->lines = realloc(log->lines, log->line_count * sizeof(char*));
-  log->lines[log->line_count - 1] = malloc(strlen(line) + 1);
-  strcpy(log->lines[log->line_count - 1], line);
+
+  if (strlen(line) > LINE_LENGTH) {
+    push_line_to_log(log, line + LINE_LENGTH);
+  }
 }
 
 void free_log(Log* log) {