/[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.102 by sysadm, Sat Jun 21 02:15:18 2025 UTC Revision 1.120 by sysadm, Tue Oct 28 05:08:50 2025 UTC
# Line 36  Line 36 
36    
37  #define ACTIVE_BOARD_HEIGHT 8  #define ACTIVE_BOARD_HEIGHT 8
38    
39  #define STR_TOP_LEFT_MAX_LEN 40  #define STR_TOP_LEFT_MAX_LEN 80
40  #define STR_TOP_MIDDLE_MAX_LEN 20  #define STR_TOP_MIDDLE_MAX_LEN 40
41  #define STR_TOP_RIGHT_MAX_LEN 20  #define STR_TOP_RIGHT_MAX_LEN 80
42    
43    static size_t get_time_str(char *s, size_t len)
44    {
45            time_t curtime;
46            struct tm local_tm;
47    
48            time(&curtime);
49            localtime_r(&curtime, &local_tm);
50            size_t j = strftime(s, len, "%m/%d %H:%M %Z", &local_tm);
51    
52            return j;
53    }
54    
55  void moveto(int row, int col)  void moveto(int row, int col)
56  {  {
# Line 81  void clearscr() Line 93  void clearscr()
93          moveto(0, 0);          moveto(0, 0);
94  }  }
95    
96  int press_any_key()  inline int press_any_key()
97  {  {
98            return press_any_key_ex("                           \033[1;33m按任意键继续...\033[m", 60);
99    }
100    
101    int press_any_key_ex(const char *msg, int sec)
102    {
103            int ch = 0;
104            int duration = 0;
105            time_t t_begin = time(NULL);
106    
107          moveto(SCREEN_ROWS, 0);          moveto(SCREEN_ROWS, 0);
108          clrtoeol();          clrtoeol();
109    
110          prints("                           \033[1;33m...\033[0;37m");          prints(msg);
111          iflush();          iflush();
112    
113          return igetch_t(MIN(MAX_DELAY_TIME, 60));          igetch_reset();
114    
115            do
116            {
117                    ch = igetch_t(sec - duration);
118                    duration = (int)(time(NULL) - t_begin);
119            } while (!SYS_server_exit && ch == 0 && duration < 60);
120    
121            return ch;
122  }  }
123    
124  void set_input_echo(int echo)  void set_input_echo(int echo)
# Line 97  void set_input_echo(int echo) Line 126  void set_input_echo(int echo)
126          if (echo)          if (echo)
127          {          {
128                  outc('\x83'); // ASCII code 131                  outc('\x83'); // ASCII code 131
                 iflush();  
129          }          }
130          else          else
131          {          {
132                  //    outc ('\x85'); // ASCII code 133                  // outc ('\x85'); // ASCII code 133
133                  prints("\xff\xfb\x01\xff\xfb\x03");                  prints("\xff\xfb\x01\xff\xfb\x03");
                 iflush();  
                 igetch(0);  
                 igetch_reset();  
134          }          }
135            iflush();
136  }  }
137    
138  static int _str_input(char *buffer, int buf_size, int echo_mode)  static int _str_input(char *buffer, int buf_size, int max_display_len, int echo_mode)
139  {  {
140          int c;          int ch;
141          int offset = 0;          int offset = 0;
142          int hz = 0;          int eol;
143            int display_len;
144            char input_str[4];
145            int str_len = 0;
146            char c;
147    
148          buffer[buf_size - 1] = '\0';          buffer[buf_size - 1] = '\0';
149          for (offset = 0; offset < buf_size - 1 && buffer[offset] != '\0'; offset++)          offset = split_line(buffer, max_display_len, &eol, &display_len, 0);
                 ;  
150    
151          igetch_reset();          igetch_reset();
152    
153          while (!SYS_server_exit)          while (!SYS_server_exit)
154          {          {
155                  c = igetch_t(MIN(MAX_DELAY_TIME, 60));                  ch = igetch_t(MIN(MAX_DELAY_TIME, 60));
156    
157                  if (c == CR)                  if (ch == CR)
158                  {                  {
                         igetch_reset();  
159                          break;                          break;
160                  }                  }
161                  else if (c == KEY_TIMEOUT || c == KEY_NULL) // timeout or broken pipe                  else if (ch == KEY_TIMEOUT || ch == KEY_NULL) // timeout or broken pipe
162                  {                  {
163                          return -1;                          return -1;
164                  }                  }
165                  else if (c == LF || c == '\0')                  else if (ch == LF || ch == '\0')
166                  {                  {
167                          continue;                          continue;
168                  }                  }
169                  else if (c == BACKSPACE)                  else if (ch == BACKSPACE)
170                  {                  {
171                          if (offset > 0)                          if (offset > 0)
172                          {                          {
173                                  offset--;                                  offset--;
174                                  if (buffer[offset] < 0 || buffer[offset] > 127)                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
175                                  {                                  {
176                                          prints("\033[D \033[D");                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
                                         offset--;  
                                         if (offset < 0) // should not happen  
177                                          {                                          {
178                                                  log_error("Offset of buffer is negative\n");                                                  offset--;
                                                 offset = 0;  
179                                          }                                          }
180                                            display_len--;
181                                            prints("\033[D \033[D");
182                                  }                                  }
183                                  buffer[offset] = '\0';                                  buffer[offset] = '\0';
184                                    display_len--;
185                                  prints("\033[D \033[D");                                  prints("\033[D \033[D");
186                                  iflush();                                  iflush();
187                          }                          }
188                          continue;                          continue;
189                  }                  }
190                  else if (c > 255 || iscntrl(c))                  else if (ch > 255 || iscntrl(ch))
191                  {                  {
192                          continue;                          continue;
193                  }                  }
194                  else if (c > 127 && c <= 255)                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character
195                  {                  {
196                          if (!hz && offset + 2 > buf_size - 1) // No enough space for Chinese character                          str_len = 0;
197                            c = (char)(ch & 0xf0);
198                            while (c & 0x80)
199                            {
200                                    input_str[str_len] = (char)(ch - 256);
201                                    str_len++;
202                                    c = (c & 0x7f) << 1;
203    
204                                    if ((c & 0x80) == 0) // Input completed
205                                    {
206                                            break;
207                                    }
208    
209                                    // Expect additional bytes of input
210                                    ch = igetch(100);                                                // 0.1 second
211                                    if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input
212                                    {
213    #ifdef _DEBUG
214                                            log_error("Ignore %d bytes of incomplete UTF8 character\n", str_len);
215    #endif
216                                            str_len = 0;
217                                            break;
218                                    }
219                            }
220    
221                            if (str_len == 0) // Incomplete input
222                            {
223                                    continue;
224                            }
225    
226                            if (offset + str_len > buf_size - 1 || display_len + 2 > max_display_len) // No enough space for Chinese character
227                          {                          {
                                 igetch(0); // Ignore 1 character  
228                                  outc('\a');                                  outc('\a');
229                                  iflush();                                  iflush();
230                                  continue;                                  continue;
231                          }                          }
                         hz = (!hz);  
                 }  
232    
233                  if (offset + 1 > buf_size - 1)                          memcpy(buffer + offset, input_str, (size_t)str_len);
234                  {                          offset += str_len;
235                          outc('\a');                          buffer[offset] = '\0';
236                          iflush();                          display_len += 2;
237                          continue;  
238                            switch (echo_mode)
239                            {
240                            case DOECHO:
241                                    prints(input_str);
242                                    break;
243                            case NOECHO:
244                                    prints("**");
245                                    break;
246                            }
247                  }                  }
248                    else if (ch >= 32 && ch < 127) // Printable character
249                    {
250                            if (offset + 1 > buf_size - 1 || display_len + 1 > max_display_len)
251                            {
252                                    outc('\a');
253                                    iflush();
254                                    continue;
255                            }
256    
257                  buffer[offset++] = (char)c;                          buffer[offset++] = (char)ch;
258                  buffer[offset] = '\0';                          buffer[offset] = '\0';
259                            display_len++;
260    
261                  switch (echo_mode)                          switch (echo_mode)
262                  {                          {
263                  case DOECHO:                          case DOECHO:
264                          outc((char)c);                                  outc((char)ch);
265                          break;                                  break;
266                  case NOECHO:                          case NOECHO:
267                          outc('*');                                  outc('*');
268                          break;                                  break;
269                            }
270                  }                  }
271                  if (!hz)                  else // Invalid character
272                  {                  {
273                          iflush();                          continue;
274                  }                  }
275    
276                    iflush();
277          }          }
278    
279          return offset;          return offset;
# Line 209  int str_input(char *buffer, int buf_size Line 285  int str_input(char *buffer, int buf_size
285    
286          buffer[0] = '\0';          buffer[0] = '\0';
287    
288          len = _str_input(buffer, buf_size, echo_mode);          len = _str_input(buffer, buf_size, buf_size, echo_mode);
289    
290          prints("\r\n");          prints("\r\n");
291          iflush();          iflush();
292    
293          return len;          return len;
294  };  }
295    
296  int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int echo_mode)  int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int max_display_len)
297  {  {
298          int len;          int len = 0;
299            int col_cur = 0;
300            int ch;
301            int offset = 0;
302            int eol;
303            int display_len;
304            char input_str[4];
305            int str_len = 0;
306            char c;
307    
308            buffer[buf_size - 1] = '\0';
309            offset = split_line(buffer, max_display_len, &eol, &display_len, 0);
310            buffer[offset] = '\0';
311            len = offset;
312            col_cur = col + str_length(prompt, 1) + display_len;
313    
314          moveto(row, col);          moveto(row, col);
315          prints("%s", prompt);          prints("%s", prompt);
316          prints("%s", buffer);          prints("%s", buffer);
317            prints("%*s", max_display_len - display_len, "");
318            moveto(row, col_cur);
319          iflush();          iflush();
320    
321          len = _str_input(buffer, buf_size, echo_mode);          igetch_reset();
322    
323            while (!SYS_server_exit)
324            {
325                    ch = igetch_t(MIN(MAX_DELAY_TIME, 60));
326    
327                    if (ch == CR)
328                    {
329                            break;
330                    }
331                    else if (ch == KEY_TIMEOUT || ch == KEY_NULL) // timeout or broken pipe
332                    {
333                            return -1;
334                    }
335                    else if (ch == LF || ch == '\0')
336                    {
337                            continue;
338                    }
339                    else if (ch == BACKSPACE)
340                    {
341                            if (offset > 0)
342                            {
343                                    str_len = 1;
344                                    offset--;
345                                    if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
346                                    {
347                                            while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
348                                            {
349                                                    str_len++;
350                                                    offset--;
351                                            }
352                                            display_len--;
353                                            col_cur--;
354                                    }
355    
356                                    memmove(buffer + offset, buffer + offset + str_len, (size_t)(len - offset - str_len));
357                                    len -= str_len;
358                                    buffer[len] = '\0';
359                                    display_len--;
360                                    col_cur--;
361    
362                                    moveto(row, col_cur);
363                                    prints("%s", buffer + offset);
364                                    prints("%*s", max_display_len - display_len, "");
365                                    moveto(row, col_cur);
366                                    iflush();
367                            }
368                            continue;
369                    }
370                    else if (ch == KEY_DEL)
371                    {
372                            if (offset < len)
373                            {
374                                    if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
375                                    {
376                                            str_len = 0;
377                                            c = (char)(buffer[offset] & 0xf0);
378                                            while (c & 0x80)
379                                            {
380                                                    str_len++;
381                                                    c = (c & 0x7f) << 1;
382                                            }
383                                            display_len--;
384                                    }
385                                    else
386                                    {
387                                            str_len = 1;
388                                    }
389    
390                                    memmove(buffer + offset, buffer + offset + str_len, (size_t)(len - offset - str_len));
391                                    len -= str_len;
392                                    buffer[len] = '\0';
393                                    display_len--;
394    
395                                    moveto(row, col_cur);
396                                    prints("%s", buffer + offset);
397                                    prints("%*s", max_display_len - display_len, "");
398                                    moveto(row, col_cur);
399                                    iflush();
400                            }
401                            continue;
402                    }
403                    else if (ch == KEY_LEFT)
404                    {
405                            if (offset > 0)
406                            {
407                                    str_len = 1;
408                                    offset--;
409                                    if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
410                                    {
411                                            while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
412                                            {
413                                                    str_len++;
414                                                    offset--;
415                                            }
416                                            col_cur--;
417                                    }
418                                    col_cur--;
419    
420                                    moveto(row, col_cur);
421                                    iflush();
422                            }
423                            continue;
424                    }
425                    else if (ch == KEY_RIGHT)
426                    {
427                            if (offset < len)
428                            {
429                                    str_len = 0;
430                                    if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
431                                    {
432                                            c = (char)(buffer[offset] & 0xf0);
433                                            while (c & 0x80)
434                                            {
435                                                    str_len++;
436                                                    c = (c & 0x7f) << 1;
437                                            }
438                                            col_cur++;
439                                    }
440                                    else
441                                    {
442                                            str_len = 1;
443                                    }
444    
445                                    col_cur++;
446                                    offset += str_len;
447    
448                                    moveto(row, col_cur);
449                                    iflush();
450                            }
451                            continue;
452                    }
453                    else if (ch == KEY_HOME || ch == KEY_UP)
454                    {
455                            if (offset > 0)
456                            {
457                                    offset = 0;
458                                    col_cur = col + str_length(prompt, 1);
459    
460                                    moveto(row, col_cur);
461                                    iflush();
462                            }
463                            continue;
464                    }
465                    else if (ch == KEY_END || ch == KEY_DOWN)
466                    {
467                            if (offset < len)
468                            {
469                                    offset = len;
470                                    col_cur = col + str_length(prompt, 1) + display_len;
471    
472                                    moveto(row, col_cur);
473                                    iflush();
474                            }
475                            continue;
476                    }
477                    else if (ch > 255 || iscntrl(ch))
478                    {
479                            continue;
480                    }
481                    else if ((ch & 0xff80) == 0x80) // head of multi-byte character
482                    {
483                            str_len = 0;
484                            c = (char)(ch & 0xf0);
485                            while (c & 0x80)
486                            {
487                                    input_str[str_len] = (char)(ch - 256);
488                                    str_len++;
489                                    c = (c & 0x7f) << 1;
490    
491                                    if ((c & 0x80) == 0) // Input completed
492                                    {
493                                            break;
494                                    }
495    
496                                    // Expect additional bytes of input
497                                    ch = igetch(100);                                                // 0.1 second
498                                    if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input
499                                    {
500    #ifdef _DEBUG
501                                            log_error("Ignore %d bytes of incomplete UTF8 character\n", str_len);
502    #endif
503                                            str_len = 0;
504                                            break;
505                                    }
506                            }
507    
508                            if (str_len == 0) // Incomplete input
509                            {
510                                    continue;
511                            }
512    
513                            if (len + str_len > buf_size - 1 || display_len + 2 > max_display_len) // No enough space for Chinese character
514                            {
515                                    outc('\a');
516                                    iflush();
517                                    continue;
518                            }
519    
520                            memmove(buffer + offset + str_len, buffer + offset, (size_t)(len - offset));
521                            memcpy(buffer + offset, input_str, (size_t)str_len);
522                            len += str_len;
523                            buffer[len] = '\0';
524                            display_len += 2;
525    
526                            moveto(row, col_cur);
527                            prints("%s", buffer + offset);
528                            prints("%*s", max_display_len - display_len, "");
529    
530                            col_cur += 2;
531    
532                            moveto(row, col_cur);
533                            iflush();
534    
535                            offset += str_len;
536                    }
537                    else if (ch >= 32 && ch < 127) // Printable character
538                    {
539                            if (len + 1 > buf_size - 1 || display_len + 1 > max_display_len)
540                            {
541                                    outc('\a');
542                                    iflush();
543                                    continue;
544                            }
545    
546                            memmove(buffer + offset + 1, buffer + offset, (size_t)(len - offset));
547                            buffer[offset] = (char)ch;
548                            len++;
549                            buffer[len] = '\0';
550                            display_len++;
551    
552                            moveto(row, col_cur);
553                            prints("%s", buffer + offset);
554                            prints("%*s", max_display_len - display_len, "");
555    
556                            col_cur++;
557    
558                            moveto(row, col_cur);
559                            iflush();
560    
561                            offset++;
562                    }
563                    else // Invalid character
564                    {
565                            continue;
566                    }
567            }
568    
569          return len;          return len;
570  }  }
# Line 294  int display_data(const void *p_data, lon Line 632  int display_data(const void *p_data, lon
632                          ctx.line_bottom = MIN(line_current - (output_current_row - screen_begin_row) + screen_row_total, display_line_total);                          ctx.line_bottom = MIN(line_current - (output_current_row - screen_begin_row) + screen_row_total, display_line_total);
633    
634                          snprintf(buffer, sizeof(buffer),                          snprintf(buffer, sizeof(buffer),
635                                           "\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",
636                                           ctx.line_top,                                           ctx.line_top,
637                                           ctx.line_bottom,                                           ctx.line_bottom,
638                                           percentile,                                           percentile,
# Line 318  int display_data(const void *p_data, lon Line 656  int display_data(const void *p_data, lon
656                                  ch = igetch_t(MAX_DELAY_TIME);                                  ch = igetch_t(MAX_DELAY_TIME);
657                                  input_ok = 1;                                  input_ok = 1;
658    
659                                    if (ch != KEY_NULL && ch != KEY_TIMEOUT)
660                                    {
661                                            BBS_last_access_tm = time(NULL);
662                                    }
663    
664                                  // extended key handler                                  // extended key handler
665                                  if (key_handler(&ch, &ctx) != 0)                                  if (key_handler(&ch, &ctx) != 0)
666                                  {                                  {
# Line 327  int display_data(const void *p_data, lon Line 670  int display_data(const void *p_data, lon
670                                  switch (ch)                                  switch (ch)
671                                  {                                  {
672                                  case KEY_NULL:                                  case KEY_NULL:
673                                            log_error("KEY_NULL\n");
674                                            goto cleanup;
675                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
676                                            log_error("User input timeout\n");
677                                          goto cleanup;                                          goto cleanup;
678                                  case KEY_HOME:                                  case KEY_HOME:
679                                          if (line_current - output_current_row < 0) // Reach begin                                          if (line_current - output_current_row < 0) // Reach begin
# Line 361  int display_data(const void *p_data, lon Line 707  int display_data(const void *p_data, lon
707                                          output_end_row = SCREEN_ROWS - 1; // Legacy Fterm only works with this line                                          output_end_row = SCREEN_ROWS - 1; // Legacy Fterm only works with this line
708                                          break;                                          break;
709                                  case CR:                                  case CR:
                                         igetch_reset();  
                                 case KEY_SPACE:  
710                                  case KEY_DOWN:                                  case KEY_DOWN:
711                                          if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= display_line_total) // Reach end                                          if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= display_line_total) // Reach end
712                                          {                                          {
# Line 373  int display_data(const void *p_data, lon Line 717  int display_data(const void *p_data, lon
717                                          output_end_row = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
718                                          moveto(SCREEN_ROWS, 0);                                          moveto(SCREEN_ROWS, 0);
719                                          clrtoeol();                                          clrtoeol();
720                                          prints("\033[S"); // Scroll up 1 line                                          // prints("\033[S"); // Scroll up 1 line
721                                            prints("\n"); // Legacy Cterm only works with this line
722                                          break;                                          break;
723                                  case KEY_PGUP:                                  case KEY_PGUP:
724                                          if (line_current - output_current_row < 0) // Reach begin                                          if (line_current - output_current_row < 0) // Reach begin
# Line 389  int display_data(const void *p_data, lon Line 734  int display_data(const void *p_data, lon
734                                          output_end_row = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
735                                          clrline(output_current_row, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
736                                          break;                                          break;
737                                    case KEY_SPACE:
738                                  case KEY_PGDN:                                  case KEY_PGDN:
739                                          if (line_current + screen_row_total - (output_current_row - screen_begin_row) >= display_line_total) // Reach end                                          if (line_current + screen_row_total - (output_current_row - screen_begin_row) >= display_line_total) // Reach end
740                                          {                                          {
# Line 429  int display_data(const void *p_data, lon Line 775  int display_data(const void *p_data, lon
775                                          input_ok = 0;                                          input_ok = 0;
776                                          break;                                          break;
777                                  }                                  }
   
                                 BBS_last_access_tm = time(NULL);  
778                          }                          }
779    
780                          continue;                          continue;
# Line 470  static int display_file_key_handler(int Line 814  static int display_file_key_handler(int
814          {          {
815          case 0: // Set msg          case 0: // Set msg
816                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),
817                                   "| [\033[32m\033[33m,\033[32mESC\033[33m] | "                                   "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] | "
818                                   "ƶ[\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] | "
819                                   "[\033[32mh\033[33m] |");                                   "帮助[\033[32mh\033[33m] |");
820                  break;                  break;
821          }          }
822    
# Line 522  int show_top(const char *str_left, const Line 866  int show_top(const char *str_left, const
866    
867          strncpy(str_left_f, str_left, sizeof(str_left_f) - 1);          strncpy(str_left_f, str_left, sizeof(str_left_f) - 1);
868          str_left_f[sizeof(str_left_f) - 1] = '\0';          str_left_f[sizeof(str_left_f) - 1] = '\0';
869          len = split_line(str_left_f, STR_TOP_LEFT_MAX_LEN, &eol, &str_left_len, 1);          len = split_line(str_left_f, STR_TOP_LEFT_MAX_LEN / 2, &eol, &str_left_len, 1);
870          str_left_f[len] = '\0';          str_left_f[len] = '\0';
871    
872          strncpy(str_middle_f, str_middle, sizeof(str_middle_f) - 1);          strncpy(str_middle_f, str_middle, sizeof(str_middle_f) - 1);
873          str_middle_f[sizeof(str_middle_f) - 1] = '\0';          str_middle_f[sizeof(str_middle_f) - 1] = '\0';
874          len = split_line(str_middle, STR_TOP_MIDDLE_MAX_LEN, &eol, &str_middle_len, 1);          len = split_line(str_middle, STR_TOP_MIDDLE_MAX_LEN / 2, &eol, &str_middle_len, 1);
875          str_middle_f[len] = '\0';          str_middle_f[len] = '\0';
876    
877          strncpy(str_right_f, str_right, sizeof(str_right_f) - 1);          strncpy(str_right_f, str_right, sizeof(str_right_f) - 1);
878          str_right_f[sizeof(str_right_f) - 1] = '\0';          str_right_f[sizeof(str_right_f) - 1] = '\0';
879          len = split_line(str_right, STR_TOP_RIGHT_MAX_LEN, &eol, &str_right_len, 1);          len = split_line(str_right, STR_TOP_RIGHT_MAX_LEN / 2, &eol, &str_right_len, 1);
880          str_right_f[len] = '\0';          str_right_f[len] = '\0';
881    
882          moveto(1, 0);          moveto(1, 0);
883          clrtoeol();          clrtoeol();
884          prints("\033[1;44;33m%s\033[37m%*s\033[33m%*s\033[m",          prints("\033[1;44;33m%s\033[37m%*s%s\033[33m%*s%s\033[m",
885                     str_left_f, 44 - str_left_len, str_middle_f, 36, str_right_f);                     str_left_f, 44 - str_left_len - str_middle_len, "",
886                       str_middle_f, 36 - str_right_len, "", str_right_f);
887    
888          return 0;          return 0;
889  }  }
# Line 546  int show_top(const char *str_left, const Line 891  int show_top(const char *str_left, const
891  int show_bottom(const char *msg)  int show_bottom(const char *msg)
892  {  {
893          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
894            int len_str_time;
895          time_t time_online;          time_t time_online;
896          struct tm *tm_online;          struct tm *tm_online;
897          char msg_f[LINE_BUFFER_LEN];          char msg_f[LINE_BUFFER_LEN];
898          int eol;          int eol;
899          int msg_len;          int len_msg;
900          int len;          int len;
901          int len_username;          int len_username;
902          char str_tm_online[LINE_BUFFER_LEN];          char str_tm_online[LINE_BUFFER_LEN];
903    
904          get_time_str(str_time, sizeof(str_time));          len_str_time = (int)get_time_str(str_time, sizeof(str_time));
905    
906          msg_f[0] = '\0';          msg_f[0] = '\0';
907          msg_len = 0;          len_msg = 0;
908          if (msg != NULL)          if (msg != NULL)
909          {          {
910                  strncpy(msg_f, msg, sizeof(msg_f) - 1);                  strncpy(msg_f, msg, sizeof(msg_f) - 1);
911                  msg_f[sizeof(msg_f) - 1] = '\0';                  msg_f[sizeof(msg_f) - 1] = '\0';
912                  len = split_line(msg_f, 23, &eol, &msg_len, 1);                  len = split_line(msg_f, 23, &eol, &len_msg, 1);
913                  msg_f[len] = '\0';                  msg_f[len] = '\0';
914          }          }
915    
# Line 574  int show_bottom(const char *msg) Line 920  int show_bottom(const char *msg)
920          if (tm_online->tm_mday > 1)          if (tm_online->tm_mday > 1)
921          {          {
922                  snprintf(str_tm_online, sizeof(str_tm_online),                  snprintf(str_tm_online, sizeof(str_tm_online),
923                                   "\033[36m%2d\033[33m\033[36m%2d\033[33mʱ",                                   "\033[36m%d\033[33md \033[36m%d\033[33m:\033[36m%.2d",
924                                   tm_online->tm_mday - 1, tm_online->tm_hour);                                   tm_online->tm_mday - 1, tm_online->tm_hour, tm_online->tm_min);
925          }          }
926          else          else
927          {          {
928                  snprintf(str_tm_online, sizeof(str_tm_online),                  snprintf(str_tm_online, sizeof(str_tm_online),
929                                   "\033[36m%2d\033[33mʱ\033[36m%2d\033[33m",                                   "\033[36m%d\033[33m:\033[36m%.2d",
930                                   tm_online->tm_hour, tm_online->tm_min);                                   tm_online->tm_hour, tm_online->tm_min);
931          }          }
932    
933          moveto(SCREEN_ROWS, 0);          moveto(SCREEN_ROWS, 0);
934          clrtoeol();          clrtoeol();
935          prints("\033[1;44;33mʱ[\033[36m%s\033[33m]%s%*s \033[33mʺ[\033[36m%s\033[33m][%s\033[33m]\033[m",          prints("\033[1;44;33m时间[\033[36m%s\033[33m]%s%*s \033[33m用户[\033[36m%s\033[33m][%s\033[33m]\033[m",
936                     str_time, msg_f, 38 - msg_len - len_username, "", BBS_username, str_tm_online);                     str_time, msg_f, 61 - len_str_time - len_msg - len_username, "", BBS_username, str_tm_online);
937    
938          return 0;          return 0;
939  }  }


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

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