/[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.109 by sysadm, Tue Oct 14 05:28:15 2025 UTC Revision 1.119 by sysadm, Tue Oct 28 05:02:17 2025 UTC
# Line 40  Line 40 
40  #define STR_TOP_MIDDLE_MAX_LEN 40  #define STR_TOP_MIDDLE_MAX_LEN 40
41  #define STR_TOP_RIGHT_MAX_LEN 80  #define STR_TOP_RIGHT_MAX_LEN 80
42    
43  static const char *get_time_str(char *s, size_t len)  static size_t get_time_str(char *s, size_t len)
44  {  {
         static const char *weekday[] = {  
                 "天", "一", "二", "三", "四", "五", "六"};  
45          time_t curtime;          time_t curtime;
46          struct tm local_tm;          struct tm local_tm;
47    
48          time(&curtime);          time(&curtime);
49          localtime_r(&curtime, &local_tm);          localtime_r(&curtime, &local_tm);
50          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);
51    
52          if (j == 0 || j + strlen(weekday[local_tm.tm_wday]) + 1 > len)          return j;
         {  
                 return NULL;  
         }  
   
         strncat(s, weekday[local_tm.tm_wday], len - 1 - j);  
   
         return s;  
53  }  }
54    
55  void moveto(int row, int col)  void moveto(int row, int col)
# Line 102  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 118  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 max_display_len, int echo_mode)  static int _str_input(char *buffer, int buf_size, int max_display_len, int echo_mode)
# Line 151  static int _str_input(char *buffer, int Line 156  static int _str_input(char *buffer, int
156    
157                  if (ch == CR)                  if (ch == CR)
158                  {                  {
                         igetch_reset();  
159                          break;                          break;
160                  }                  }
161                  else if (ch == KEY_TIMEOUT || ch == KEY_NULL) // timeout or broken pipe                  else if (ch == KEY_TIMEOUT || ch == KEY_NULL) // timeout or broken pipe
# Line 169  static int _str_input(char *buffer, int Line 173  static int _str_input(char *buffer, int
173                                  offset--;                                  offset--;
174                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
175                                  {                                  {
176                                          while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000)                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
177                                          {                                          {
178                                                  offset--;                                                  offset--;
179                                          }                                          }
# Line 190  static int _str_input(char *buffer, int Line 194  static int _str_input(char *buffer, int
194                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character
195                  {                  {
196                          str_len = 0;                          str_len = 0;
197                          c = (char)(ch & 0b11110000);                          c = (char)(ch & 0xf0);
198                          while (c & 0b10000000)                          while (c & 0x80)
199                          {                          {
200                                  input_str[str_len] = (char)(ch - 256);                                  input_str[str_len] = (char)(ch - 256);
201                                  str_len++;                                  str_len++;
202                                  c = (c & 0b01111111) << 1;                                  c = (c & 0x7f) << 1;
203    
204                                  if ((c & 0b10000000) == 0) // Input completed                                  if ((c & 0x80) == 0) // Input completed
205                                  {                                  {
206                                          break;                                          break;
207                                  }                                  }
# Line 287  int str_input(char *buffer, int buf_size Line 291  int str_input(char *buffer, int buf_size
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 max_display_len)  int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int max_display_len)
297  {  {
# Line 322  int get_data(int row, int col, char *pro Line 326  int get_data(int row, int col, char *pro
326    
327                  if (ch == CR)                  if (ch == CR)
328                  {                  {
                         igetch_reset();  
329                          break;                          break;
330                  }                  }
331                  else if (ch == KEY_TIMEOUT || ch == KEY_NULL) // timeout or broken pipe                  else if (ch == KEY_TIMEOUT || ch == KEY_NULL) // timeout or broken pipe
# Line 341  int get_data(int row, int col, char *pro Line 344  int get_data(int row, int col, char *pro
344                                  offset--;                                  offset--;
345                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
346                                  {                                  {
347                                          while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000)                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
348                                          {                                          {
349                                                  str_len++;                                                  str_len++;
350                                                  offset--;                                                  offset--;
# Line 371  int get_data(int row, int col, char *pro Line 374  int get_data(int row, int col, char *pro
374                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
375                                  {                                  {
376                                          str_len = 0;                                          str_len = 0;
377                                          c = (char)(buffer[offset] & 0b11110000);                                          c = (char)(buffer[offset] & 0xf0);
378                                          while (c & 0b10000000)                                          while (c & 0x80)
379                                          {                                          {
380                                                  str_len++;                                                  str_len++;
381                                                  c = (c & 0b01111111) << 1;                                                  c = (c & 0x7f) << 1;
382                                          }                                          }
383                                          display_len--;                                          display_len--;
384                                  }                                  }
# Line 405  int get_data(int row, int col, char *pro Line 408  int get_data(int row, int col, char *pro
408                                  offset--;                                  offset--;
409                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
410                                  {                                  {
411                                          while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000)                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
412                                          {                                          {
413                                                  str_len++;                                                  str_len++;
414                                                  offset--;                                                  offset--;
# Line 426  int get_data(int row, int col, char *pro Line 429  int get_data(int row, int col, char *pro
429                                  str_len = 0;                                  str_len = 0;
430                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
431                                  {                                  {
432                                          c = (char)(buffer[offset] & 0b11110000);                                          c = (char)(buffer[offset] & 0xf0);
433                                          while (c & 0b10000000)                                          while (c & 0x80)
434                                          {                                          {
435                                                  str_len++;                                                  str_len++;
436                                                  c = (c & 0b01111111) << 1;                                                  c = (c & 0x7f) << 1;
437                                          }                                          }
438                                          col_cur++;                                          col_cur++;
439                                  }                                  }
# Line 478  int get_data(int row, int col, char *pro Line 481  int get_data(int row, int col, char *pro
481                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character
482                  {                  {
483                          str_len = 0;                          str_len = 0;
484                          c = (char)(ch & 0b11110000);                          c = (char)(ch & 0xf0);
485                          while (c & 0b10000000)                          while (c & 0x80)
486                          {                          {
487                                  input_str[str_len] = (char)(ch - 256);                                  input_str[str_len] = (char)(ch - 256);
488                                  str_len++;                                  str_len++;
489                                  c = (c & 0b01111111) << 1;                                  c = (c & 0x7f) << 1;
490    
491                                  if ((c & 0b10000000) == 0) // Input completed                                  if ((c & 0x80) == 0) // Input completed
492                                  {                                  {
493                                          break;                                          break;
494                                  }                                  }
# Line 653  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 662  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 696  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 725  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 765  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 883  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 911  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, 60 - 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