summaryrefslogtreecommitdiff
path: root/userspace/ncurses
diff options
context:
space:
mode:
Diffstat (limited to 'userspace/ncurses')
-rw-r--r--userspace/ncurses/Makefile11
-rw-r--r--userspace/ncurses/foolstart.c149
-rw-r--r--userspace/ncurses/nc.c200
-rw-r--r--userspace/ncurses/ncurs.c70
4 files changed, 206 insertions, 224 deletions
diff --git a/userspace/ncurses/Makefile b/userspace/ncurses/Makefile
index 5fa350f..e920dc7 100644
--- a/userspace/ncurses/Makefile
+++ b/userspace/ncurses/Makefile
@@ -1,13 +1,14 @@
CC=i686-foolos-gcc
CFLAGS=
CFLAGS+=-O0
-#CFLAGS+=-gstabs
-CFLAGS+=-g
+CFLAGS+=-gstabs
#LDLIBS=-lncurses -lform -lmenu -lpanel -ltinfo
-LDLIBS=-lncurses -ltinfo
+#DLIBS=-ltinfo_g -lncurses_g
+#LDLIBS=-lncurses -ltinfo
+LDLIBS=-ltinfo_g
-foolstart:
+nc:
clean:
- rm -f *.o ncurs foolstart
+ rm -f *.o nc
diff --git a/userspace/ncurses/foolstart.c b/userspace/ncurses/foolstart.c
deleted file mode 100644
index 0b795aa..0000000
--- a/userspace/ncurses/foolstart.c
+++ /dev/null
@@ -1,149 +0,0 @@
-#include <ncurses.h>
-
-// http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/printw.html
-
-#include <stdio.h>
-#include <ncurses.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()
-{ 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(); /* 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);
-}
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);
+//// }
diff --git a/userspace/ncurses/ncurs.c b/userspace/ncurses/ncurs.c
deleted file mode 100644
index 88b6e09..0000000
--- a/userspace/ncurses/ncurs.c
+++ /dev/null
@@ -1,70 +0,0 @@
-#include <ncurses.h>
-#include "../newcalls.h"
-
-void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string)
-{
- int length, x, y;
- float temp;
-
- if(win == NULL)
- win = stdscr;
- getyx(win, y, x);
- if(startx != 0)
- x = startx;
- if(starty != 0)
- y = starty;
- if(width == 0)
- width = 80;
-
- length = strlen(string);
- temp = (width - length)/ 2;
- x = startx + (int)temp;
- mvwprintw(win, y, x, "%s", string);
- refresh();
-}
-
-/*
-int write()
-{
- printf("hi\n");
-}
-*/
-
-int main()
-{
-
- initscr();
-
- //cbreak();
- ////noecho();
-
-if(has_colors() == FALSE)
-
- { endwin();
- printf("Your terminal does not support color\n");
- exit(1);
- }
-
- start_color(); /* Start color */
- init_pair(1, COLOR_RED, COLOR_BLACK);
-
- attron(COLOR_PAIR(1));
- print_in_middle(stdscr, LINES / 2, 0, 0, "Viola !!! In color ...");
- attroff(COLOR_PAIR(1));
- getch();
- print_in_middle(stdscr, LINES / 2, 0, 0, "Fool Masters");
- getch();
- endwin();
-
- //write();
-
-// initscr(); /* Start curses mode */
-// printw("Hello World !!!"); /* Print Hello World */
-// refresh(); /* Print it on to the real screen */
-// getch(); /* Wait for user input */
- //while(1);
-
-// endwin(); /* End curses mode */
-
-// return 0;
-}