/[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.81 by sysadm, Fri May 30 05:28:41 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 wait,
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          {          {
# 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:
# Line 377  int display_data(const void *p_data, lon Line 392  int display_data(const void *p_data, lon
392                                          loop = 0;                                          loop = 0;
393                                          break;                                          break;
394                                  case 'h':                                  case 'h':
395                                          if (!show_help)                                          if (!show_help) // Not reentrant
396                                          {                                          {
397                                                  break;                                                  break;
398                                          }                                          }
399    
400                                          // Display help information                                          // Display help information
401                                          show_help = 0;                                          show_help = 0;
402                                          display_file(DATA_READ_HELP, begin_line, 1);                                          display_file(help_filename, begin_line, 1);
403                                          show_help = 1;                                          show_help = 1;
404                                    case KEY_F5:
405                                          // Refresh after display help information                                          // Refresh after display help information
406                                          line_current -= (line - 1);                                          line_current -= (line - 1);
407                                          line = begin_line;                                          line = begin_line;
408                                          max_lines = SCREEN_ROWS - 1;                                          max_lines = SCREEN_ROWS - 1;
409                                          clrline(begin_line, SCREEN_ROWS);                                          clrline(begin_line, SCREEN_ROWS);
410                                          break;                                          break;
411                                    case 0: // Refresh bottom line
412                                            break;
413                                  default:                                  default:
414                                          input_ok = 0;                                          input_ok = 0;
415                                          break;                                          break;
# Line 426  cleanup: Line 443  cleanup:
443          return ch;          return ch;
444  }  }
445    
446    static int display_file_key_handler(int *key, char *msg, size_t msg_len)
447    {
448            static int topic_view = 0;
449    
450            switch (*key)
451            {
452            case 0: // Set msg
453                    snprintf(msg, msg_len,
454                                     "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ "
455                                     "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] │ "
456                                     "帮助[\033[32mh\033[33m] |");
457                    break;
458            case 'p':
459                    break;
460                    topic_view = !topic_view;
461                    if (topic_view)
462                    {
463                            snprintf(msg, msg_len,
464                                             "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ "
465                                             "同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] │ "
466                                             "帮助[\033[32mh\033[33m] |");
467                    }
468                    else
469                    {
470                            snprintf(msg, msg_len,
471                                             "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ "
472                                             "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] │ "
473                                             "帮助[\033[32mh\033[33m] |");
474                    }
475                    *key = 0;
476                    break;
477            case 'H':
478                    *key = 'h';
479                    return 0;
480            }
481    
482            return 0;
483    }
484    
485  int display_file(const char *filename, int begin_line, int wait)  int display_file(const char *filename, int begin_line, int wait)
486  {  {
487          int ch = KEY_NULL;          int ret;
488          const void *p_shm;          const void *p_shm;
489          size_t data_len;          size_t data_len;
490          long line_total;          long line_total;
# Line 441  int display_file(const char *filename, i Line 497  int display_file(const char *filename, i
497                  return KEY_NULL;                  return KEY_NULL;
498          }          }
499    
500          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, wait, display_file_key_handler, DATA_READ_HELP);
501    
502          if (detach_file_shm(p_shm) < 0)          if (detach_file_shm(p_shm) < 0)
503          {          {
504                  log_error("detach_file_shm(%s) error\n", filename);                  log_error("detach_file_shm(%s) error\n", filename);
505          }          }
506    
507          return ch;          return ret;
508  }  }
509    
510  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