basicmenu.h  1.0.0
integrate a menu in your console program easily
basicmenu.h File Reference

integrate a menu in your console application easily More...

#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>

Go to the source code of this file.

Data Structures

struct  custom_Menu
 a strcuture for menu More...

Enumerations

enum  _COLOR_ {
  BLACK, RED, GREEN, YELLOW,
  BLUE, MAGENTA, CYAN, WHITE
}
 a liste of the colors avilable More...
enum  BOOLEAN { FALSE, TRUE }
 With this enum you don't must to include the stdbool.h to use false and true Remark: with this enum you need to write FALSE and TRUE as uppercase letters More...

Functions

void addNewItem (custom_Menu **mymenu, char newItem[])
 add a new item to the menu
void BG_COLOR_OFF ()
 desactivate the background color for the selected item in the menu
void BG_COLOR_ON (_COLOR_ COLOR)
 activate the background for the selected item in the menu this will display the selected item with diffrent background color
void BOLD_TEXT_OFF ()
 don't show the selected item in bold
void BOLD_TEXT_ON ()
 show the selected item in bold
void dynamic_menu_OFF ()
 desactivate the dynamically this must invoked only if the dynamic_menu_ON() function was invoked previously
void dynamic_menu_ON ()
 make the menu dynamic when you want to select the next item after the latest the first one will be selected automaticly
void FG_COLOR_OFF ()
 desactivate the forground color for the selected item in the menu
void FG_COLOR_ON (_COLOR_ COLOR)
 activate the forground for the selected item in the menu this will display the selected item with diffrent forground color
int getch (void)
 get (or push back) characters from terminal keyboard the program waits until the system passes text through to the program.
int getTouch (void)
 the same function as int getch(void) but can distinct also the arrow keys get (or push back) characters from terminal keyboard the program waits until the system passes text through to the program.
void init_new_menu (custom_Menu **mymenu)
 initialize the a new menu with a malloc
void item_border_OFF ()
 switch off the border for each item in the menu
void item_border_ON ()
 switch on the border for each item in the menu this function switch off the menu border
void menu_border_OFF ()
 switch off the menu border
void menu_border_ON ()
 switch on the menu border this function switch off the item border
void menu_in_middle_OFF ()
 desactivate the display of the menu in the middle of the screen
void menu_in_middle_ON ()
 display the menu in the middle of the screen Remark : this can't be invoked in the same time with the set_menu_padding() function
The latest invoked one will disactivate the previous
int put_menu (custom_Menu *mymenu, void(*before)(void), void(*after)(void))
 this function put the menu on the console You can edit the before and the after functions as you like to be compatible with your program
int put_menu_with (custom_Menu *mymenu)
 this function put the menu on the console with a specified paramaters This function is the same as put_menu() function, but without the before and after functions as paramters you can add a paramters to this function , then edit the code into function, where commented to add functions and procedures before the menu and after the menu
void set_menu_padding (int padding)
 Set the padding left to display the menu in the screen with a padding specified Remark : this can't be invoked in the same time with the menu_in_middle_ON() function
The latest invoked one will disactivate the previous.
void startBasicMenu (void)
 You must put this function in the begining of the main inorder to use this library correctly.

Detailed Description

integrate a menu in your console application easily

Author:
Younes CHEIKH
Version:
1.1
Date:
14/12/11

Enumeration Type Documentation

enum _COLOR_

a liste of the colors avilable

With this enum , you can use a liste of colors as displayed also you can use the index of each color as figured as param in the BG_COLOR_ON() and FG_COLOR_ON() functions

Enumerator:
BLACK 

number 0

RED 

number 1

GREEN 

number 2

YELLOW 

number 3

BLUE 

number 4

MAGENTA 

number 5

CYAN 

number 6

WHITE 

number 7

enum BOOLEAN

With this enum you don't must to include the stdbool.h to use false and true Remark: with this enum you need to write FALSE and TRUE as uppercase letters

Enumerator:
FALSE 

Can be the integer 0

TRUE 

Can be the integer 1


Function Documentation

void addNewItem ( custom_Menu **  mymenu,
char  newItem[] 
)

add a new item to the menu

Parameters:
mymenuThe menu.
newItem[]the string of the new item.
Examples:
example1.c, items_border.c, menu_border.c, menu_in_middle.c, set_menu_padding.c, show_bg_color.c, show_bold_text.c, and show_fg_color.c.
void BG_COLOR_OFF ( )

desactivate the background color for the selected item in the menu

Examples:
show_bg_color.c.
void BG_COLOR_ON ( _COLOR_  COLOR)

activate the background for the selected item in the menu this will display the selected item with diffrent background color

Parameters:
COLORtype _COLOR_ { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE }
Remark : you can use numbers between [0,7]
       but if you use another the background color shouldn't be activated
Examples:
show_bg_color.c.
void BOLD_TEXT_OFF ( )

don't show the selected item in bold

Examples:
show_bold_text.c.
void BOLD_TEXT_ON ( )

show the selected item in bold

Examples:
show_bold_text.c.
void dynamic_menu_OFF ( )

desactivate the dynamically this must invoked only if the dynamic_menu_ON() function was invoked previously

void dynamic_menu_ON ( )

make the menu dynamic when you want to select the next item after the latest the first one will be selected automaticly

void FG_COLOR_OFF ( )

desactivate the forground color for the selected item in the menu

Examples:
show_fg_color.c.
void FG_COLOR_ON ( _COLOR_  COLOR)

activate the forground for the selected item in the menu this will display the selected item with diffrent forground color

Parameters:
COLORtype _COLOR_ { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE }
Remark : you can use numbers between [0,7]
       but if you use another the forground color shouldn't be activated
Examples:
show_fg_color.c.
int getch ( void  )

get (or push back) characters from terminal keyboard the program waits until the system passes text through to the program.

Returns:
The ascii code of the character passed by the keyboard.
int getTouch ( void  )

the same function as int getch(void) but can distinct also the arrow keys get (or push back) characters from terminal keyboard the program waits until the system passes text through to the program.

Returns:
300,301,302,303 for the (UP,DOWN,RIGHT,LEFT)keys else The ascii code of the character passed by the keyboard.
void init_new_menu ( custom_Menu **  mymenu)

initialize the a new menu with a malloc

Parameters:
mymenuThe new menu that we want to initialize
Examples:
example1.c, items_border.c, menu_border.c, menu_in_middle.c, set_menu_padding.c, show_bg_color.c, show_bold_text.c, and show_fg_color.c.

switch off the border for each item in the menu

Examples:
items_border.c.

switch on the border for each item in the menu this function switch off the menu border

Examples:
items_border.c.

switch off the menu border

Examples:
menu_border.c.

switch on the menu border this function switch off the item border

Examples:
menu_border.c.

desactivate the display of the menu in the middle of the screen

Examples:
menu_in_middle.c.

display the menu in the middle of the screen Remark : this can't be invoked in the same time with the set_menu_padding() function
The latest invoked one will disactivate the previous

Examples:
menu_in_middle.c.
int put_menu ( custom_Menu mymenu,
void(*)(void)  before,
void(*)(void)  after 
)

this function put the menu on the console You can edit the before and the after functions as you like to be compatible with your program

Parameters:
mymenuthe menu which you want to put
beforethe void function that print some thing before the menu in the screen
afterthe void function that print some thing after the menu in the screen
Returns:
(int) the index of the item chosen by the user
Examples:
example1.c.
int put_menu_with ( custom_Menu mymenu)

this function put the menu on the console with a specified paramaters This function is the same as put_menu() function, but without the before and after functions as paramters you can add a paramters to this function , then edit the code into function, where commented to add functions and procedures before the menu and after the menu

Parameters:
mymenuthe menu which you want to put
Returns:
(int) the index of the item chosen by the user
Examples:
items_border.c, menu_border.c, menu_in_middle.c, set_menu_padding.c, show_bg_color.c, show_bold_text.c, and show_fg_color.c.
void set_menu_padding ( int  padding)

Set the padding left to display the menu in the screen with a padding specified Remark : this can't be invoked in the same time with the menu_in_middle_ON() function
The latest invoked one will disactivate the previous.

Parameters:
paddingthe number of rows (the padding)
Examples:
set_menu_padding.c.
void startBasicMenu ( void  )

You must put this function in the begining of the main inorder to use this library correctly.

Examples:
example1.c, items_border.c, menu_border.c, menu_in_middle.c, set_menu_padding.c, show_bg_color.c, show_bold_text.c, and show_fg_color.c.