/[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.82 by sysadm, Fri May 30 12:51:00 2025 UTC Revision 1.88 by sysadm, Thu Jun 5 11:48:35 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                                            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 424  int display_data(const void *p_data, lon Line 438  int display_data(const void *p_data, lon
438                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];
439                  if (len >= LINE_BUFFER_LEN)                  if (len >= LINE_BUFFER_LEN)
440                  {                  {
441                          log_error("buffer overflow: len=%ld(%ld - %ld) line=%ld \n",                          log_error("Buffer overflow: len=%ld(%ld - %ld) line=%ld \n",
442                                            len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);                                            len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);
443                          len = LINE_BUFFER_LEN - 1;                          len = LINE_BUFFER_LEN - 1;
444                  }                  }
445                    else if (len < 0)
446                    {
447                            log_error("Incorrect line offsets: len=%ld(%ld - %ld) line=%ld \n",
448                                              len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);
449                            len = 0;
450                    }
451    
452                  memcpy(buffer, (const char *)p_data + p_line_offsets[line_current], (size_t)len);                  memcpy(buffer, (const char *)p_data + p_line_offsets[line_current], (size_t)len);
453                  buffer[len] = '\0';                  buffer[len] = '\0';
# Line 443  cleanup: Line 463  cleanup:
463          return ch;          return ch;
464  }  }
465    
466  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)
467  {  {
468          switch (*key)          switch (*p_key)
469          {          {
470          case 0: // Set msg          case 0: // Set msg
471                  snprintf(msg, msg_len,                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),
472                                   "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ "                                   "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] | "
473                                   "移动[\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] | "
474                                   "帮助[\033[32mh\033[33m] |");                                   "帮助[\033[32mh\033[33m] |");
475                  break;                  break;
         case 'H':  
                 *key = 'h';  
                 return 0;  
476          }          }
477    
478          return 0;          return 0;
# Line 530  int show_bottom(const char *msg) Line 547  int show_bottom(const char *msg)
547          int msg_len;          int msg_len;
548          int len;          int len;
549          int len_username;          int len_username;
550            char str_tm_online[LINE_BUFFER_LEN];
551    
552          get_time_str(str_time, sizeof(str_time));          get_time_str(str_time, sizeof(str_time));
553    
# Line 547  int show_bottom(const char *msg) Line 565  int show_bottom(const char *msg)
565    
566          time_online = time(0) - BBS_login_tm;          time_online = time(0) - BBS_login_tm;
567          tm_online = gmtime(&time_online);          tm_online = gmtime(&time_online);
568            if (tm_online->tm_mday > 1)
569            {
570                    snprintf(str_tm_online, sizeof(str_tm_online),
571                                    "\033[36m%2d\033[33m天\033[36m%2d\033[33m时",
572                                    tm_online->tm_mday - 1, tm_online->tm_hour);
573            }
574            else
575            {
576                    snprintf(str_tm_online, sizeof(str_tm_online),
577                                    "\033[36m%2d\033[33m时\033[36m%2d\033[33m分",
578                                    tm_online->tm_hour, tm_online->tm_min);
579            }
580    
581          moveto(SCREEN_ROWS, 0);          moveto(SCREEN_ROWS, 0);
582          clrtoeol();          clrtoeol();
583          prints("\033[1;44;33m时间[\033[36m%s\033[33m]%s%*s \033[33m帐号[\033[36m%s\033[33m]"          prints("\033[1;44;33m时间[\033[36m%s\033[33m]%s%*s \033[33m帐号[\033[36m%s\033[33m][%s\033[33m]\033[m",
584                     "[\033[36m%1d\033[33m天\033[36m%2d\033[33m时\033[36m%2d\033[33m分]\033[m",                     str_time, msg_f, 38 - msg_len - len_username, "", BBS_username, str_tm_online);
                    str_time, msg_f, 35 - msg_len - len_username, "", BBS_username,  
                    tm_online->tm_mday - 1, tm_online->tm_hour, tm_online->tm_min);  
585    
586          return 0;          return 0;
587  }  }


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

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