commit c21782b

0uppy  ·  2026-07-23 01:02:45 +0000 UTC
parent 33f734d
cotton v0.2 - cot's printing has now been split into print and println
1 files changed,  +30, -10
+30, -10
 1@@ -90,7 +90,7 @@ static void draw_char
 2 // da commands
 3 
 4 static void 
 5-cmd_print(Cotton *cotton, CottonWindow *cw, char *arg)
 6+cmd_pre_print(Cotton *cotton, CottonWindow *cw, char *arg, int newline) // idfk how else to rename this :sob:
 7 {
 8     if (!arg)
 9         return;
10@@ -102,7 +102,12 @@ cmd_print(Cotton *cotton, CottonWindow *cw, char *arg)
11         text = (char *)value;
12     }
13 
14-    printf("%s\n", text);
15+    if (newline) {
16+        printf("%s\n", text);
17+    } else {
18+        printf("%s", text);
19+        fflush(stdout);
20+    }
21 
22     for (int i = 0; text[i] != '\0'; i++) {
23         if (text[i] == '\n') {
24@@ -120,12 +125,26 @@ cmd_print(Cotton *cotton, CottonWindow *cw, char *arg)
25         }
26     }
27 
28-    cotton->cursor_x = 0;
29-    cotton->cursor_y += FONT_HEIGHT + 4;
30-
31+    if (newline) {
32+        cotton->cursor_x = 0;
33+        cotton->cursor_y += FONT_HEIGHT + 4;
34+    }
35+    
36     cottonwindow_update(cw, cotton->video, sizeof(cotton->video[0]) * VIDEO_WIDTH);
37 }
38 
39+static void 
40+cmd_print(Cotton *cotton, CottonWindow *cw, char *arg)
41+{
42+    cmd_pre_print(cotton, cw, arg, 0);
43+}
44+
45+static void 
46+cmd_println(Cotton *cotton, CottonWindow *cw, char *arg)
47+{
48+    cmd_pre_print(cotton, cw, arg, 1);
49+}
50+
51 static void 
52 cmd_var(Cotton *cotton, char *arg)
53 {
54@@ -155,8 +174,7 @@ cmd_clear(Cotton *cotton, CottonWindow *cw)
55     cotton->cursor_x = 0;
56     cotton->cursor_y = 0;
57 
58-    cottonwindow_update(cw, cotton->video,
59-                        sizeof(cotton->video[0]) * VIDEO_WIDTH);
60+    cottonwindow_update(cw, cotton->video, sizeof(cotton->video[0]) * VIDEO_WIDTH);
61 }
62 
63 static void 
64@@ -322,15 +340,17 @@ cotton_interpret(Cotton *cotton, CottonWindow *cw, FILE *file)
65     if (!cmd)
66         return;
67 
68-    // RELEASE THE KRAKE- I MEAN, RELEASE THE GREAT WALL OF COMMANDS !!!
69-    // could i format this better? maybe,, but but i'd say this is readable and
70-    // i think readability is gud so i will keep it nice and green,,, green!! :D
71+    // RELEASE THE KRAKE- I MEAN, RELEASE THE GREAT WALL OF COMMANDS !!! could i format this better? maybe,, but but i'd say this is readable and i think readability is gud so i will keep it nice and green,,, green!! :D
72     char *arg = get_arg(line);
73 
74     if (strcmp(cmd, "print") == 0) {
75         cmd_print(cotton, cw, arg);
76     }
77 
78+    else if (strcmp(cmd, "println") == 0) {
79+        cmd_println(cotton, cw, arg);
80+    }
81+
82     else if (strcmp(cmd, "var") == 0) {
83         cmd_var(cotton, arg);
84     }