From 413872dba6100c40cacf59a29ac2015184868b66 Mon Sep 17 00:00:00 2001 From: atomega Date: Wed, 15 Jun 2022 10:28:38 +0200 Subject: [PATCH] learned ncurses up to a basic menu system --- ked/ncurses/instbrave.sh | 11 ++ ked/ncurses/main.c | 252 +++++++++++++++++++++++++++++++-------- ked/ncurses/menu | Bin 17432 -> 18032 bytes 3 files changed, 214 insertions(+), 49 deletions(-) create mode 100755 ked/ncurses/instbrave.sh diff --git a/ked/ncurses/instbrave.sh b/ked/ncurses/instbrave.sh new file mode 100755 index 0000000..120120e --- /dev/null +++ b/ked/ncurses/instbrave.sh @@ -0,0 +1,11 @@ +#!/bin/bash +sudo apt install apt-transport-https curl + +sudo curl -fsSLo /usr/share/keyrings/brave-browser-archive-keyring.gpg https://brave-browser-apt-release.s3.brave.com/brave-browser-archive-keyring.gpg + +echo "deb [signed-by=/usr/share/keyrings/brave-browser-archive-keyring.gpg arch=amd64] https://brave-browser-apt-release.s3.brave.com/ stable main"|sudo tee /etc/apt/sources.list.d/brave-browser-release.list + +sudo apt update + +sudo apt install brave-browser + diff --git a/ked/ncurses/main.c b/ked/ncurses/main.c index d89f96b..0b7afc4 100644 --- a/ked/ncurses/main.c +++ b/ked/ncurses/main.c @@ -3,8 +3,144 @@ **/ #include +//#include int main(int argc, char** argv) +{ + int i, xBeg, yBeg, std_xMax, std_yMax = 0; + int choices, highlight = 0; + char* menu_items[3]={"Menu1", "menu2", "Menu3"}; + + // start of ncurses + initscr(); + noecho(); + cbreak(); + + getmaxyx(stdscr, std_yMax, std_xMax); + + WINDOW * menu_win = newwin(6,std_xMax-5,std_yMax-8,5); + keypad(menu_win, true); // so that we can use the arrow keys + box(menu_win,0,0); + refresh(); + wrefresh(menu_win); + + while(1) + { + for(i = 0; i<3; i++) + { + if(i==highlight) + { + wattron(menu_win, A_REVERSE); + } + + mvwprintw(menu_win, i+1, 1,menu_items[i]); + wattroff(menu_win, A_REVERSE); + } + + choices = wgetch(menu_win); + + switch(choices) + { + case KEY_UP: + highlight --; + if(highlight == -1) + highlight = 0; + break; + + case KEY_DOWN: + highlight ++; + if(highlight == 3) + highlight = 2; + break; + + default: + break; + } + if(choices == 10)// 10 = enter in asci + { + break; + } + } + + printw("your choice was : %s", menu_items[highlight]); + getch(); + endwin(); +} + +int tutorial_0_1() // Hello Word and user input +{ + int c,y,x = 0; + + y=10; + x=10; + + //Init sequence. to set up the screen and init the memory usage + initscr(); // inits the screen and sets up the screen + + move(y,x);// Moving to the given coordinates + + printw("Hello World!"); + //Refeshes the screen to match what is in the memory + refresh(); + + // Gets the user input + c = getch(); + + // Clreasthe screen + clear(); + + move(0,0); + printw("You pressed %d", c); + + // Gets the user input before quiting + getch(); + + // Delocates memory and ends ncurses + endwin(); + return 0; +} + +int tutorial_2() // create a box and write into it +{ + // VAriable declarations + int height, width, start_y, start_x = 0; + height = 10; + width = 30; + start_y = 10; + start_x = 10; + + //Init sequence. to set up the screen and init the memory usage + initscr(); // inits the screen and sets up the screen + + // Creating a window + WINDOW * win= newwin(height,width,start_y, start_x); + //This refresh will initialize the base screen. + refresh(); + + // Making a box out of the window + box(win,0,0); + + // this will print on 0,0 coordinate of rhtis window + wprintw(win,"this is an new window"); + + //and this refresh will only refresh the created window + wrefresh(win); + + //this will moove inside of the window an print to tth given coordinate + mvwprintw(win,5,5,"Content of the box"); + + //and this refresh will only refresh the created window + wrefresh(win); + + // Gets the user input before quiting + getch(); + + // Delocates memory and ends ncurses + endwin(); + return 0; +} + +int tuttorial_3 () // Customize the windows/boxes { // Variable declarations int height, width, start_y, start_x = 0; @@ -72,30 +208,30 @@ int main(int argc, char** argv) return 0; } -int tutorial_0_1() // Hello Word and user input +int tuttorial_4() // Ncurses Tutorial 4 - Attributes and Colors (attron, attroff, has_colors, start_color, init_pair) { - int c,y,x = 0; - - y=10; - x=10; - //Init sequence. to set up the screen and init the memory usage initscr(); // inits the screen and sets up the screen - - move(y,x);// Moving to the given coordinates - printw("Hello World!"); - //Refeshes the screen to match what is in the memory - refresh(); + // To use the standart linux bash commanc lije ctrl-c ctrl-x and so on : Is active as default + cbreak(); - // Gets the user input - c = getch(); + // Doesn't show the pressed char in the scrren + noecho(); - // Clreasthe screen - clear(); + if(!has_colors()) + { + printw("Terminal has no colorsupport"); + getch(); + return -1; + } + start_color(); + init_pair(1, COLOR_BLUE, COLOR_RED); + init_pair(2, COLOR_BLUE, COLOR_YELLOW); - move(0,0); - printw("You pressed %d", c); + attron(COLOR_PAIR(2)); + printw("Hello wold"); + attroff(COLOR_PAIR(2)); // Gets the user input before quiting getch(); @@ -105,42 +241,60 @@ int tutorial_0_1() // Hello Word and user input return 0; } -int tutorial_2() // create a box and write into it +int tuttorial_5() // Get position { - // VAriable declarations - int height, width, start_y, start_x = 0; - height = 10; - width = 30; - start_y = 10; - start_x = 10; - - //Init sequence. to set up the screen and init the memory usage - initscr(); // inits the screen and sets up the screen - - // Creating a window - WINDOW * win= newwin(height,width,start_y, start_x); - //This refresh will initialize the base screen. - refresh(); - - // Making a box out of the window - box(win,0,0); - - // this will print on 0,0 coordinate of rhtis window - wprintw(win,"this is an new window"); + int x, y, xBeg, yBeg, xMax, yMax = 0; + // start of ncurses + initscr(); + noecho(); + cbreak(); - //and this refresh will only refresh the created window - wrefresh(win); + WINDOW * win = newwin(10,20,10,10); + getyx(stdscr, y, x); + getbegyx(win, yBeg, xBeg); + getmaxyx(stdscr, yMax, xMax); - //this will moove inside of the window an print to tth given coordinate - mvwprintw(win,5,5,"Content of the box"); + printw("x:%d y:%d xBeg:%d yBeg:%d xMax:%d yMax:%d",x,y,xBeg,yBeg,xMax,yMax); + mvprintw(yMax/2, xMax/2, "Hello from the middle"); - //and this refresh will only refresh the created window - wrefresh(win); + getch(); + endwin(); + + return 0; +} - // Gets the user input before quiting - getch(); +int tutorial_6() // user inputs +{ + int c, x, y, xBeg, yBeg, xMax, yMax = 0; + // start of ncurses + initscr(); + noecho(); + cbreak(); - // Delocates memory and ends ncurses - endwin(); - return 0; + getmaxyx(stdscr, yMax, xMax); + getyx(stdscr, y, x); + + WINDOW * input_win = newwin(3,xMax-12,yMax-5,5); + + box(input_win,0,0); + keypad(input_win, true); + refresh(); + wrefresh(input_win); + c = wgetch(input_win); + if(c == 'j') + { + mvwprintw(input_win,1,1,"you have pressed j! now press the up arrow key"); + wrefresh(input_win); + } + + c = wgetch(input_win); + if(c == KEY_UP) + { + mvwprintw(input_win,1,1," "); + wrefresh(input_win); + mvwprintw(input_win,1,1,"you have pressed key up"); + wrefresh(input_win); + } + getch(); + endwin(); } diff --git a/ked/ncurses/menu b/ked/ncurses/menu index eb9588943aeba053822f572ad4fde58188b57dea..3f6e4099b67c781705d42a68cfb717be537fd6c8 100755 GIT binary patch literal 18032 zcmeHPeRP!7nZJ`E5WXe>L0Lt46;QA;Bp@kh(HY3V#FHRmf?C00l9`afWF}`aLjo0x zhI*WiadWzEi{09Kx_esJ-JZp5*8=N-AV{zuHm>L*i@VW{b_T4CiZ-s1?C-hvK9hGQ z^R~Kw^z0wGF!#C7@A1?gXluJmI?5sljBqd=gN)%6ag_P8M zF72G6^q8_dlb@mFB8PTSMG%;p?Wk=|ERtezVr4cJ+HRJnY)8#OcBi!6DQ(A8==NgD z?MZDyzhhdSODiCwz?5_;tbaQep!B9IB|C~XDOfONyW3z#<@~&Xn|*`M&#GOP>+&z%C;=Mq`(8PK7oT)VDTJT?D~Bfmbd^pn%y ze*KqEZaRDQ#@DDBU%YhsC<%W#_ z^0o6D7Wgw3_&-?ScUs_$7Wj3*4g7LL2Y`I#{H6u|8t`ctZM`le5cs<8NBSy>wZ?+cn(Ea}k#MlaU)K~AKHt{nNZ8jJ^G9PopOC6~6~mEWePcwl`D3xD zFA^5b+gqZcaI8(VZ4Jii8^O0RP#1|JH__;C_0>n3BGFb63zUR0yL z-S2A%h5b#Tom4B#0rk38&34+=~MZ*`!d4gi|KRY;@R|+tbFs^j% znKjCW8D%amcA9$({Nk5}Celp32p9#D&os&H)pr23ixnn$p_Y^W?LRt=EDJ=fmh-y8 z<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