/[LeafOK_CVS]/lbbs/src/screen.c
ViewVC logotype

Diff of /lbbs/src/screen.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.10 by sysadm, Sun Mar 20 17:23:17 2005 UTC Revision 1.15 by sysadm, Fri Apr 8 11:11:11 2005 UTC
# Line 78  press_any_key () Line 78  press_any_key ()
78    prints ("                           \033[1;33m按任意键继续...\033[0;37m");    prints ("                           \033[1;33m按任意键继续...\033[0;37m");
79    iflush ();    iflush ();
80    
81    return igetch ();    return igetch_t (60);
82  }  }
83    
84  void  void
85  set_input_echo(int echo)  set_input_echo (int echo)
86  {  {
   char temp[256];  
   
87    if (echo)    if (echo)
88    {      {
89      outc ('\x83'); // ASCII code 131        outc ('\x83');            // ASCII code 131
90      iflush ();        iflush ();
91    }      }
92    else    else
93    {      {
94  //    outc ('\x85'); // ASCII code 133  //    outc ('\x85'); // ASCII code 133
95      prints ("\xff\xfb\x01\xff\xfb\x03");        prints ("\xff\xfb\x01\xff\xfb\x03");
96      iflush ();        iflush ();
97      igetch ();        igetch_t (60);
98      igetch ();        igetch_t (60);
99    }      }
100  }  }
101    
102  int  int
# Line 109  str_input (char *buffer, int buffer_leng Line 107  str_input (char *buffer, int buffer_leng
107    
108    memset (buffer, '\0', buffer_length);    memset (buffer, '\0', buffer_length);
109    
110    while (c = igetch ())    while (c = igetch_t (60))
111      {      {
112        if (c == CR)        if (c == KEY_NULL || c == KEY_TIMEOUT || c == CR)
113          break;          break;
114        if (c == LF)        if (c == LF)
115          continue;          continue;
116        if (c == BACKSPACE)        if (c == BACKSPACE)
117          {          {
118            if (offset > 0)            if (offset > 0)
# Line 163  str_input (char *buffer, int buffer_leng Line 161  str_input (char *buffer, int buffer_leng
161  }  }
162    
163  int  int
164    get_data (int row, int col, char *prompt, char *buffer, int buffer_length, int echo_mode)
165    {
166      int len;
167    
168      moveto (row, col);
169      iflush ();
170      prints (prompt);
171      prints (buffer);
172      iflush ();
173    
174      len = str_input (buffer, buffer_length, echo_mode);
175      
176      return len;
177    }
178    
179    int
180  display_file (const char *filename)  display_file (const char *filename)
181  {  {
182    char buffer[260];    char buffer[260];
# Line 170  display_file (const char *filename) Line 184  display_file (const char *filename)
184    int i;    int i;
185    
186    if ((fin = fopen (filename, "r")) == NULL)    if ((fin = fopen (filename, "r")) == NULL)
187    {      {
188      return -1;        return -1;
189    }      }
190    
191    while (fgets (buffer, 255, fin))    while (fgets (buffer, 255, fin))
192      {      {
193        i = strlen (buffer);        i = strlen (buffer);
194        if (buffer[i - 1] == '\n' && buffer[i - 2] != '\r')        if (buffer[i - 1] == '\n' && buffer[i - 2] != '\r')
195          {          {
196            buffer[i - 1] = '\r';            buffer[i - 1] = '\r';
197            buffer[i] = '\n';            buffer[i] = '\n';
198            buffer[i + 1] = '\0';            buffer[i + 1] = '\0';
# Line 186  display_file (const char *filename) Line 200  display_file (const char *filename)
200        prints (buffer);        prints (buffer);
201        iflush ();        iflush ();
202      }      }
203    fclose(fin);    fclose (fin);
204    
205    return 0;    return 0;
206  }  }
# Line 196  display_file_ex (const char *filename, i Line 210  display_file_ex (const char *filename, i
210  {  {
211    char buffer[260], temp[256];    char buffer[260], temp[256];
212    int i, ch, input_ok;    int i, ch, input_ok;
213    long int line, c_line_begin = 0, c_line_total=0;    long int line, c_line_begin = 0, c_line_total = 0;
214    long int f_line, f_size, f_offset;    long int f_line, f_size, f_offset;
215    FILE *fin;    FILE *fin;
216    struct stat f_stat;    struct stat f_stat;
# Line 215  display_file_ex (const char *filename, i Line 229  display_file_ex (const char *filename, i
229        f_size = f_stat.st_size;        f_size = f_stat.st_size;
230    
231        while (fgets (buffer, 255, fin))        while (fgets (buffer, 255, fin))
232          c_line_total ++;          c_line_total++;
233        rewind (fin);        rewind (fin);
234    
235        while (fgets (buffer, 255, fin))        while (fgets (buffer, 255, fin))
# Line 227  display_file_ex (const char *filename, i Line 241  display_file_ex (const char *filename, i
241                moveto (screen_lines, 0);                moveto (screen_lines, 0);
242                prints                prints
243                  ("\033[1;44;32m下面还有喔 (%d%%)\033[33m   │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │     \033[m",                  ("\033[1;44;32m下面还有喔 (%d%%)\033[33m   │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │     \033[m",
244                   (f_offset-strlen(buffer)) * 100 / f_size);                   (f_offset - strlen (buffer)) * 100 / f_size);
245                iflush ();                iflush ();
246    
247                input_ok = 0;                input_ok = 0;
248                while (!input_ok)                while (!input_ok)
249                  {                  {
250                    ch = igetch ();                    ch = igetch_t (MAX_DELAY_TIME);
251                    input_ok = 1;                    input_ok = 1;
252                    switch (ch)                    switch (ch)
253                      {                      {
# Line 279  display_file_ex (const char *filename, i Line 293  display_file_ex (const char *filename, i
293                          }                          }
294                        break;                        break;
295                      case KEY_RIGHT:                      case KEY_RIGHT:
296                      case KEY_PGDOWN:                      case KEY_PGDN:
297                      case Ctrl ('F'):                      case Ctrl ('F'):
298                      case KEY_SPACE:                      case KEY_SPACE:
299                        c_line_begin += (screen_lines - begin_line - 1);                        c_line_begin += (screen_lines - begin_line - 1);
300                        if (c_line_begin + (screen_lines - begin_line) > c_line_total)                        if (c_line_begin + (screen_lines - begin_line) >
301                          c_line_begin = c_line_total - (screen_lines - begin_line);                            c_line_total)
302                            c_line_begin =
303                              c_line_total - (screen_lines - begin_line);
304                        rewind (fin);                        rewind (fin);
305                        for (f_line = 0; f_line < c_line_begin; f_line++)                        for (f_line = 0; f_line < c_line_begin; f_line++)
306                          {                          {
# Line 292  display_file_ex (const char *filename, i Line 308  display_file_ex (const char *filename, i
308                              goto exit;                              goto exit;
309                          }                          }
310                        break;                        break;
311                        case KEY_NULL:
312                        case KEY_TIMEOUT:
313                      case KEY_LEFT:                      case KEY_LEFT:
314                      case 'q':                      case 'q':
315                      case 'Q':                      case 'Q':
# Line 339  display_file_ex (const char *filename, i Line 357  display_file_ex (const char *filename, i
357            line++;            line++;
358          }          }
359        if (wait)        if (wait)
360          ch = press_any_key();          ch = press_any_key ();
361        else        else
362          ch = 0;          ch = 0;
363    
364      exit:      exit:
365        fclose (fin);        fclose (fin);


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1