/[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.80 by sysadm, Fri May 30 00:20:53 2025 UTC Revision 1.84 by sysadm, Sat May 31 01:58:22 2025 UTC
# Line 40  Line 40 
40  #define STR_TOP_MIDDLE_MAX_LEN 20  #define STR_TOP_MIDDLE_MAX_LEN 20
41  #define STR_TOP_RIGHT_MAX_LEN 20  #define STR_TOP_RIGHT_MAX_LEN 20
42    
43    #define MSG_EXT_MAX_LEN 200
44    
45  void moveto(int row, int col)  void moveto(int row, int col)
46  {  {
47          if (row >= 0)          if (row >= 0)
# Line 231  int get_data(int row, int col, char *pro Line 233  int get_data(int row, int col, char *pro
233          return len;          return len;
234  }  }
235    
236  int display_data(const void *p_data, long line_total, const long *p_line_offsets, int begin_line, int wait)  int display_data(const void *p_data, long line_total, const long *p_line_offsets, int begin_line, int eof_exit,
237                                     display_data_key_handler key_handler, const char *help_filename)
238  {  {
239          static int show_help = 1;          static int show_help = 1;
240          char buffer[LINE_BUFFER_LEN];          char buffer[LINE_BUFFER_LEN];
241          int ch = KEY_NULL;          char msg_ext[MSG_EXT_MAX_LEN];
242            int ch = 0;
243          int input_ok, line, max_lines;          int input_ok, line, max_lines;
244          long int line_current = 0;          long int line_current = 0;
245          long int len;          long int len;
# Line 247  int display_data(const void *p_data, lon Line 251  int display_data(const void *p_data, lon
251          line = begin_line;          line = begin_line;
252          max_lines = SCREEN_ROWS - 1;          max_lines = SCREEN_ROWS - 1;
253    
254            // update msg_ext with extended key handler
255            if (key_handler(&ch, msg_ext, sizeof(msg_ext)) != 0)
256            {
257                    return ch;
258            }
259    
260          loop = 1;          loop = 1;
261          while (!SYS_server_exit && loop)          while (!SYS_server_exit && loop)
262          {          {
263                  if (line_current >= line_total && line_total <= SCREEN_ROWS - 2)                  if (eof_exit > 0 && line_current >= line_total && line_total <= SCREEN_ROWS - 2)
264                  {                  {
265                          if (wait)                          if (eof_exit == 1)
266                          {                          {
267                                  ch = press_any_key();                                  ch = press_any_key();
268                          }                          }
269                          else                          else // if (eof_exit == 2)
270                          {                          {
271                                  iflush();                                  iflush();
272                          }                          }
# Line 277  int display_data(const void *p_data, lon Line 287  int display_data(const void *p_data, lon
287                          }                          }
288    
289                          snprintf(buffer, sizeof(buffer),                          snprintf(buffer, sizeof(buffer),
290                                           "\033[1;44;33m第\033[32m%ld\033[33m-\033[32m%ld\033[33m行 (\033[32m%ld%%\033[33m) │ "                                           "\033[1;44;33m第\033[32m%ld\033[33m-\033[32m%ld\033[33m行 (\033[32m%ld%%\033[33m) %s",
                                          "返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ 移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] │ "  
                                          "帮助[\033[32mh\033[33m] │",  
291                                           line_current - (line - 1) + 1,                                           line_current - (line - 1) + 1,
292                                           MIN(line_current - (line - 1) + (SCREEN_ROWS - 2), line_total),                                           MIN(line_current - (line - 1) + (SCREEN_ROWS - 2), line_total),
293                                           percentile);                                           percentile, msg_ext);
294    
295                          len = split_line(buffer, SCREEN_COLS, &eol, &display_len);                          len = split_line(buffer, SCREEN_COLS, &eol, &display_len);
296                          for (;display_len < SCREEN_COLS; display_len++)                          for (; display_len < SCREEN_COLS; display_len++)
297                          {                          {
298                                  buffer[len++] = ' ';                                  buffer[len++] = ' ';
299                          }                          }
# Line 301  int display_data(const void *p_data, lon Line 309  int display_data(const void *p_data, lon
309                          {                          {
310                                  ch = igetch_t(MAX_DELAY_TIME);                                  ch = igetch_t(MAX_DELAY_TIME);
311                                  input_ok = 1;                                  input_ok = 1;
312    
313                                    // extended key handler
314                                    if (key_handler(&ch, msg_ext, sizeof(msg_ext)) != 0)
315                                    {
316                                            goto cleanup;
317                                    }
318    
319                                  switch (ch)                                  switch (ch)
320                                  {                                  {
321                                  case KEY_NULL:                                  case KEY_NULL:
322                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
323                                          goto cleanup;                                          goto cleanup;
324                                  case KEY_HOME:                                  case KEY_HOME:
325                                            if (line_current - line < 0) // Reach top
326                                            {
327                                                    break;
328                                            }
329                                          line_current = 0;                                          line_current = 0;
330                                          line = begin_line;                                          line = begin_line;
331                                          max_lines = SCREEN_ROWS - 1;                                          max_lines = SCREEN_ROWS - 1;
332                                          clrline(begin_line, SCREEN_ROWS);                                          clrline(begin_line, SCREEN_ROWS);
333                                          break;                                          break;
334                                  case KEY_END:                                  case KEY_END:
335                                            if (line_total < SCREEN_ROWS - 2)
336                                            {
337                                                    break;
338                                            }
339                                          line_current = line_total - (SCREEN_ROWS - 2);                                          line_current = line_total - (SCREEN_ROWS - 2);
340                                          line = begin_line;                                          line = begin_line;
341                                          max_lines = SCREEN_ROWS - 1;                                          max_lines = SCREEN_ROWS - 1;
# Line 377  int display_data(const void *p_data, lon Line 400  int display_data(const void *p_data, lon
400                                          loop = 0;                                          loop = 0;
401                                          break;                                          break;
402                                  case 'h':                                  case 'h':
403                                          if (!show_help)                                          if (!show_help) // Not reentrant
404                                          {                                          {
405                                                  break;                                                  break;
406                                          }                                          }
407    
408                                          // Display help information                                          // Display help information
409                                          show_help = 0;                                          show_help = 0;
410                                          display_file(DATA_READ_HELP, begin_line, 1);                                          display_file(help_filename, begin_line, 1);
411                                          show_help = 1;                                          show_help = 1;
412                                    case KEY_F5:
413                                          // Refresh after display help information                                          // Refresh after display help information
414                                          line_current -= (line - 1);                                          line_current -= (line - 1);
415                                          line = begin_line;                                          line = begin_line;
416                                          max_lines = SCREEN_ROWS - 1;                                          max_lines = SCREEN_ROWS - 1;
417                                          clrline(begin_line, SCREEN_ROWS);                                          clrline(begin_line, SCREEN_ROWS);
418                                          break;                                          break;
419                                    case 0: // Refresh bottom line
420                                            break;
421                                  default:                                  default:
422                                          input_ok = 0;                                          input_ok = 0;
423                                          break;                                          break;
# Line 426  cleanup: Line 451  cleanup:
451          return ch;          return ch;
452  }  }
453    
454  int display_file(const char *filename, int begin_line, int wait)  static int display_file_key_handler(int *key, char *msg, size_t msg_len)
455  {  {
456          int ch = KEY_NULL;          switch (*key)
457            {
458            case 0: // Set msg
459                    snprintf(msg, msg_len,
460                                     "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ "
461                                     "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] │ "
462                                     "帮助[\033[32mh\033[33m] |");
463                    break;
464            case 'H':
465                    *key = 'h';
466                    return 0;
467            }
468    
469            return 0;
470    }
471    
472    int display_file(const char *filename, int begin_line, int eof_exit)
473    {
474            int ret;
475          const void *p_shm;          const void *p_shm;
476          size_t data_len;          size_t data_len;
477          long line_total;          long line_total;
# Line 441  int display_file(const char *filename, i Line 484  int display_file(const char *filename, i
484                  return KEY_NULL;                  return KEY_NULL;
485          }          }
486    
487          ch = display_data(p_data, line_total, p_line_offsets, begin_line, wait);          ret = display_data(p_data, line_total, p_line_offsets, begin_line, eof_exit, display_file_key_handler, DATA_READ_HELP);
488    
489          if (detach_file_shm(p_shm) < 0)          if (detach_file_shm(p_shm) < 0)
490          {          {
491                  log_error("detach_file_shm(%s) error\n", filename);                  log_error("detach_file_shm(%s) error\n", filename);
492          }          }
493    
494          return ch;          return ret;
495  }  }
496    
497  int show_top(const char *str_left, const char *str_middle, const char *str_right)  int show_top(const char *str_left, const char *str_middle, const char *str_right)


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

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