/[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.9 by sysadm, Sat Mar 19 13:34:20 2005 UTC Revision 1.17 by sysadm, Fri May 6 16:37:59 2005 UTC
# Line 62  clrline (int line_begin, int line_end) Line 62  clrline (int line_begin, int line_end)
62  }  }
63    
64  void  void
65    clrtobot (int line_begin)
66    {
67      clrline (line_begin, screen_lines);
68      moveto (line_begin, 0);
69    }
70    
71    void
72  clearscr ()  clearscr ()
73  {  {
74    prints ("\33[2J");    prints ("\33[2J");
# Line 78  press_any_key () Line 85  press_any_key ()
85    prints ("                           \033[1;33m按任意键继续...\033[0;37m");    prints ("                           \033[1;33m按任意键继续...\033[0;37m");
86    iflush ();    iflush ();
87    
88    return igetch ();    return igetch_t (60);
89  }  }
90    
91  void  void
92  set_input_echo(int echo)  set_input_echo (int echo)
93  {  {
   char temp[256];  
   
94    if (echo)    if (echo)
95    {      {
96      outc ('\x83'); // ASCII code 131        outc ('\x83');            // ASCII code 131
97      iflush ();        iflush ();
98    }      }
99    else    else
100    {      {
101  //    outc ('\x85'); // ASCII code 133  //    outc ('\x85'); // ASCII code 133
102      prints ("\xff\xfb\x01\xff\xfb\x03");        prints ("\xff\xfb\x01\xff\xfb\x03");
103      iflush ();        iflush ();
104      igetch ();        igetch_t (60);
105      igetch ();        igetch_t (60);
106    }      }
107  }  }
108    
109  int  int
# Line 109  str_input (char *buffer, int buffer_leng Line 114  str_input (char *buffer, int buffer_leng
114    
115    memset (buffer, '\0', buffer_length);    memset (buffer, '\0', buffer_length);
116    
117    while (c = igetch ())    while (c = igetch_t (60))
118      {      {
119        if (c == CR)        if (c == KEY_NULL || c == KEY_TIMEOUT || c == CR)
120          break;          break;
121        if (c == LF)        if (c == LF)
122          continue;          continue;
123        if (c == BACKSPACE)        if (c == BACKSPACE)
124          {          {
125            if (offset > 0)            if (offset > 0)
# Line 143  str_input (char *buffer, int buffer_leng Line 148  str_input (char *buffer, int buffer_leng
148        buffer[offset] = '\0';        buffer[offset] = '\0';
149        switch (echo_mode)        switch (echo_mode)
150          {          {
151          case 0:          case DOECHO:
152            outc ((char) c);            outc ((char) c);
153            break;            break;
154          case 1:          case NOECHO:
155            outc ('*');            outc ('*');
156            break;            break;
157          }          }
# Line 163  str_input (char *buffer, int buffer_leng Line 168  str_input (char *buffer, int buffer_leng
168  }  }
169    
170  int  int
171    get_data (int row, int col, char *prompt, char *buffer, int buffer_length, int echo_mode)
172    {
173      int len;
174    
175      moveto (row, col);
176      iflush ();
177      prints (prompt);
178      prints (buffer);
179      iflush ();
180    
181      len = str_input (buffer, buffer_length, echo_mode);
182      
183      return len;
184    }
185    
186    int
187  display_file (const char *filename)  display_file (const char *filename)
188  {  {
189    char buffer[260];    char buffer[260];
190    FILE *fin;    FILE *fin;
191    int i;    int i;
192    
193    if ((fin = fopen (filename, "r")) != NULL)    if ((fin = fopen (filename, "r")) == NULL)
194    {      {
195      while (fgets (buffer, 255, fin))        return -1;
196        {      }
197          i = strlen (buffer);  
198          if (buffer[i - 1] == '\n' && buffer[i - 2] != '\r')    while (fgets (buffer, 255, fin))
199            {      {
200              buffer[i - 1] = '\r';        i = strlen (buffer);
201              buffer[i] = '\n';        if (buffer[i - 1] == '\n' && buffer[i - 2] != '\r')
202              buffer[i + 1] = '\0';          {
203            }            buffer[i - 1] = '\r';
204          prints (buffer);            buffer[i] = '\n';
205          iflush ();            buffer[i + 1] = '\0';
206        }          }
207      fclose(fin);        prints (buffer);
208      return 0;        iflush ();
209    }      }
210        fclose (fin);
211    return -1;  
212      return 0;
213  }  }
214    
215  int  int
# Line 195  display_file_ex (const char *filename, i Line 217  display_file_ex (const char *filename, i
217  {  {
218    char buffer[260], temp[256];    char buffer[260], temp[256];
219    int i, ch, input_ok;    int i, ch, input_ok;
220    long int line, c_line_begin = 0, c_line_total=0;    long int line, c_line_begin = 0, c_line_total = 0;
221    long int f_line, f_size, f_offset;    long int f_line, f_size, f_offset;
222    FILE *fin;    FILE *fin;
223    struct stat f_stat;    struct stat f_stat;
# Line 214  display_file_ex (const char *filename, i Line 236  display_file_ex (const char *filename, i
236        f_size = f_stat.st_size;        f_size = f_stat.st_size;
237    
238        while (fgets (buffer, 255, fin))        while (fgets (buffer, 255, fin))
239          c_line_total ++;          c_line_total++;
240        rewind (fin);        rewind (fin);
241    
242        while (fgets (buffer, 255, fin))        while (fgets (buffer, 255, fin))
# Line 226  display_file_ex (const char *filename, i Line 248  display_file_ex (const char *filename, i
248                moveto (screen_lines, 0);                moveto (screen_lines, 0);
249                prints                prints
250                  ("\033[1;44;32m下面还有喔 (%d%%)\033[33m   │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │     \033[m",                  ("\033[1;44;32m下面还有喔 (%d%%)\033[33m   │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │     \033[m",
251                   (f_offset-strlen(buffer)) * 100 / f_size);                   (f_offset - strlen (buffer)) * 100 / f_size);
252                iflush ();                iflush ();
253    
254                input_ok = 0;                input_ok = 0;
255                while (!input_ok)                while (!input_ok)
256                  {                  {
257                    ch = igetch ();                    ch = igetch_t (MAX_DELAY_TIME);
258                    input_ok = 1;                    input_ok = 1;
259                    switch (ch)                    switch (ch)
260                      {                      {
# Line 278  display_file_ex (const char *filename, i Line 300  display_file_ex (const char *filename, i
300                          }                          }
301                        break;                        break;
302                      case KEY_RIGHT:                      case KEY_RIGHT:
303                      case KEY_PGDOWN:                      case KEY_PGDN:
304                      case Ctrl ('F'):                      case Ctrl ('F'):
305                      case KEY_SPACE:                      case KEY_SPACE:
306                        c_line_begin += (screen_lines - begin_line - 1);                        c_line_begin += (screen_lines - begin_line - 1);
307                        if (c_line_begin + (screen_lines - begin_line) > c_line_total)                        if (c_line_begin + (screen_lines - begin_line) >
308                          c_line_begin = c_line_total - (screen_lines - begin_line);                            c_line_total)
309                            c_line_begin =
310                              c_line_total - (screen_lines - begin_line);
311                        rewind (fin);                        rewind (fin);
312                        for (f_line = 0; f_line < c_line_begin; f_line++)                        for (f_line = 0; f_line < c_line_begin; f_line++)
313                          {                          {
# Line 291  display_file_ex (const char *filename, i Line 315  display_file_ex (const char *filename, i
315                              goto exit;                              goto exit;
316                          }                          }
317                        break;                        break;
318                        case KEY_NULL:
319                        case KEY_TIMEOUT:
320                      case KEY_LEFT:                      case KEY_LEFT:
321                      case 'q':                      case 'q':
322                      case 'Q':                      case 'Q':
# Line 338  display_file_ex (const char *filename, i Line 364  display_file_ex (const char *filename, i
364            line++;            line++;
365          }          }
366        if (wait)        if (wait)
367          ch = press_any_key();          ch = press_any_key ();
368        else        else
369          ch = 0;          ch = 0;
370    
371      exit:      exit:
372        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