/[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.20 by sysadm, Tue Jan 3 12:34:54 2006 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
110  str_input (char *buffer, int buffer_length, int echo_mode)  _str_input (char *buffer, int buffer_length, int echo_mode)
111  {  {
112    char buf[256], ch;    char buf[256], ch;
113    int c, offset = 0, len, loop = 1, i, hz = 0;    int c, offset = 0, len, loop = 1, i, hz = 0;
114    
115    memset (buffer, '\0', buffer_length);    for (i=0; i<buffer_length && buffer[i] != '\0'; i++)
116        {
117              offset++;
118        }
119    
120    while (c = igetch ())    while (c = igetch_t (60))
121      {      {
122        if (c == CR)        if (c == KEY_NULL || c == KEY_TIMEOUT || c == CR)
123          break;          break;
124        if (c == LF)        if (c == LF)
125          continue;          continue;
126        if (c == BACKSPACE)        if (c == BACKSPACE)
127          {          {
128            if (offset > 0)            if (offset > 0)
# Line 143  str_input (char *buffer, int buffer_leng Line 151  str_input (char *buffer, int buffer_leng
151        buffer[offset] = '\0';        buffer[offset] = '\0';
152        switch (echo_mode)        switch (echo_mode)
153          {          {
154          case 0:          case DOECHO:
155            outc ((char) c);            outc ((char) c);
156            break;            break;
157          case 1:          case NOECHO:
158            outc ('*');            outc ('*');
159            break;            break;
160          }          }
# Line 163  str_input (char *buffer, int buffer_leng Line 171  str_input (char *buffer, int buffer_leng
171  }  }
172    
173  int  int
174    str_input (char *buffer, int buffer_length, int echo_mode)
175    {
176      int offset;
177      
178      memset (buffer, '\0', buffer_length);
179      
180      offset = _str_input (buffer, buffer_length, echo_mode);
181      
182      return offset;
183    };
184    
185    int
186    get_data (int row, int col, char *prompt, char *buffer, int buffer_length, int echo_mode)
187    {
188      int len;
189    
190      moveto (row, col);
191      iflush ();
192      prints (prompt);
193      prints (buffer);
194      iflush ();
195    
196      len = _str_input (buffer, buffer_length, echo_mode);
197      
198      return len;
199    }
200    
201    int
202  display_file (const char *filename)  display_file (const char *filename)
203  {  {
204    char buffer[260];    char buffer[260];
# Line 170  display_file (const char *filename) Line 206  display_file (const char *filename)
206    int i;    int i;
207    
208    if ((fin = fopen (filename, "r")) == NULL)    if ((fin = fopen (filename, "r")) == NULL)
209    {      {
210      return -1;        return -1;
211    }      }
212    
213    while (fgets (buffer, 255, fin))    while (fgets (buffer, 255, fin))
214      {      {
215        i = strlen (buffer);        i = strlen (buffer);
216        if (buffer[i - 1] == '\n' && buffer[i - 2] != '\r')        if (buffer[i - 1] == '\n' && buffer[i - 2] != '\r')
217          {          {
218            buffer[i - 1] = '\r';            buffer[i - 1] = '\r';
219            buffer[i] = '\n';            buffer[i] = '\n';
220            buffer[i + 1] = '\0';            buffer[i + 1] = '\0';
# Line 186  display_file (const char *filename) Line 222  display_file (const char *filename)
222        prints (buffer);        prints (buffer);
223        iflush ();        iflush ();
224      }      }
225    fclose(fin);    fclose (fin);
226    
227    return 0;    return 0;
228  }  }
# Line 195  int Line 231  int
231  display_file_ex (const char *filename, int begin_line, int wait)  display_file_ex (const char *filename, int begin_line, int wait)
232  {  {
233    char buffer[260], temp[256];    char buffer[260], temp[256];
234    int i, ch, input_ok;    int i, ch, input_ok, max_lines;
235    long int line, c_line_begin = 0, c_line_total=0;    long int line, c_line_begin = 0, c_line_total = 0;
236    long int f_line, f_size, f_offset;    long int f_line, f_size, f_offset;
237    FILE *fin;    FILE *fin;
238    struct stat f_stat;    struct stat f_stat;
239    
240      max_lines = screen_lines - 1;
241    clrline (begin_line, screen_lines);    clrline (begin_line, screen_lines);
242    line = begin_line;    line = begin_line;
243    moveto (line, 0);    moveto (line, 0);
# Line 215  display_file_ex (const char *filename, i Line 252  display_file_ex (const char *filename, i
252        f_size = f_stat.st_size;        f_size = f_stat.st_size;
253    
254        while (fgets (buffer, 255, fin))        while (fgets (buffer, 255, fin))
255          c_line_total ++;          c_line_total++;
256        rewind (fin);        rewind (fin);
257    
258        while (fgets (buffer, 255, fin))        while (fgets (buffer, 255, fin))
259          {          {
260            if (line >= screen_lines)            if (line >= max_lines)
261              {              {
262                f_offset = ftell (fin);                f_offset = ftell (fin);
263    
264                moveto (screen_lines, 0);                moveto (screen_lines, 0);
265                prints                prints
266                  ("\033[1;44;32m下面还有喔 (%d%%)\033[33m   │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │     \033[m",                  ("\033[1;44;32m下面还有喔 (%d%%)\033[33m   │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │     \033[m",
267                   (f_offset-strlen(buffer)) * 100 / f_size);                   (f_offset - strlen (buffer)) * 100 / f_size);
268                iflush ();                iflush ();
269    
270                input_ok = 0;                input_ok = 0;
271                while (!input_ok)                while (!input_ok)
272                  {                  {
273                    ch = igetch ();                    ch = igetch_t (MAX_DELAY_TIME);
274                    input_ok = 1;                    input_ok = 1;
275                    switch (ch)                    switch (ch)
276                      {                      {
# Line 266  display_file_ex (const char *filename, i Line 303  display_file_ex (const char *filename, i
303                      case KEY_PGUP:                      case KEY_PGUP:
304                      case Ctrl ('B'):                      case Ctrl ('B'):
305                        if (c_line_begin > 0)                        if (c_line_begin > 0)
306                          c_line_begin -= (screen_lines - begin_line - 1);                          c_line_begin -= (max_lines - begin_line - 1);
307                        else                        else
308                          goto exit;                          goto exit;
309                        if (c_line_begin < 0)                        if (c_line_begin < 0)
# Line 279  display_file_ex (const char *filename, i Line 316  display_file_ex (const char *filename, i
316                          }                          }
317                        break;                        break;
318                      case KEY_RIGHT:                      case KEY_RIGHT:
319                      case KEY_PGDOWN:                      case KEY_PGDN:
320                      case Ctrl ('F'):                      case Ctrl ('F'):
321                      case KEY_SPACE:                      case KEY_SPACE:
322                        c_line_begin += (screen_lines - begin_line - 1);                        c_line_begin += (max_lines - begin_line - 1);
323                        if (c_line_begin + (screen_lines - begin_line) > c_line_total)                        if (c_line_begin + (max_lines - begin_line) >
324                          c_line_begin = c_line_total - (screen_lines - begin_line);                            c_line_total)
325                            c_line_begin =
326                              c_line_total - (max_lines - begin_line);
327                        rewind (fin);                        rewind (fin);
328                        for (f_line = 0; f_line < c_line_begin; f_line++)                        for (f_line = 0; f_line < c_line_begin; f_line++)
329                          {                          {
# Line 292  display_file_ex (const char *filename, i Line 331  display_file_ex (const char *filename, i
331                              goto exit;                              goto exit;
332                          }                          }
333                        break;                        break;
334                        case KEY_NULL:
335                        case KEY_TIMEOUT:
336                      case KEY_LEFT:                      case KEY_LEFT:
337                      case 'q':                      case 'q':
338                      case 'Q':                      case 'Q':
# Line 339  display_file_ex (const char *filename, i Line 380  display_file_ex (const char *filename, i
380            line++;            line++;
381          }          }
382        if (wait)        if (wait)
383          ch = press_any_key();          ch = press_any_key ();
384        else        else
385          ch = 0;          ch = 0;
386    
387      exit:      exit:
388        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