Add: cowsay, splash

This commit is contained in:
xamidev
2024-08-24 21:50:20 +02:00
parent 2893e75ad1
commit 942b4fa88e
7 changed files with 134 additions and 6 deletions

72
src/programs/cowsay.c Normal file
View File

@@ -0,0 +1,72 @@
// Cowsay-like program
// Author: xamidev
// Licensed under the Unlicense. See the repo below.
// https://github.com/xamidev/blankos
#include "../libc/stdio.h"
#include "../libc/string.h"
#define MAX_MSG_LEN 128
const char* cow =
" \\ ^__^\n"
" \\ (oo)\\_______\n"
" (__)\\ )\\/\\\n"
" ||----w |\n"
" || ||\n";
void print_bubble(const char* message)
{
int len = strlen(message);
puts(" ");
for (int i=0; i<len+2; i++)
{
puts("_");
}
puts("\n");
printf("< %s >\n", message);
puts(" ");
for (int i=0; i<len+2; i++)
{
puts("-");
}
puts("\n");
}
void cowsay(char* msg, uint32_t fg, uint32_t bg)
{
print_bubble(msg);
colorputs(cow, fg, bg);
}
void program_cowsay(int argc, char* argv[])
{
if (argc < 2)
{
printf("Usage: %s <message>\n", argv[0]);
return;
}
char message[MAX_MSG_LEN];
message[0] = '\0';
for (int i=1; i<argc; i++)
{
if (strlen(message) + strlen(argv[i]) + 1 < MAX_MSG_LEN)
{
strcat(message, argv[i]);
if (i < argc-1)
{
strcat(message, " ");
}
} else {
puts("Too long message.\n");
return;
}
}
print_bubble(message);
printf("%s", cow);
}