Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ncurses.h>
  3. #include <iostream>
  4. #include <string>
  5. #include <fstream>
  6.  
  7. void initalize_ncurses();
  8.  
  9. int main(int argc, char* argv[]) { // argc is argument count, argv is ./a.out and after
  10.     int ch, curr_row, curr_col, row, col;
  11.     initalize_ncurses();
  12.     getmaxyx(stdscr, row, col);
  13.     while((ch = getch()) != KEY_F(12)) {
  14.         switch(ch) {
  15.             case KEY_UP:
  16.                 getyx(stdscr, curr_row, curr_col);
  17.                 move(curr_row - 1, curr_col);
  18.                 break;
  19.             case KEY_DOWN:
  20.                 getyx(stdscr, curr_row, curr_col);
  21.                 move(curr_row + 1, curr_col);
  22.                 break;
  23.             case KEY_RIGHT:
  24.                 getyx(stdscr, curr_row, curr_col);
  25.                 move(curr_row, curr_col + 1);
  26.                 break;
  27.             case KEY_LEFT:
  28.                 getyx(stdscr, curr_row, curr_col);
  29.                 move(curr_row, curr_col - 1);
  30.                 break;
  31.             case KEY_BACKSPACE:
  32.             case KEY_DC:
  33.             case 127:
  34.                 getyx(stdscr, curr_row, curr_col);
  35.                 move(curr_row, curr_col -1);
  36.                 if(curr_col == 0) { // note : add code to make cursor go to end of string of characters in next iteration
  37.                     move(curr_row-1, 0);
  38.                     break;
  39.                 }
  40.                 delch();
  41.                 //delch();
  42.                 break;
  43.             default:
  44.                 addch(ch);
  45.         }
  46.     }
  47.     endwin();
  48. }
  49.  
  50. void initalize_ncurses() {
  51.     initscr();
  52.     noecho();
  53.     cbreak();
  54.     curs_set(2);
  55.     keypad(stdscr, true);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement