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 eb95889..3f6e409 100755 Binary files a/ked/ncurses/menu and b/ked/ncurses/menu differ