Skip to content

Commit

Permalink
fix: background color first in lib
Browse files Browse the repository at this point in the history
This change is for swapping color in function on library.

The background color in `cprint` function is first and then the
foreground color. I think is more intuitive.
  • Loading branch information
mdsanima committed Aug 26, 2024
1 parent c304f77 commit cdf84a5
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/mdsanima.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <mdsanima.h>
#include <stdio.h>

void cprint(const char *text, int foreground, int background)
void cprint(const char *text, int background, int foreground)
{
printf("\e[38;5;%dm\e[48;5;%dm\e[1m%s\e[0m\n", foreground, background, text);
printf("\e[48;5;%dm\e[38;5;%dm\e[1m%s\e[0m\n", background, foreground, text);
}
4 changes: 2 additions & 2 deletions lib/mdsanima.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
* @note Wrapper for the ANSI escape sequence, where 0 is black and 255 is white.
*
* @param text The bold text message to stdout print in the color on the terminal.
* @param foreground The foreground color of the text message. A number from 0 to 255.
* @param background The background color of the text message. A number from 0 to 255.
* @param foreground The foreground color of the text message. A number from 0 to 255.
*/
void cprint(const char *text, int foreground, int background);
void cprint(const char *text, int background, int foreground);

#endif
4 changes: 2 additions & 2 deletions project/mdsanima-amarooke/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
int main(void)
{
const char *message = " MDSANIMA AMAROOKE ";
const int fgColor = 38; // Text color
const int bgColor = 26; // Background color
const int fgColor = 38; // Text color

cprint(message, fgColor, bgColor);
cprint(message, bgColor, fgColor);

return 0;
}
4 changes: 2 additions & 2 deletions project/mdsanima-blizzard/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
int main(void)
{
const char *message = " MDSANIMA BLIZZARD ";
const int fgColor = 48; // Text color
const int bgColor = 36; // Background color
const int fgColor = 48; // Text color

cprint(message, fgColor, bgColor);
cprint(message, bgColor, fgColor);

return 0;
}
4 changes: 2 additions & 2 deletions project/mdsanima-conquest/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
int main(void)
{
const char *message = " MDSANIMA CONQUEST ";
const int fgColor = 74; // Text color
const int bgColor = 62; // Background color
const int fgColor = 74; // Text color

cprint(message, fgColor, bgColor);
cprint(message, bgColor, fgColor);

return 0;
}

0 comments on commit cdf84a5

Please sign in to comment.