summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosias <justjosias@tutanota.com>2020-04-22 16:24:09 +0300
committerJosias <justjosias@tutanota.com>2020-04-22 16:24:09 +0300
commit7426f68feeddf9021ac19fe61472104dc61b7971 (patch)
treee9dc667082cc7082ba4db109e0261b11f6dc8ec4
parent00cfff4484c09865636bc98a624a3c147b98d02e (diff)
Revise Markdown
-rw-r--r--rccat.c5
-rw-r--r--rccat.md23
2 files changed, 14 insertions, 14 deletions
diff --git a/rccat.c b/rccat.c
index 5710b80..683e96c 100644
--- a/rccat.c
+++ b/rccat.c
@@ -20,10 +20,7 @@ const char *colors[7] = {KNRM, KRED, KGRN, KYEL, KBLU, KMAG, KCYN};
int lastcolor = 0;
void printColors(char *text)
{
- if (!(isatty(STDOUT_FILENO))) {
- printf("%s", text);
- return;
- }
+
if (text) {
for (int i = 0; i < strlen(text); ++i) {
int color = 0;
diff --git a/rccat.md b/rccat.md
index 02c847f..9439fc5 100644
--- a/rccat.md
+++ b/rccat.md
@@ -1,4 +1,7 @@
-# rccat
+---
+title: Randomly Colored Cat
+author: Josias Allestad
+---
This program will provide a `cat`-like utility for printing text from a file to `stdout`. Except that output will be randomly colorized.
@@ -52,22 +55,22 @@ const char *colors[7] = {KNRM, KRED, KGRN, KYEL, KBLU, KMAG, KCYN};
These are all the codes for the colors we want, and an array to order them nicely to randomly index them.
-## Print Colors
+# Print Colors
``` {.c #colors-function}
int lastcolor = 0;
void printColors(char *text)
{
- <<notty>>
+ <<colors=notty>>
if (text) {
- <<normal>>
+ <<colors-normal>>
}
- <<reset>>
+ <<colors-reset>>
}
```
If the output is piped (and thus isn't a tty), the colors don't make much sense.
-``` {.c #notty}
+``` {.c #colors-notty}
if (!(isatty(STDOUT_FILENO))) {
printf("%s", text);
return;
@@ -75,7 +78,7 @@ if (!(isatty(STDOUT_FILENO))) {
```
Go through the text character by character and print it with a random color between 0 and 6 (the index of colors). It also makes sure that the color is not the same as the last one.
-``` {.c #normal}
+``` {.c #colors-normal}
for (int i = 0; i < strlen(text); ++i) {
int color = 0;
do {
@@ -87,11 +90,11 @@ for (int i = 0; i < strlen(text); ++i) {
```
Now we have to reset the terminal to the normal colors.
-``` {.c #reset}
+``` {.c #colors-reset}
printf("%s", KWHT);
```
-## Main
+# Main
The main function that every C program must have.
@@ -159,7 +162,7 @@ if (!(fp)) {
fclose(fp);
```
-## Building
+# Building
To compile with your C compiler directly, you can use `gcc -o rccat rccat.c`, but that isn't as useful as a Makefile.