/[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.113 by sysadm, Fri Oct 17 11:23:30 2025 UTC Revision 1.124 by sysadm, Wed Nov 5 02:33:30 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                                    screen.c  -  description  /*
3                                                           -------------------   * screen
4          Copyright            : (C) 2004-2025 by Leaflet   *   - advanced telnet-based user interactive input / output features
5          Email                : leaflet@leafok.com   *
6   ***************************************************************************/   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>
7     */
 /***************************************************************************  
  *                                                                         *  
  *   This program is free software; you can redistribute it and/or modify  *  
  *   it under the terms of the GNU General Public License as published by  *  
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
8    
9  #include "bbs.h"  #include "bbs.h"
10  #include "common.h"  #include "common.h"
# Line 34  Line 26 
26  #include <sys/shm.h>  #include <sys/shm.h>
27  #include <sys/types.h>  #include <sys/types.h>
28    
29  #define ACTIVE_BOARD_HEIGHT 8  const char CTRL_SEQ_CLR_LINE[] = "\033[K";
30    
31  #define STR_TOP_LEFT_MAX_LEN 80  static const int ACTIVE_BOARD_HEIGHT = 8;
 #define STR_TOP_MIDDLE_MAX_LEN 40  
 #define STR_TOP_RIGHT_MAX_LEN 80  
32    
33  static const char *get_time_str(char *s, size_t len)  static const int STR_TOP_LEFT_MAX_LEN = 80;
34    static const int STR_TOP_MIDDLE_MAX_LEN = 40;
35    static const int STR_TOP_RIGHT_MAX_LEN = 80;
36    
37    static size_t get_time_str(char *s, size_t len)
38  {  {
         static const char *weekday[] = {  
                 "天", "一", "二", "三", "四", "五", "六"};  
39          time_t curtime;          time_t curtime;
40          struct tm local_tm;          struct tm local_tm;
41    
42          time(&curtime);          time(&curtime);
43          localtime_r(&curtime, &local_tm);          localtime_r(&curtime, &local_tm);
44          size_t j = strftime(s, len, "%b %d %H:%M 星期", &local_tm);          size_t j = strftime(s, len, "%m/%d %H:%M %Z", &local_tm);
   
         if (j == 0 || j + strlen(weekday[local_tm.tm_wday]) + 1 > len)  
         {  
                 return NULL;  
         }  
   
         strncat(s, weekday[local_tm.tm_wday], len - 1 - j);  
45    
46          return s;          return j;
47  }  }
48    
49  void moveto(int row, int col)  void moveto(int row, int col)
# Line 104  void clearscr() Line 89  void clearscr()
89    
90  inline int press_any_key()  inline int press_any_key()
91  {  {
92          return press_any_key_ex("                           \033[1;33m按任意键继续...\033[m");          return press_any_key_ex("                           \033[1;33m按任意键继续...\033[m", 60);
93  }  }
94    
95  int press_any_key_ex(const char *msg)  int press_any_key_ex(const char *msg, int sec)
96  {  {
97          int ch = 0;          int ch = 0;
         int wait_seconds = 60;  
98          int duration = 0;          int duration = 0;
99          time_t t_begin = time(NULL);          time_t t_begin = time(NULL);
100    
# Line 120  int press_any_key_ex(const char *msg) Line 104  int press_any_key_ex(const char *msg)
104          prints(msg);          prints(msg);
105          iflush();          iflush();
106    
107            igetch_reset();
108    
109          do          do
110          {          {
111                  ch = igetch_t(wait_seconds - duration);                  ch = igetch_t(sec - duration);
112                  duration = (int)(time(NULL) - t_begin);                  duration = (int)(time(NULL) - t_begin);
113          } while (!SYS_server_exit && ch == 0 && duration < 60);          } while (!SYS_server_exit && ch == 0 && duration < 60);
114    
# Line 143  void set_input_echo(int echo) Line 129  void set_input_echo(int echo)
129          iflush();          iflush();
130  }  }
131    
132  static int _str_input(char *buffer, int buf_size, int max_display_len, int echo_mode)  static int _str_input(char *buffer, int buf_size, int max_display_len, enum io_echo_t echo_mode)
133  {  {
134          int ch;          int ch;
135          int offset = 0;          int offset = 0;
# Line 160  static int _str_input(char *buffer, int Line 146  static int _str_input(char *buffer, int
146    
147          while (!SYS_server_exit)          while (!SYS_server_exit)
148          {          {
149                  ch = igetch_t(MIN(MAX_DELAY_TIME, 60));                  ch = igetch_t(MIN(BBS_max_user_idle_time, 60));
150    
151                  if (ch == CR)                  if (ch == CR)
152                  {                  {
# Line 181  static int _str_input(char *buffer, int Line 167  static int _str_input(char *buffer, int
167                                  offset--;                                  offset--;
168                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
169                                  {                                  {
170                                          while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000)                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
171                                          {                                          {
172                                                  offset--;                                                  offset--;
173                                          }                                          }
# Line 202  static int _str_input(char *buffer, int Line 188  static int _str_input(char *buffer, int
188                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character
189                  {                  {
190                          str_len = 0;                          str_len = 0;
191                          c = (char)(ch & 0b11110000);                          c = (char)(ch & 0xf0);
192                          while (c & 0b10000000)                          while (c & 0x80)
193                          {                          {
194                                  input_str[str_len] = (char)(ch - 256);                                  input_str[str_len] = (char)(ch - 256);
195                                  str_len++;                                  str_len++;
196                                  c = (c & 0b01111111) << 1;                                  c = (c & 0x7f) << 1;
197    
198                                  if ((c & 0b10000000) == 0) // Input completed                                  if ((c & 0x80) == 0) // Input completed
199                                  {                                  {
200                                          break;                                          break;
201                                  }                                  }
# Line 287  static int _str_input(char *buffer, int Line 273  static int _str_input(char *buffer, int
273          return offset;          return offset;
274  }  }
275    
276  int str_input(char *buffer, int buf_size, int echo_mode)  int str_input(char *buffer, int buf_size, enum io_echo_t echo_mode)
277  {  {
278          int len;          int len;
279    
# Line 299  int str_input(char *buffer, int buf_size Line 285  int str_input(char *buffer, int buf_size
285          iflush();          iflush();
286    
287          return len;          return len;
288  };  }
289    
290  int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int max_display_len)  int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int max_display_len)
291  {  {
# Line 330  int get_data(int row, int col, char *pro Line 316  int get_data(int row, int col, char *pro
316    
317          while (!SYS_server_exit)          while (!SYS_server_exit)
318          {          {
319                  ch = igetch_t(MIN(MAX_DELAY_TIME, 60));                  ch = igetch_t(MIN(BBS_max_user_idle_time, 60));
320    
321                  if (ch == CR)                  if (ch == CR)
322                  {                  {
# Line 352  int get_data(int row, int col, char *pro Line 338  int get_data(int row, int col, char *pro
338                                  offset--;                                  offset--;
339                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
340                                  {                                  {
341                                          while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000)                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
342                                          {                                          {
343                                                  str_len++;                                                  str_len++;
344                                                  offset--;                                                  offset--;
# Line 382  int get_data(int row, int col, char *pro Line 368  int get_data(int row, int col, char *pro
368                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
369                                  {                                  {
370                                          str_len = 0;                                          str_len = 0;
371                                          c = (char)(buffer[offset] & 0b11110000);                                          c = (char)(buffer[offset] & 0xf0);
372                                          while (c & 0b10000000)                                          while (c & 0x80)
373                                          {                                          {
374                                                  str_len++;                                                  str_len++;
375                                                  c = (c & 0b01111111) << 1;                                                  c = (c & 0x7f) << 1;
376                                          }                                          }
377                                          display_len--;                                          display_len--;
378                                  }                                  }
# Line 416  int get_data(int row, int col, char *pro Line 402  int get_data(int row, int col, char *pro
402                                  offset--;                                  offset--;
403                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
404                                  {                                  {
405                                          while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000)                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
406                                          {                                          {
407                                                  str_len++;                                                  str_len++;
408                                                  offset--;                                                  offset--;
# Line 437  int get_data(int row, int col, char *pro Line 423  int get_data(int row, int col, char *pro
423                                  str_len = 0;                                  str_len = 0;
424                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
425                                  {                                  {
426                                          c = (char)(buffer[offset] & 0b11110000);                                          c = (char)(buffer[offset] & 0xf0);
427                                          while (c & 0b10000000)                                          while (c & 0x80)
428                                          {                                          {
429                                                  str_len++;                                                  str_len++;
430                                                  c = (c & 0b01111111) << 1;                                                  c = (c & 0x7f) << 1;
431                                          }                                          }
432                                          col_cur++;                                          col_cur++;
433                                  }                                  }
# Line 489  int get_data(int row, int col, char *pro Line 475  int get_data(int row, int col, char *pro
475                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character
476                  {                  {
477                          str_len = 0;                          str_len = 0;
478                          c = (char)(ch & 0b11110000);                          c = (char)(ch & 0xf0);
479                          while (c & 0b10000000)                          while (c & 0x80)
480                          {                          {
481                                  input_str[str_len] = (char)(ch - 256);                                  input_str[str_len] = (char)(ch - 256);
482                                  str_len++;                                  str_len++;
483                                  c = (c & 0b01111111) << 1;                                  c = (c & 0x7f) << 1;
484    
485                                  if ((c & 0b10000000) == 0) // Input completed                                  if ((c & 0x80) == 0) // Input completed
486                                  {                                  {
487                                          break;                                          break;
488                                  }                                  }
# Line 661  int display_data(const void *p_data, lon Line 647  int display_data(const void *p_data, lon
647                          input_ok = 0;                          input_ok = 0;
648                          while (!SYS_server_exit && !input_ok)                          while (!SYS_server_exit && !input_ok)
649                          {                          {
650                                  ch = igetch_t(MAX_DELAY_TIME);                                  ch = igetch_t(BBS_max_user_idle_time);
651                                  input_ok = 1;                                  input_ok = 1;
652    
653                                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)                                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
# Line 715  int display_data(const void *p_data, lon Line 701  int display_data(const void *p_data, lon
701                                          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
702                                          break;                                          break;
703                                  case CR:                                  case CR:
                                 case KEY_SPACE:  
704                                  case KEY_DOWN:                                  case KEY_DOWN:
705                                          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
706                                          {                                          {
# Line 743  int display_data(const void *p_data, lon Line 728  int display_data(const void *p_data, lon
728                                          output_end_row = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
729                                          clrline(output_current_row, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
730                                          break;                                          break;
731                                    case KEY_SPACE:
732                                  case KEY_PGDN:                                  case KEY_PGDN:
733                                          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
734                                          {                                          {
# Line 899  int show_top(const char *str_left, const Line 885  int show_top(const char *str_left, const
885  int show_bottom(const char *msg)  int show_bottom(const char *msg)
886  {  {
887          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
888            int len_str_time;
889          time_t time_online;          time_t time_online;
890          struct tm *tm_online;          struct tm *tm_online;
891          char msg_f[LINE_BUFFER_LEN];          char msg_f[LINE_BUFFER_LEN];
892          int eol;          int eol;
893          int msg_len;          int len_msg;
894          int len;          int len;
895          int len_username;          int len_username;
896          char str_tm_online[LINE_BUFFER_LEN];          char str_tm_online[LINE_BUFFER_LEN];
897    
898          get_time_str(str_time, sizeof(str_time));          len_str_time = (int)get_time_str(str_time, sizeof(str_time));
899    
900          msg_f[0] = '\0';          msg_f[0] = '\0';
901          msg_len = 0;          len_msg = 0;
902          if (msg != NULL)          if (msg != NULL)
903          {          {
904                  strncpy(msg_f, msg, sizeof(msg_f) - 1);                  strncpy(msg_f, msg, sizeof(msg_f) - 1);
905                  msg_f[sizeof(msg_f) - 1] = '\0';                  msg_f[sizeof(msg_f) - 1] = '\0';
906                  len = split_line(msg_f, 23, &eol, &msg_len, 1);                  len = split_line(msg_f, 23, &eol, &len_msg, 1);
907                  msg_f[len] = '\0';                  msg_f[len] = '\0';
908          }          }
909    
# Line 927  int show_bottom(const char *msg) Line 914  int show_bottom(const char *msg)
914          if (tm_online->tm_mday > 1)          if (tm_online->tm_mday > 1)
915          {          {
916                  snprintf(str_tm_online, sizeof(str_tm_online),                  snprintf(str_tm_online, sizeof(str_tm_online),
917                                   "\033[36m%2d\033[33m天\033[36m%2d\033[33m时",                                   "\033[36m%d\033[33md \033[36m%d\033[33m:\033[36m%.2d",
918                                   tm_online->tm_mday - 1, tm_online->tm_hour);                                   tm_online->tm_mday - 1, tm_online->tm_hour, tm_online->tm_min);
919          }          }
920          else          else
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[33m:\033[36m%.2d",
924                                   tm_online->tm_hour, tm_online->tm_min);                                   tm_online->tm_hour, tm_online->tm_min);
925          }          }
926    
927          moveto(SCREEN_ROWS, 0);          moveto(SCREEN_ROWS, 0);
928          clrtoeol();          clrtoeol();
929          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",
930                     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);
931    
932          return 0;          return 0;
933  }  }


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

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