atm959

Will this code work?

Feb 15th, 2016
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.53 KB | None | 0 0
  1. //Console Tools
  2.  
  3. #include <stdio.h>
  4. #include <3ds.h>
  5. #include <string.h>
  6.  
  7. char[1000] foregroundColorString;
  8. char[1000] backgroundColorString;
  9. char[1000] fullColorString;
  10. char[1000] fullCursorPositionString;
  11.  
  12. //printArt(lineOne, lineTwo, lineThree, lineFour, lineFive, lineSix, lineSeven) - Prints ascii art to the console. Supports up to seven lines.
  13. //clearScreen() - clears the screen of all text.
  14. //setConsoleScreen(direction) - sets the console to be on the top or bottom screen. direction can be "top" or "bottom".
  15. //setConsoleColors(foregroundColor, backgroundColor) - set the colors of the foreground and background of the colsole. Both parameters are strings and can be: "black", "red", "green", "yellow", "blue", "magenta", "cyan",or "white".
  16. //setConsoleColorsToDefault() - sets the console foreground and background colors to default: white text, black background.
  17. //setCursorPosition(x, y) - set the cursor's position to x, y.
  18.  
  19. void printArt(char[1000] lineOne, char[1000] lineTwo, char[1000] lineThree, char[1000] lineFour, char[1000] lineFive, char[1000] lineSix, char[1000] lineSeven){
  20.    
  21.     printf("%s\n", lineOne);
  22.     printf("%s\n", lineTwo);
  23.     printf("%s\n", lineThree);
  24.     printf("%s\n", lineFour);
  25.     printf("%s\n", lineFive);
  26.     printf("%s\n", lineSix);
  27.     printf("%s\n", lineSeven);
  28.    
  29. }
  30.  
  31. void clearScreen(){
  32.    
  33.     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
  34.    
  35. }
  36.  
  37. void setConsoleScreen(char[6] direction){
  38.    
  39.     if(direction == "top"){
  40.        
  41.         consoleInit(GFX_TOP, NULL);
  42.        
  43.     } else if(direction == "bottom"){
  44.        
  45.         consoleInit(GFX_BOTTOM, NULL);
  46.        
  47.     }
  48.    
  49. }
  50.  
  51. void setConsoleColors(String foreGroundColor, String backgroundColor){
  52.    
  53.     if(foreGroundColor == "black"){
  54.        
  55.         memcpy(foregroundColorString, "\x1b[30");
  56.        
  57.     } else if(foregroundColor == "red"){
  58.        
  59.         memcpy(foregroundColorString, "\x1b[31");
  60.        
  61.     } else if(foregroundColor == "green"){
  62.        
  63.         memcpy(foregroundColorString, "\x1b[32");
  64.        
  65.     } else if(foregroundColor == "yellow"){
  66.        
  67.         memcpy(foregroundColorString, "\x1b[33");
  68.        
  69.     } else if(foregroundColor == "blue"){
  70.        
  71.         memcpy(foregroundColorString, "\x1b[34");
  72.        
  73.     } else if(foregroundColor == "magenta"){
  74.        
  75.         memcpy(foregroundColorString, "\x1b[35");
  76.        
  77.     } else if(foregroundColor == "cyan"){
  78.        
  79.         memcpy(foregroundColorString, "\x1b[36");
  80.        
  81.     } else if(foregroundColor == "white"){
  82.        
  83.         memcpy(foregroundColorString, "\x1b[37");
  84.        
  85.     }
  86.    
  87.     if(backGroundColor == "black"){
  88.        
  89.         strcpy(backgroundColorString, ";40m");
  90.        
  91.     } else if(backgroundColor == "red"){
  92.        
  93.         strcpy(backgroundColorString, ";41m");
  94.        
  95.     } else if(backgroundColor == "green"){
  96.        
  97.         strcpy(backgroundColorString, ";42m");
  98.        
  99.     } else if(backgroundColor == "yellow"){
  100.        
  101.         strcpy(backgroundColorString, ";43m");
  102.        
  103.     } else if(backgroundColor == "blue"){
  104.        
  105.         strcpy(backgroundColorString, ";44m");
  106.        
  107.     } else if(backgroundColor == "magenta"){
  108.        
  109.         strcpy(backgroundColorString, ";45m");
  110.        
  111.     } else if(backgroundColor == "cyan"){
  112.        
  113.         strcpy(backgroundColorString, ";46m");
  114.        
  115.     } else if(backgroundColor == "white"){
  116.        
  117.         strcpy(backgroundColorString, ";47m");
  118.        
  119.     }
  120.    
  121.     strcpy(fullColorString, "%s", foregroundColorString);
  122.     strcat(fullColorString, "%s", backgroundColorString);
  123.    
  124.     printf("%s", fullColorString);
  125.    
  126. }
  127.  
  128. void setConsoleColorsToDefault(){
  129.    
  130.     strcpy(fullColorString, "\x1b[39;49m");
  131.    
  132.     printf("%s", fullColorString);
  133.    
  134. }
  135.  
  136. void setCursorPosition(int x, int y){
  137.    
  138.     sprintf(fullCursorPositionString, "\x1b[%d;%dH", x, y);
  139.    
  140.     printf("%s", fullCorsorPositionString);
  141.    
  142. }
Advertisement
Add Comment
Please, Sign In to add comment