summaryrefslogtreecommitdiff
path: root/userspace/ncurses
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-10-13 00:57:28 +0200
committerMiguel <m.i@gmx.at>2018-10-13 00:57:28 +0200
commit279f3336a8f6b31ca38bdd272c73aebd68fa88fe (patch)
treeb4bb4a21a4acf38eb810768ac6c1b099e2f18a58 /userspace/ncurses
parentb461c3558b2fe765a4bac512638b0acf5185b4bb (diff)
ncurses arrow keys working etc
Diffstat (limited to 'userspace/ncurses')
-rw-r--r--userspace/ncurses/Makefile4
-rw-r--r--userspace/ncurses/foolstart.c149
-rw-r--r--userspace/ncurses/ncurs.c5
3 files changed, 151 insertions, 7 deletions
diff --git a/userspace/ncurses/Makefile b/userspace/ncurses/Makefile
index 22bae34..5fa350f 100644
--- a/userspace/ncurses/Makefile
+++ b/userspace/ncurses/Makefile
@@ -7,7 +7,7 @@ CFLAGS+=-g
#LDLIBS=-lncurses -lform -lmenu -lpanel -ltinfo
LDLIBS=-lncurses -ltinfo
-ncurs:
+foolstart:
clean:
- rm -f *.o ncurs
+ rm -f *.o ncurs foolstart
diff --git a/userspace/ncurses/foolstart.c b/userspace/ncurses/foolstart.c
new file mode 100644
index 0000000..0b795aa
--- /dev/null
+++ b/userspace/ncurses/foolstart.c
@@ -0,0 +1,149 @@
+#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/ncurs.c b/userspace/ncurses/ncurs.c
index 26068fa..88b6e09 100644
--- a/userspace/ncurses/ncurs.c
+++ b/userspace/ncurses/ncurs.c
@@ -1,11 +1,6 @@
#include <ncurses.h>
#include "../newcalls.h"
-int dup(int oldfd)
-{
- return _dup2(oldfd,0xffffffff); // dup emulation mode
-}
-
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string)
{
int length, x, y;