Guest User

Untitled

a guest
Jun 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #ifndef _CONSOLEHELPER_H_
  2. #define _CONSOLEHELPER_H_
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdarg.h>
  7.  
  8. #define CON_BLACK 0
  9. #define CON_RED 1
  10. #define CON_GREEN 2
  11. #define CON_YELLOW 3
  12. #define CON_BLUE 4
  13. #define CON_MAGENTA 5
  14. #define CON_CYAN 6
  15. #define CON_WHITE 7
  16. #define CON_BRIGHT 8
  17. #define CON_BRIGHT_BLACK CON_BLACK | CON_BRIGHT
  18. #define CON_BRIGHT_RED CON_RED | CON_BRIGHT
  19. #define CON_BRIGHT_GREEN CON_GREEN | CON_BRIGHT
  20. #define CON_BRIGHT_YELLOW CON_YELLOW | CON_BRIGHT
  21. #define CON_BRIGHT_BLUE CON_BLUE | CON_BRIGHT
  22. #define CON_BRIGHT_MAGENTA CON_MAGENTA | CON_BRIGHT
  23. #define CON_BRIGHT_CYAN CON_CYAN | CON_BRIGHT
  24. #define CON_BRIGHT_WHITE CON_WHITE | CON_BRIGHT
  25.  
  26.  
  27. void CON_Printf(int x, int y, const char* fmt, ...)
  28. {
  29. char tmpbuf[255];
  30.  
  31. va_list marker;
  32. va_start(marker,fmt);
  33. vsprintf(tmpbuf, fmt, marker);
  34. va_end(marker);
  35.  
  36. printf("\x1b[%d;%dH%s", y, x, tmpbuf);
  37. }
  38.  
  39. void CON_SetColor(u8 foreground, u8 background)
  40. {
  41. u8 bright = foreground & CON_BRIGHT ? 1 : 0;
  42.  
  43. if (bright)
  44. foreground &= ~CON_BRIGHT;
  45.  
  46. printf("\x1b[%d;%d;%dm", 30+foreground, bright, 40+background);
  47. }
  48.  
  49. #endif
Add Comment
Please, Sign In to add comment