Advertisement
Guest User

Untitled

a guest
Apr 26th, 2020
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <termios.h>
  3. /***************************************************************************/
  4. #include "settings.h"
  5. #include "lib_colors.h"
  6. /**t************************************************************************/
  7. struct lib_strings_colorRGB {
  8.   unsigned char r;
  9.   unsigned char g;
  10.   unsigned char b;
  11.   unsigned char t;
  12. };
  13. /**e************************************************************************/
  14. struct lib_strings_colorRGB lib_strings_ink;
  15. struct lib_strings_colorRGB lib_strings_paper;
  16. /***************************************************************************/
  17. static unsigned char memory[LINE_SIZE*LINE_NUM];
  18. static unsigned int cursor;
  19.  
  20. /***************************************************************************/
  21. void putcharS( char ch )
  22. {
  23.     if (ch<' ') ch='#';
  24.     putchar( ch );
  25.  
  26.     return;
  27. }
  28. /**h*************************************************************************/
  29. extern int lib_screen_init()
  30. {
  31.  
  32.     static struct termios old, current;
  33.  
  34.     tcgetattr(0, &old); /* grab old terminal i/o settings */
  35.     current = old; /* make new settings same as old settings */
  36.     current.c_lflag &= ~ICANON; /* disable buffered i/o */
  37.     current.c_lflag &= ~ECHO; /* set no echo mode */
  38.     tcsetattr(0, TCSANOW, &current); /* use these new terminal i/o settings now */
  39.  
  40.  
  41.     return 0;
  42. }
  43. /**h************************************************************************/
  44. extern int lib_screen_cls()
  45. {
  46.     printf("\033[8;%i;%it",LINE_NUM,LINE_SIZE);
  47.  
  48.     printf("\033[2J");
  49.  
  50.     for(int i=0;i<LINE_SIZE*LINE_NUM;i++)
  51.     {
  52.         memory[i]=' ';
  53.     }
  54.     cursor=0;
  55.     lib_strings_ink=lib_colors_main_ink;
  56.  
  57.     lib_strings_paper=lib_colors_main_backgrownd;
  58.  
  59.     return 0;
  60. }
  61. /**h************************************************************************/
  62. extern int lib_screen_cursor( int x, int y )
  63. {
  64.     cursor=y*LINE_SIZE+x;
  65.     return cursor;
  66. }
  67. /**h************************************************************************/
  68. extern int lib_screen_curGet( )
  69. {
  70.     return cursor;
  71. }
  72. /**h************************************************************************/
  73. extern void lib_screen_curSet( int cur)
  74. {
  75.     cursor=cur;
  76.     return;
  77. }
  78. /**h************************************************************************/
  79. extern unsigned char * lib_screen_ptr( int x, int y )
  80. {
  81.     return &memory[y*LINE_SIZE+x];
  82. }
  83. /**h************************************************************************/
  84. extern unsigned char lib_screen_get( int x, int y )
  85. {
  86.     return memory[y*LINE_SIZE+x];
  87. }
  88. /**h************************************************************************/
  89. extern int lib_screen_print( int n,unsigned char *str )
  90. {
  91.     printf("\033[%i;%iH",cursor / LINE_SIZE+1, cursor % LINE_SIZE+1);
  92.  
  93.     printf("\033[38;2;%i;%i;%im",lib_strings_ink.r,lib_strings_ink.g,lib_strings_ink.b);
  94.     printf("\033[48;2;%i;%i;%im",lib_strings_paper.r,lib_strings_paper.g,lib_strings_paper.b);
  95.  
  96.     for(int i=0;i<n;i++)
  97.     {
  98.         putcharS(memory[cursor]=str[i]);
  99.         cursor++;
  100.         if (cursor>LINE_SIZE*LINE_NUM)
  101.         {
  102.             cursor=0;
  103.         }
  104.     }
  105.     return cursor;
  106. }
  107. /**h************************************************************************/
  108. extern int lib_screen_printC( int n,unsigned char ch )
  109. {
  110.     printf("\033[%i;%iH",cursor / LINE_SIZE+1, cursor % LINE_SIZE+1);
  111.  
  112.     printf("\033[38;2;%i;%i;%im",lib_strings_ink.r,lib_strings_ink.g,lib_strings_ink.b);
  113.     printf("\033[48;2;%i;%i;%im",lib_strings_paper.r,lib_strings_paper.g,lib_strings_paper.b);
  114.  
  115.     for(int i=0;i<n;i++)
  116.     {
  117.         putcharS(memory[cursor]=ch);
  118.         cursor++;
  119.         if (cursor>LINE_SIZE*LINE_NUM)
  120.         {
  121.             cursor=0;
  122.         }
  123.     }
  124.     return cursor;
  125. }
  126. /***************************************************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement