Projet Editeur de texte (C)
the F
Messages postés
162
Statut
Membre
-
niki -
niki -
Bonjour,
je Lance le projet de realiser un editeur de texte ecrit en language C et en utilisant la bibliothéque <curses.h>
NB : C'est a titre educatif notamment
pour commencer voici quelques fonctions que j'ai implementé ; à vous de commenter et ajouter ce que vous voyez necessaire :
********************************************
je Lance le projet de realiser un editeur de texte ecrit en language C et en utilisant la bibliothéque <curses.h>
NB : C'est a titre educatif notamment
pour commencer voici quelques fonctions que j'ai implementé ; à vous de commenter et ajouter ce que vous voyez necessaire :
********************************************
// ces fonction initialises l'environnement (barre de titre et barre d'etat )
#include <curses.h>
void draw_title (WINDOW* active_win ){
int scr_x ;
initscr();
start_color();
scr_x=getmaxx(active_win);
init_pair(1, COLOR_GREEN, COLOR_BLACK);
init_pair(2,COLOR_CYAN,COLOR_BLACK);
/*the title is a separate window */
WINDOW *title =newwin(3,scr_x,4,5);
/* Draws the title box */
wattron(title,COLOR_PAIR(2));
wborder(title,'|','|','~','~','#','~','~','#');
wattroff(title,COLOR_PAIR(2));
wattron(title,COLOR_PAIR(1));
mvwaddstr(title,1,((scr_x)/2)-15,"TexT Editor Written in C");
wattroff(title,COLOR_PAIR(1));
wrefresh(title);
wrefresh(active_win);
return;
}
void draw_status_bar (char *crnt_fl_name,WINDOW * active_win ){
int scr_y;
int scr_x ;
scr_x=getmaxx(active_win);
scr_y=getmaxy(active_win);
init_pair(1, COLOR_GREEN, COLOR_BLACK);
init_pair(2,COLOR_CYAN,COLOR_BLACK);
/*Status bar is also a separate window */
WINDOW *bar =newwin(3,scr_x,scr_y-2,0);
wattron(bar,COLOR_PAIR(2));
wborder(bar,'|','|','_','_','_','_','_','_');
wattroff(bar,COLOR_PAIR(2));
wattron(bar,COLOR_PAIR(1));
mvwaddstr(bar,1,3,"current file :");
mvwaddstr(bar,1,17,crnt_fl_name);
wattroff(bar,COLOR_PAIR(1));
wrefresh(bar);
wrefresh(active_win);
endwin();
return ;
}
init_env(WINDOW *active_screen){
initscr ();
start_color();
WINDOW * new_editor ;
draw_status_bar("d",active_screen);
draw_title(active_screen);
wrefresh(active_screen);
return;
}
Configuration: Linux Safari 532.9
3 réponses
-
-
Voici la fonction qui lit les caracteres saisis :
char * edit_text(WINDOW* active_window ){ char* texte =(char*)calloc(500,sizeof(char)); int nblins=0,car=0; int posx=0; int posy=5; initscr(); start_color(); keypad(active_window,TRUE); cbreak(); do { texte[car]=mvwgetch(active_window,posy,posx); car++; if (texte[car]=='\n'){ /*la ou l'utilisateur appuye sur "entree"*/ nblins++; posy++; posx=0; } else { /* un caractere normal */ posx++; mvwaddch(active_window,posy,posx,texte[car]); } if(posx==COLS){ /*cas ou on arrive a la fin de ligne */ posx=0; posy++; texte[car]='\n'; mvwaddch(active_window,posy,posx,texte[car]); nblins++; } }while(texte[car]=='[^') ; /* le programme prend fin quand on appuiye sur "esc" } -