commit ec080c8
0uppy
·
2026-07-22 23:28:30 +0000 UTC
parent 01b98b6
cotton v0.2 - added input to cot, still a bit of a placeholder as the implementation is a quick and dirty way of doing it but it works for now i think
2 files changed,
+20,
-5
+16,
-5
1@@ -212,12 +212,23 @@ static void cmd_color(Cotton *cotton, char *arg)
2 fprintf(stderr, "cot syntax error: cotton doesn't know the color \"%s\" sorry,, :(\n", arg);
3 }
4
5-static void cmd_input(CottonWindow *cw, char *arg)
6+static void cmd_input(Cotton *cotton, char *arg)
7 {
8- (void)cw;
9- (void)arg;
10+ if (!arg)
11+ {
12+ fprintf(stderr, "cotton syntax error: input needs a variable name xP\n");
13+ return;
14+ }
15
16- // will work on this for v0.2 or whenever it is that i add variables
17+ char buffer[VAR_VAL_LEN];
18+
19+ // kind of a quick and dirty way of implementing input, i know, but, i cant be arsed to get myself into a potential rabbit hole with SDL so for now i will leave this to be this way,, sorry,,
20+ if (fgets(buffer, sizeof(buffer), stdin) != NULL)
21+ {
22+ buffer[strcspn(buffer, "\r\n")] = '\0';
23+
24+ cotton_store_var(cotton, arg, buffer);
25+ }
26 }
27
28 static void cmd_unknown(const char *cmd)
29@@ -287,7 +298,7 @@ void cotton_interpret(Cotton *cotton, CottonWindow *cw, FILE *file)
30
31 else if (strcmp(cmd, "input") == 0)
32 {
33- cmd_input(cw, arg);
34+ cmd_input(cotton, arg);
35 }
36
37 else if (strcmp(cmd, "kill") == 0)
+4,
-0
1@@ -7,6 +7,10 @@
2
3 int main(int argc, char **argv)
4 {
5+
6+ // added this specifically with the new user input command in mind, makes it so the terminal isnt so cluttered for when there is user input needed, atleast for me :P
7+ printf("\033[2J\033[H");
8+
9 //thank you chld for the idea of changing the scale and having it be optional ^^
10 int scale = 4;
11 char *filename = NULL;