Guest User

Untitled

a guest
Jul 24th, 2011
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.92 KB | None | 0 0
  1. #include <curses.h>
  2. #include <signal.h>
  3.  
  4. static void finish(int sig);
  5.  
  6. int main(int argc, char *argv[]){
  7.     int num = 0;
  8.    
  9.     // our data structures should go here
  10.    
  11.     (void) signal(SIGINT,finish); //arrange interrupts to terminate
  12.     (void) initscr();   //initialize curses
  13.     keypad(stdscr, TRUE);   //enable keyboard
  14.     (void) nonl();      //don't do newlines and whatnot
  15.     //(void) cbreak();  //take input chars one at a time
  16.     (void) echo();      //echo input in color
  17.    
  18.    
  19.     //going to make our windows, first we have to get the size of the current terminal
  20.    
  21.     //TODO: resize windows when term is resized
  22.    
  23.     int termwidth = getmaxy(stdscr);
  24.         int termheight = getmaxx(stdscr);
  25.        
  26.         int chanheight = termheight - 1;
  27.        
  28.         WINDOW *channel = newwin(termwidth, chanheight, 0, 0);
  29.     scrollok(channel, TRUE);
  30.            
  31.         WINDOW *input = newwin(termwidth, 1, termheight + 1, 0);
  32.     scrollok(input, TRUE);
  33.            
  34.         wmove(channel, 0, 0);
  35.         wrefresh(input);
  36.         wrefresh(channel);
  37.        
  38.        
  39.         printw("proportions: %i %i", termwidth, termheight);
  40.         wmove(input, 0, 0);
  41.    
  42.     if (has_colors()){
  43.         start_color();  //i assume this initializes colors
  44.        
  45.         //we're setting the various colorset IDs here, I'm planning on
  46.         //using pair 0 for channel text and pair 1 for OOC. pair 2 should
  47.         //be for menus.
  48.        
  49.         init_pair(1, COLOR_RED,     COLOR_BLACK);
  50.         init_pair(2, COLOR_GREEN,   COLOR_BLACK);
  51.         init_pair(3, COLOR_BLACK,   COLOR_WHITE);
  52.     }
  53.    
  54.     //main loop
  55.    
  56.     for (;;) {
  57.         int c = getch(); //on refresh, we get the single keystroke of input
  58.        
  59.         //wmove(channel, 0, 0);
  60.        
  61.         if (c == 101) {
  62.             printw("\nyou pressed e!\n> ");
  63.         } else {
  64.             wprintw(channel, "%c (%i)\n", c, c);
  65.             wprintw(input, "CLAMSAUCE%c", c);
  66.         }
  67.        
  68.         wmove(input, 0, 0);
  69.                
  70.         wrefresh(channel);
  71.         wrefresh(input);
  72.     }
  73.    
  74.     finish(0); //done
  75. }
  76.  
  77. static void finish(int sig){
  78.  
  79.     endwin();
  80.    
  81.     //our wrapup goes here
  82.    
  83.     exit(0);
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment