/[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.83 by sysadm, Sat May 31 01:37:18 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 238  int display_data(const void *p_data, lon Line 236  int display_data(const void *p_data, lon
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 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                                          line_current = line_total - (SCREEN_ROWS - 2);                                          if (line_total < SCREEN_ROWS - 2)
                                         if (line_current < 0)  
342                                          {                                          {
343                                                  line_current = 0;                                                  break;
344                                          }                                          }
345                                            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 352  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 364  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 378  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 447  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          switch (*key)          switch (*p_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 'H':  
                 *key = 'h';  
                 return 0;  
470          }          }
471    
472          return 0;          return 0;


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

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