5 A part of the extended file system 2 disk editor.
7 --------------------------------------------------------
8 Window management - Interfacing with the ncurses library
9 --------------------------------------------------------
11 First written on: April 17 1995
12 Modified on : April 05 2001 Christian.Bac@int-evry.fr
13 it looks like readline does not like that initscr decides to set the tty to
16 Copyright (C) 1995 Gadi Oxman
26 #include <sys/ioctl.h>
29 #include "../version.h"
31 struct struct_pad_info show_pad_info;
32 WINDOW *title_win,*show_win,*command_win,*mt_win1,*mt_win2,*show_pad;
34 /* to remember configuration after initscr
37 struct termios termioInit, termioCurrent;
39 void draw_title_win (void)
41 char title_string [128];
45 sprintf (title_string,"EXT2ED - Extended-2 File System editor ver %s (%s)", E2FSPROGS_VERSION, E2FSPROGS_DATE);
46 wmove (title_win,TITLE_WIN_LINES/2,(COLS-strlen (title_string))/2);
47 wprintw (title_win,title_string);
51 void setup_show_win(void)
53 wbkgdset (show_win,A_REVERSE);werase (show_win);
56 show_pad_info.display_lines=LINES-TITLE_WIN_LINES-SHOW_WIN_LINES-COMMAND_WIN_LINES-2;
57 show_pad_info.display_cols=COLS;
58 show_pad_info.max_line=show_pad_info.display_lines-1;show_pad_info.max_col=show_pad_info.display_cols-1;
59 show_pad_info.disable_output=0;
62 void init_windows (void)
65 tcgetattr(0,&termioInit); /* save initial config */
66 termioCurrent = termioInit;
67 termioCurrent.c_lflag |= ECHO; /* set echo on */
68 tcsetattr(0,TCSANOW,&termioCurrent);
70 if (LINES<TITLE_WIN_LINES+SHOW_WIN_LINES+COMMAND_WIN_LINES+3) {
71 printf ("Sorry, your terminal screen is too small\n");
72 printf ("Error - Can not initialize windows\n");
76 title_win=newwin (TITLE_WIN_LINES,COLS,0,0);
77 show_win=newwin (SHOW_WIN_LINES,COLS,TITLE_WIN_LINES,0);
78 show_pad=newpad (SHOW_PAD_LINES,SHOW_PAD_COLS);
79 mt_win1=newwin (1,COLS,TITLE_WIN_LINES+SHOW_WIN_LINES,0);
80 mt_win2=newwin (1,COLS,LINES-COMMAND_WIN_LINES-1,0);
81 command_win=newwin (COMMAND_WIN_LINES,COLS,LINES-COMMAND_WIN_LINES,0);
83 if (title_win==NULL || show_win==NULL || show_pad==NULL || command_win==NULL) {
84 printf ("Error - Not enough memory - Can not initialize windows\n");exit (1);
91 scrollok (command_win,TRUE);
96 refresh_command_win ();
101 void refresh_title_win (void)
103 wrefresh (title_win);
106 void refresh_show_win (void)
108 int current_page,total_pages;
110 current_page=show_pad_info.line/show_pad_info.display_lines+1;
111 if (show_pad_info.line%show_pad_info.display_lines)
113 total_pages=show_pad_info.max_line/show_pad_info.display_lines+1;
115 wmove (show_win,2,COLS-18);
116 wprintw (show_win,"Page %d of %d\n",current_page,total_pages);
118 wmove (show_win,2,COLS-18);
123 void refresh_show_pad (void)
126 int left,top,right,bottom,i;
128 if (show_pad_info.disable_output)
131 if (show_pad_info.max_line < show_pad_info.display_lines-1) {
132 for (i=show_pad_info.max_line+1;i<show_pad_info.display_lines;i++) {
133 wmove (show_pad,i,0);wprintw (show_pad,"\n");
136 left=0;right=show_pad_info.display_cols-1;
137 top=TITLE_WIN_LINES+SHOW_WIN_LINES+1;bottom=top+show_pad_info.display_lines-1;
139 if (show_pad_info.line > show_pad_info.max_line-show_pad_info.display_lines+1)
140 show_pad_info.line=show_pad_info.max_line-show_pad_info.display_lines+1;
142 if (show_pad_info.line < 0)
143 show_pad_info.line=0;
146 prefresh (show_pad,show_pad_info.line,show_pad_info.col,top,left,show_pad_info.display_lines-1,show_pad_info.display_cols-1);
148 prefresh (show_pad,show_pad_info.line,show_pad_info.col,top,left,top+show_pad_info.display_lines-1,left+show_pad_info.display_cols-1);
152 void refresh_command_win (void)
154 wrefresh (command_win);
157 void close_windows (void)
160 tcsetattr(0,TCSANOW,&termioInit);
163 delwin (command_win);
170 void show_info (void)
172 int block_num,block_offset;
174 block_num=device_offset/file_system_info.block_size;
175 block_offset=device_offset%file_system_info.block_size;
177 wmove (show_win,0,0);
178 wprintw (show_win,"Offset %-3ld in block %ld. ",block_offset,block_num);
179 if (current_type != NULL)
180 wprintw (show_win,"Type: %s\n",current_type->name);
182 wprintw (show_win,"Type: %s\n","none");
188 void redraw_all (void)
190 int min_lines = TITLE_WIN_LINES+SHOW_WIN_LINES+COMMAND_WIN_LINES+3;
192 int save_col, save_lines;
194 /* get the size of the terminal connected to stdout */
195 ioctl(1, TIOCGWINSZ, &ws);
197 * Do it again because GDB doesn't stop before the first ioctl
198 * call, we want an up-to-date size when we're
201 if (ioctl(1, TIOCGWINSZ, &ws) == 0) {
202 if (ws.ws_row < min_lines)
203 ws.ws_row = min_lines;
204 if ((ws.ws_row != LINES) || (ws.ws_col != COLS)) {
205 wmove (show_win,2,COLS-18);
208 resizeterm(ws.ws_row, ws.ws_col);
209 wresize(title_win, TITLE_WIN_LINES,COLS);
210 wresize(show_win, SHOW_WIN_LINES,COLS);
211 wresize(command_win, COMMAND_WIN_LINES,COLS);
212 wresize(mt_win1, 1,COLS);
213 wresize(mt_win2, 1,COLS);
214 mvwin(mt_win2, LINES-COMMAND_WIN_LINES-1,0);
215 mvwin(command_win, LINES-COMMAND_WIN_LINES,0);
217 show_pad_info.display_lines=LINES-TITLE_WIN_LINES-SHOW_WIN_LINES-COMMAND_WIN_LINES-2;
218 show_pad_info.display_cols=COLS;
221 clearok(title_win, 1);
222 clearok(show_win, 1);
223 clearok(command_win, 1);
230 refresh_title_win ();
231 refresh_command_win ();