diff options
| author | Miguel <m.i@gmx.at> | 2018-10-14 22:36:16 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-10-14 22:36:16 +0200 |
| commit | 2a6690e9fd53a02613796764248006e06ac482d6 (patch) | |
| tree | ea3063ef3ecd0808e9291faf6c56949d91b1b09e /userspace/ncurses/nc.c | |
| parent | 5aeab1c853e487aa0042d5c32200d623efe908d3 (diff) | |
ported vim et al
Diffstat (limited to 'userspace/ncurses/nc.c')
| -rw-r--r-- | userspace/ncurses/nc.c | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/userspace/ncurses/nc.c b/userspace/ncurses/nc.c new file mode 100644 index 0000000..58be71e --- /dev/null +++ b/userspace/ncurses/nc.c @@ -0,0 +1,200 @@ +// http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/printw.html + +#include <stdio.h> +#include <curses.h> +#include <term.h> + +#define WIDTH 50 +#define HEIGHT 20 + +int startx = 0; +int starty = 0; + + +/* + COLOR_BLACK 0 + COLOR_RED 1 + COLOR_GREEN 2 + COLOR_YELLOW 3 + COLOR_BLUE 4 + COLOR_MAGENTA 5 + COLOR_CYAN 6 + COLOR_WHITE 7 + */ + +char *choices[] = { + "Choice 1", + "Choice 2", + "Choice 3", + "Choice 4", + "Exit", + }; + + +int n_choices = sizeof(choices) / sizeof(char *); + +//void print_menu(WINDOW *menu_win, int highlight); + +int main() +{ + printf("HELLO\n"); + setupterm(getenv("TERM"), 1, (int *)0); + putp(tigetstr("clear")); + putchar('X'); + putp(tparm(tigetstr("cup"),10,10)); + putchar('X'); + printf("BYE\n"); + while(1); + + putp(tigetstr("clear")); + putp("XXX"); + return 0; + + tputs(tparm(tigetstr("cup"),1,5),1,putchar); + tputs(tparm(tigetstr("cup"),5,1),1,putchar); + + return 0; + + for(int i=2;i<40;i+=2) + { +// tputs(tparm(tigetstr("cup"),2,i),1,putchar); + putchar('X'); + } + + tputs(tparm(tigetstr("cup"),1,5),1,putchar); + putchar('X'); + fflush(stdout); + + + endwin(); + + + /* + //printf("x"); + putchar('A'); + tputs("clear",1,putchar); + // putp("buum"); + putchar('B'); + + return 0; + putc('a',stdout); + putchar('\n'); + */ + return 0; +} + +//// int main2() +//// { +//// +//// WINDOW *menu_win; +//// +//// int highlight = 1; +//// int choice = 0; +//// int c; +//// +//// initscr(); +//// clear(); +//// noecho(); +//// cbreak(); /// Line buffering disabled. pass on everything +//// +//// startx = (80 - WIDTH) / 2; +//// starty = (24 - HEIGHT) / 2; +//// +//// start_color(); +//// init_pair(1, COLOR_BLACK, COLOR_WHITE); +//// init_pair(2, COLOR_WHITE, COLOR_BLUE); +//// +//// menu_win = newwin(HEIGHT, WIDTH, starty, startx); +//// wbkgd(menu_win, COLOR_PAIR(2)); +//// +//// keypad(menu_win, TRUE); +//// +//// /* +//// nodelay(menu_win,FALSE); +//// notimeout(menu_win,FALSE); +//// wtimeout(menu_win,-1); +//// */ +//// +//// mvprintw(0, 0, "Use W/S/A/D to go up and down, Press enter to select a choice"); +//// refresh(); +//// print_menu(menu_win, highlight); +//// while(1) +//// { +//// choice=0; +//// int y=0; +//// while(1) +//// { c = wgetch(menu_win); +//// mvprintw(y++,0, "%3d / '%c'", c, c); +//// y%=24; +//// +//// refresh(); +//// switch(c) +//// { case 'w': +//// case KEY_UP: +//// +//// if(highlight == 1) +//// highlight = n_choices; +//// else +//// --highlight; +//// break; +//// +//// case 's': +//// case KEY_DOWN: +//// +//// if(highlight == n_choices) +//// highlight = 1; +//// else +//// ++highlight; +//// break; +//// +//// case 10: +//// +//// choice = highlight; +//// break; +//// } +//// print_menu(menu_win, highlight); +//// if(choice != 0) /* User did a choice come out of the infinite loop */ +//// break; +//// } +//// mvprintw(23, 0, "You chose choice %d with choice string %s\n", choice, choices[choice - 1]); +//// +//// char *argv1[]={"xterm","/bin/fsh",0}; +//// char *env1[]={"HOME=/home/miguel","PS1=\033[34m$\033[37m","PWD=/home/miguel","PATH=/bin","TERM=fool-term",0}; +//// +//// +//// int pid=_fork(); +//// +//// if(pid==0) +//// { +//// _execve("/bin/xterm",argv1,env1); +//// } +//// } +//// +//// clrtoeol(); +//// refresh(); +//// endwin(); +//// return 0; +//// } +//// +//// +//// void print_menu(WINDOW *menu_win, int highlight) +//// { +//// int x, y, i; +//// +//// x = 2; +//// y = 2; +//// +//// box(menu_win, 0, 0); +//// +//// for(i = 0; i < n_choices; ++i) +//// { if(highlight == i + 1) /* High light the present choice */ +//// { wattron(menu_win, COLOR_PAIR(1)); +//// mvwprintw(menu_win, y, x, ">> %40s <<", choices[i]); +//// wattroff(menu_win, COLOR_PAIR(1)); +//// } +//// else +//// mvwprintw(menu_win, y, x, " %40s ", choices[i]); +//// ++y; +//// } +//// wrefresh(menu_win); +//// } |
