/[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.81 by sysadm, Fri May 30 05:28:41 2025 UTC Revision 1.86 by sysadm, Sat May 31 14:59:18 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    
 #define MSG_EXT_MAX_LEN 200  
   
43  void moveto(int row, int col)  void moveto(int row, int col)
44  {  {
45          if (row >= 0)          if (row >= 0)
# Line 233  int get_data(int row, int col, char *pro Line 231  int get_data(int row, int col, char *pro
231          return len;          return len;
232  }  }
233    
234  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,
235                                   display_data_key_handler key_handler, const char *help_filename)                                   display_data_key_handler key_handler, const char *help_filename)
236  {  {
237          static int show_help = 1;          static int show_help = 1;
238          char buffer[LINE_BUFFER_LEN];          char buffer[LINE_BUFFER_LEN];
239          char msg_ext[MSG_EXT_MAX_LEN];          DISPLAY_CTX ctx;
240          int ch = 0;          int ch = 0;
241          int input_ok, line, max_lines;          int input_ok, line, max_lines;
242          long int line_current = 0;          long int line_current = 0;
# Line 252  int display_data(const void *p_data, lon Line 250  int display_data(const void *p_data, lon
250          max_lines = SCREEN_ROWS - 1;          max_lines = SCREEN_ROWS - 1;
251    
252          // update msg_ext with extended key handler          // update msg_ext with extended key handler
253          if (key_handler(&ch, msg_ext, sizeof(msg_ext)) != 0)          if (key_handler(&ch, &ctx) != 0)
254          {          {
255                  return ch;                  return ch;
256          }          }
# Line 260  int display_data(const void *p_data, lon Line 258  int display_data(const void *p_data, lon
258          loop = 1;          loop = 1;
259          while (!SYS_server_exit && loop)          while (!SYS_server_exit && loop)
260          {          {
261                  if (line_current >= line_total && line_total <= SCREEN_ROWS - 2)                  if (eof_exit > 0 && line_current >= line_total && line_total <= SCREEN_ROWS - 2)
262                  {                  {
263                          if (wait)                          if (eof_exit == 1)
264                          {                          {
265                                  ch = press_any_key();                                  ch = press_any_key();
266                          }                          }
267                          else                          else // if (eof_exit == 2)
268                          {                          {
269                                  iflush();                                  iflush();
270                          }                          }
# Line 277  int display_data(const void *p_data, lon Line 275  int display_data(const void *p_data, lon
275    
276                  if (line_current >= line_total || line >= max_lines)                  if (line_current >= line_total || line >= max_lines)
277                  {                  {
278                            ctx.reach_begin = (line_current < line ? 1 : 0);
279    
280                          if (line_current - (line - 1) + (SCREEN_ROWS - 2) < line_total)                          if (line_current - (line - 1) + (SCREEN_ROWS - 2) < line_total)
281                          {                          {
282                                  percentile = (line_current - (line - 1) + (SCREEN_ROWS - 2)) * 100 / line_total;                                  percentile = (line_current - (line - 1) + (SCREEN_ROWS - 2)) * 100 / line_total;
283                                    ctx.reach_end = 0;
284                          }                          }
285                          else                          else
286                          {                          {
287                                  percentile = 100;                                  percentile = 100;
288                                    ctx.reach_end = 1;
289                          }                          }
290    
291                            ctx.line_top = line_current - (line - 1) + 1;
292                            ctx.line_bottom = MIN(line_current - (line - 1) + (SCREEN_ROWS - 2), line_total);
293    
294                          snprintf(buffer, sizeof(buffer),                          snprintf(buffer, sizeof(buffer),
295                                           "\033[1;44;33m第\033[32m%ld\033[33m-\033[32m%ld\033[33m行 (\033[32m%ld%%\033[33m) %s",                                           "\033[1;44;33m第\033[32m%ld\033[33m-\033[32m%ld\033[33m行 (\033[32m%ld%%\033[33m) %s",
296                                           line_current - (line - 1) + 1,                                           ctx.line_top,
297                                           MIN(line_current - (line - 1) + (SCREEN_ROWS - 2), line_total),                                           ctx.line_bottom,
298                                           percentile, msg_ext);                                           percentile,
299                                             ctx.msg);
300    
301                          len = split_line(buffer, SCREEN_COLS, &eol, &display_len);                          len = split_line(buffer, SCREEN_COLS, &eol, &display_len);
302                          for (; display_len < SCREEN_COLS; display_len++)                          for (; display_len < SCREEN_COLS; display_len++)
# Line 311  int display_data(const void *p_data, lon Line 317  int display_data(const void *p_data, lon
317                                  input_ok = 1;                                  input_ok = 1;
318    
319                                  // extended key handler                                  // extended key handler
320                                  if (key_handler(&ch, msg_ext, sizeof(msg_ext)) != 0)                                  if (key_handler(&ch, &ctx) != 0)
321                                  {                                  {
322                                          goto cleanup;                                          goto cleanup;
323                                  }                                  }
# Line 322  int display_data(const void *p_data, lon Line 328  int display_data(const void *p_data, lon
328                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
329                                          goto cleanup;                                          goto cleanup;
330                                  case KEY_HOME:                                  case KEY_HOME:
331                                            if (line_current - line < 0) // Reach begin
332                                            {
333                                                    break;
334                                            }
335                                          line_current = 0;                                          line_current = 0;
336                                          line = begin_line;                                          line = begin_line;
337                                          max_lines = SCREEN_ROWS - 1;                                          max_lines = SCREEN_ROWS - 1;
338                                          clrline(begin_line, SCREEN_ROWS);                                          clrline(begin_line, SCREEN_ROWS);
339                                          break;                                          break;
340                                  case KEY_END:                                  case KEY_END:
341                                            if (line_total < SCREEN_ROWS - 2)
342                                            {
343                                                    break;
344                                            }
345                                          line_current = line_total - (SCREEN_ROWS - 2);                                          line_current = line_total - (SCREEN_ROWS - 2);
346                                          line = begin_line;                                          line = begin_line;
347                                          max_lines = SCREEN_ROWS - 1;                                          max_lines = SCREEN_ROWS - 1;
348                                          clrline(begin_line, SCREEN_ROWS);                                          clrline(begin_line, SCREEN_ROWS);
349                                          break;                                          break;
350                                  case KEY_UP:                                  case KEY_UP:
351                                          if (line_current - line < 0) // Reach top                                          if (line_current - line < 0) // Reach begin
352                                          {                                          {
353                                                  break;                                                  break;
354                                          }                                          }
# Line 348  int display_data(const void *p_data, lon Line 362  int display_data(const void *p_data, lon
362                                          igetch_reset();                                          igetch_reset();
363                                  case KEY_SPACE:                                  case KEY_SPACE:
364                                  case KEY_DOWN:                                  case KEY_DOWN:
365                                          if (line_current + ((SCREEN_ROWS - 2) - (line - 1)) >= line_total) // Reach bottom                                          if (line_current + ((SCREEN_ROWS - 2) - (line - 1)) >= line_total) // Reach end
366                                          {                                          {
367                                                  break;                                                  break;
368                                          }                                          }
# Line 360  int display_data(const void *p_data, lon Line 374  int display_data(const void *p_data, lon
374                                          prints("\033[S"); // Scroll up 1 line                                          prints("\033[S"); // Scroll up 1 line
375                                          break;                                          break;
376                                  case KEY_PGUP:                                  case KEY_PGUP:
377                                          if (line_current - line < 0) // Reach top                                          if (line_current - line < 0) // Reach begin
378                                          {                                          {
379                                                  break;                                                  break;
380                                          }                                          }
# Line 374  int display_data(const void *p_data, lon Line 388  int display_data(const void *p_data, lon
388                                          clrline(begin_line, SCREEN_ROWS);                                          clrline(begin_line, SCREEN_ROWS);
389                                          break;                                          break;
390                                  case KEY_PGDN:                                  case KEY_PGDN:
391                                          if (line_current + (SCREEN_ROWS - 2) - (line - 1) >= line_total) // Reach bottom                                          if (line_current + (SCREEN_ROWS - 2) - (line - 1) >= line_total) // Reach end
392                                          {                                          {
393                                                  break;                                                  break;
394                                          }                                          }
# Line 443  cleanup: Line 457  cleanup:
457          return ch;          return ch;
458  }  }
459    
460  static int display_file_key_handler(int *key, char *msg, size_t msg_len)  static int display_file_key_handler(int *p_key, DISPLAY_CTX *p_ctx)
461  {  {
462          static int topic_view = 0;          switch (*p_key)
   
         switch (*key)  
463          {          {
464          case 0: // Set msg          case 0: // Set msg
465                  snprintf(msg, msg_len,                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),
466                                   "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ "                                   "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] | "
467                                   "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] │ "                                   "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] | "
468                                   "帮助[\033[32mh\033[33m] |");                                   "帮助[\033[32mh\033[33m] |");
469                  break;                  break;
         case 'p':  
                 break;  
                 topic_view = !topic_view;  
                 if (topic_view)  
                 {  
                         snprintf(msg, msg_len,  
                                          "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ "  
                                          "同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] │ "  
                                          "帮助[\033[32mh\033[33m] |");  
                 }  
                 else  
                 {  
                         snprintf(msg, msg_len,  
                                          "| 返回[\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] |");  
                 }  
                 *key = 0;  
                 break;  
         case 'H':  
                 *key = 'h';  
                 return 0;  
470          }          }
471    
472          return 0;          return 0;
473  }  }
474    
475  int display_file(const char *filename, int begin_line, int wait)  int display_file(const char *filename, int begin_line, int eof_exit)
476  {  {
477          int ret;          int ret;
478          const void *p_shm;          const void *p_shm;
# Line 497  int display_file(const char *filename, i Line 487  int display_file(const char *filename, i
487                  return KEY_NULL;                  return KEY_NULL;
488          }          }
489    
490          ret = display_data(p_data, line_total, p_line_offsets, begin_line, wait, display_file_key_handler, DATA_READ_HELP);          ret = display_data(p_data, line_total, p_line_offsets, begin_line, eof_exit, display_file_key_handler, DATA_READ_HELP);
491    
492          if (detach_file_shm(p_shm) < 0)          if (detach_file_shm(p_shm) < 0)
493          {          {


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

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