Modify the full-screen editor. With the support of panel, you can open three windows to edit different content and save the content of the three windows.
The effect is as follows:
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Signature + signature + 9eq1NjH69eiw/Signature + Cjxicj4KPHA + signature + CjxwPns8L3A + signature + CjxwPn08L3A + signature + Signature = "");
Initscr ();
Clear ();
Noecho ();
Cbreak ();
If (has_colors () = FALSE)
{
Endwin ();
Printf ("your terminal does not support color! \ N ");
Return (1 );
}
Start_color ();/* Start the color mechanism */
Mvprintw (3, COLS/2-10, "simple Editor-limited to single screen editing ");
Mvprintw (4, COLS/2-20, "[F9 read and save the content, F10 Save the disk, F11 exit, F12 Delete the entire row, TAB change window ]");
Refresh ();
Init_pair (1, COLOR_GREEN, COLOR_BLACK );
Init_pair (2, COLOR_BLUE, COLOR_BLACK );
Init_pair (3, COLOR_RED, COLOR_BLACK );
WINDOW * mywins [3];
PANEL * top;
PANEL * mypanels [3];
Char filename [10];
Int width = COLS-18;
Int height = LINES-18;
Int x, y;
Int begin_y = 5; int begin_x = 5;
Int I;
For (I = 0; I <3; ++ I)
{
Mywins [I] = newwin (height, width, begin_y, begin_x); // new window (row, column, begin_y, begin_x)
Keypad (mywins [I], TRUE );
Wattron (mywins [I], COLOR_PAIR (I + 1 ));
Mypanels [I] = new_panel (mywins [I]);
Box (mywins [I], ACS_VLINE, ACS_HLINE );
Wattroff (mywins [I], COLOR_PAIR (I + 1 ));
Begin_y + = 4; begin_x + = 4;
}
Set_panel_userptr (mypanels [0], mypanels [1]);
Set_panel_userptr (mypanels [1], mypanels [2]);
Set_panel_userptr (mypanels [2], mypanels [0]);
Top = mypanels [2];
Update_panels ();
Doupdate ();
Int nowwinid = 2;
Sprintf (filename, "myed % d. dat", nowwinid );
Getyx (mywins [nowwinid], y, x );
++ Y; ++ x;
Mmask_t oldmousemask;
Int ans = 0;
FILE * fp2 = NULL;
FILE * fp1 = NULL;
Mousemask (ALL_MOUSE_EVENTS, & oldmousemask );
While (1 ){
Int c = mvwgetch (mywins [nowwinid], y, x );
Switch (c)
{Case KEY_MOUSE:
If (getmouse (& event) = OK)
{/* When the user clicks left mouse button */
If (event. bstate & buttonerepressed)
{
Y = event. y-7; x = events. x-7;
Wmove (mywins [nowwinid], y, x );
}
}
Break;
Case KEY_BACKSPACE:
-- X;
If (x <1 ){
-- Y; x = width-2;
}
If (y <1 ){
Y = height-2;
}
Mvwprintw (mywins [nowwinid], y, x ,"");
Break;
Case KEY_RIGHT:
++ X;
If (x> = width-1 ){
++ Y;
X = 1;
}
Break;
Case KEY_LEFT: -- x;
If (x <1 ){
-- Y;
X = width-2;
}
Break;
Case KEY_UP:
-- Y;
If (y <1 ){
Y = height-2;
}
Break;
Case KEY_DOWN:
++ Y;
If (y> = height-1 ){
Y = 1;
}
Break;
Case 10:
++ Y;
If (y> = height-1 ){
Y = 1;
}
Break;
Case KEY_F (11 ):
// Exit
Mvprintw (LINES-3, 2 ,"");
Mvprintw (LINES-3, 2, "exit the editor? ");
Mvprintw (LINES-2, 2 ,"");
Mvprintw (LINES-1, 2, "\ n ");
Refresh ();
Ans = getch ();
If (ans = 'y' | ans = 'y ')
{
Mvprintw (LINES-2, 2, "Yes \ n ");
Refresh ();
Wattroff (mywins [nowwinid], COLOR_PAIR (1 ));
Mousemask (oldmousemask, NULL );
Endwin ();
Return 0;
} Else
Mvprintw (LINES-2, 2, "No \ n ");
Refresh ();
Break;