Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ncurses.h>
- #include <iostream>
- #include <string>
- #include <fstream>
- void initalize_ncurses();
- int main(int argc, char* argv[]) { // argc is argument count, argv is ./a.out and after
- int ch, curr_row, curr_col, row, col;
- initalize_ncurses();
- getmaxyx(stdscr, row, col);
- while((ch = getch()) != KEY_F(12)) {
- switch(ch) {
- case KEY_UP:
- getyx(stdscr, curr_row, curr_col);
- move(curr_row - 1, curr_col);
- break;
- case KEY_DOWN:
- getyx(stdscr, curr_row, curr_col);
- move(curr_row + 1, curr_col);
- break;
- case KEY_RIGHT:
- getyx(stdscr, curr_row, curr_col);
- move(curr_row, curr_col + 1);
- break;
- case KEY_LEFT:
- getyx(stdscr, curr_row, curr_col);
- move(curr_row, curr_col - 1);
- break;
- case KEY_BACKSPACE:
- case KEY_DC:
- case 127:
- getyx(stdscr, curr_row, curr_col);
- move(curr_row, curr_col -1);
- if(curr_col == 0) { // note : add code to make cursor go to end of string of characters in next iteration
- move(curr_row-1, 0);
- break;
- }
- delch();
- //delch();
- break;
- default:
- addch(ch);
- }
- }
- endwin();
- }
- void initalize_ncurses() {
- initscr();
- noecho();
- cbreak();
- curs_set(2);
- keypad(stdscr, true);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement