/[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.108 by sysadm, Thu Oct 9 12:20:31 2025 UTC Revision 1.117 by sysadm, Wed Oct 22 04:48:53 2025 UTC
# Line 38  Line 38 
38    
39  #define STR_TOP_LEFT_MAX_LEN 80  #define STR_TOP_LEFT_MAX_LEN 80
40  #define STR_TOP_MIDDLE_MAX_LEN 40  #define STR_TOP_MIDDLE_MAX_LEN 40
41  #define STR_TOP_RIGHT_MAX_LEN 40  #define STR_TOP_RIGHT_MAX_LEN 80
42    
43  static const char *get_time_str(char *s, size_t len)  static const char *get_time_str(char *s, size_t len)
44  {  {
# Line 102  void clearscr() Line 102  void clearscr()
102          moveto(0, 0);          moveto(0, 0);
103  }  }
104    
105  int press_any_key()  inline int press_any_key()
106  {  {
107            return press_any_key_ex("                           \033[1;33m按任意键继续...\033[m", 60);
108    }
109    
110    int press_any_key_ex(const char *msg, int sec)
111    {
112            int ch = 0;
113            int duration = 0;
114            time_t t_begin = time(NULL);
115    
116          moveto(SCREEN_ROWS, 0);          moveto(SCREEN_ROWS, 0);
117          clrtoeol();          clrtoeol();
118    
119          prints("                           \033[1;33m按任意键继续...\033[0;37m");          prints(msg);
120          iflush();          iflush();
121    
122          return igetch_t(MIN(MAX_DELAY_TIME, 60));          igetch_reset();
123    
124            do
125            {
126                    ch = igetch_t(sec - duration);
127                    duration = (int)(time(NULL) - t_begin);
128            } while (!SYS_server_exit && ch == 0 && duration < 60);
129    
130            return ch;
131  }  }
132    
133  void set_input_echo(int echo)  void set_input_echo(int echo)
# Line 118  void set_input_echo(int echo) Line 135  void set_input_echo(int echo)
135          if (echo)          if (echo)
136          {          {
137                  outc('\x83'); // ASCII code 131                  outc('\x83'); // ASCII code 131
                 iflush();  
138          }          }
139          else          else
140          {          {
141                  //    outc ('\x85'); // ASCII code 133                  // outc ('\x85'); // ASCII code 133
142                  prints("\xff\xfb\x01\xff\xfb\x03");                  prints("\xff\xfb\x01\xff\xfb\x03");
                 iflush();  
                 igetch(0);  
                 igetch_reset();  
143          }          }
144            iflush();
145  }  }
146    
147  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 165  static int _str_input(char *buffer, int
165    
166                  if (ch == CR)                  if (ch == CR)
167                  {                  {
                         igetch_reset();  
168                          break;                          break;
169                  }                  }
170                  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 182  static int _str_input(char *buffer, int
182                                  offset--;                                  offset--;
183                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
184                                  {                                  {
185                                          while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000)                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
186                                          {                                          {
187                                                  offset--;                                                  offset--;
188                                          }                                          }
# Line 190  static int _str_input(char *buffer, int Line 203  static int _str_input(char *buffer, int
203                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character
204                  {                  {
205                          str_len = 0;                          str_len = 0;
206                          c = (char)(ch & 0b11110000);                          c = (char)(ch & 0xf0);
207                          while (c & 0b10000000)                          while (c & 0x80)
208                          {                          {
209                                  input_str[str_len] = (char)(ch - 256);                                  input_str[str_len] = (char)(ch - 256);
210                                  str_len++;                                  str_len++;
211                                  c = (c & 0b01111111) << 1;                                  c = (c & 0x7f) << 1;
212    
213                                  if ((c & 0b10000000) == 0) // Input completed                                  if ((c & 0x80) == 0) // Input completed
214                                  {                                  {
215                                          break;                                          break;
216                                  }                                  }
# Line 287  int str_input(char *buffer, int buf_size Line 300  int str_input(char *buffer, int buf_size
300          iflush();          iflush();
301    
302          return len;          return len;
303  };  }
304    
305  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)
306  {  {
# Line 322  int get_data(int row, int col, char *pro Line 335  int get_data(int row, int col, char *pro
335    
336                  if (ch == CR)                  if (ch == CR)
337                  {                  {
                         igetch_reset();  
338                          break;                          break;
339                  }                  }
340                  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 353  int get_data(int row, int col, char *pro
353                                  offset--;                                  offset--;
354                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
355                                  {                                  {
356                                          while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000)                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
357                                          {                                          {
358                                                  str_len++;                                                  str_len++;
359                                                  offset--;                                                  offset--;
# Line 371  int get_data(int row, int col, char *pro Line 383  int get_data(int row, int col, char *pro
383                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
384                                  {                                  {
385                                          str_len = 0;                                          str_len = 0;
386                                          c = (char)(buffer[offset] & 0b11110000);                                          c = (char)(buffer[offset] & 0xf0);
387                                          while (c & 0b10000000)                                          while (c & 0x80)
388                                          {                                          {
389                                                  str_len++;                                                  str_len++;
390                                                  c = (c & 0b01111111) << 1;                                                  c = (c & 0x7f) << 1;
391                                          }                                          }
392                                          display_len--;                                          display_len--;
393                                  }                                  }
# Line 405  int get_data(int row, int col, char *pro Line 417  int get_data(int row, int col, char *pro
417                                  offset--;                                  offset--;
418                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
419                                  {                                  {
420                                          while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000)                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
421                                          {                                          {
422                                                  str_len++;                                                  str_len++;
423                                                  offset--;                                                  offset--;
# Line 426  int get_data(int row, int col, char *pro Line 438  int get_data(int row, int col, char *pro
438                                  str_len = 0;                                  str_len = 0;
439                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
440                                  {                                  {
441                                          c = (char)(buffer[offset] & 0b11110000);                                          c = (char)(buffer[offset] & 0xf0);
442                                          while (c & 0b10000000)                                          while (c & 0x80)
443                                          {                                          {
444                                                  str_len++;                                                  str_len++;
445                                                  c = (c & 0b01111111) << 1;                                                  c = (c & 0x7f) << 1;
446                                          }                                          }
447                                          col_cur++;                                          col_cur++;
448                                  }                                  }
# Line 478  int get_data(int row, int col, char *pro Line 490  int get_data(int row, int col, char *pro
490                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character
491                  {                  {
492                          str_len = 0;                          str_len = 0;
493                          c = (char)(ch & 0b11110000);                          c = (char)(ch & 0xf0);
494                          while (c & 0b10000000)                          while (c & 0x80)
495                          {                          {
496                                  input_str[str_len] = (char)(ch - 256);                                  input_str[str_len] = (char)(ch - 256);
497                                  str_len++;                                  str_len++;
498                                  c = (c & 0b01111111) << 1;                                  c = (c & 0x7f) << 1;
499    
500                                  if ((c & 0b10000000) == 0) // Input completed                                  if ((c & 0x80) == 0) // Input completed
501                                  {                                  {
502                                          break;                                          break;
503                                  }                                  }
# Line 653  int display_data(const void *p_data, lon Line 665  int display_data(const void *p_data, lon
665                                  ch = igetch_t(MAX_DELAY_TIME);                                  ch = igetch_t(MAX_DELAY_TIME);
666                                  input_ok = 1;                                  input_ok = 1;
667    
668                                    if (ch != KEY_NULL && ch != KEY_TIMEOUT)
669                                    {
670                                            BBS_last_access_tm = time(NULL);
671                                    }
672    
673                                  // extended key handler                                  // extended key handler
674                                  if (key_handler(&ch, &ctx) != 0)                                  if (key_handler(&ch, &ctx) != 0)
675                                  {                                  {
# Line 662  int display_data(const void *p_data, lon Line 679  int display_data(const void *p_data, lon
679                                  switch (ch)                                  switch (ch)
680                                  {                                  {
681                                  case KEY_NULL:                                  case KEY_NULL:
682                                            log_error("KEY_NULL\n");
683                                            goto cleanup;
684                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
685                                            log_error("User input timeout\n");
686                                          goto cleanup;                                          goto cleanup;
687                                  case KEY_HOME:                                  case KEY_HOME:
688                                          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 716  int display_data(const void *p_data, lon
716                                          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
717                                          break;                                          break;
718                                  case CR:                                  case CR:
                                         igetch_reset();  
                                 case KEY_SPACE:  
719                                  case KEY_DOWN:                                  case KEY_DOWN:
720                                          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
721                                          {                                          {
# Line 725  int display_data(const void *p_data, lon Line 743  int display_data(const void *p_data, lon
743                                          output_end_row = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
744                                          clrline(output_current_row, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
745                                          break;                                          break;
746                                    case KEY_SPACE:
747                                  case KEY_PGDN:                                  case KEY_PGDN:
748                                          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
749                                          {                                          {
# Line 765  int display_data(const void *p_data, lon Line 784  int display_data(const void *p_data, lon
784                                          input_ok = 0;                                          input_ok = 0;
785                                          break;                                          break;
786                                  }                                  }
   
                                 BBS_last_access_tm = time(NULL);  
787                          }                          }
788    
789                          continue;                          continue;
# Line 908  int show_bottom(const char *msg) Line 925  int show_bottom(const char *msg)
925    
926          time_online = time(NULL) - BBS_login_tm;          time_online = time(NULL) - BBS_login_tm;
927          tm_online = gmtime(&time_online);          tm_online = gmtime(&time_online);
928          if (tm_online->tm_mday > 1)          if (tm_online->tm_mday > 0)
929          {          {
930                  snprintf(str_tm_online, sizeof(str_tm_online),                  snprintf(str_tm_online, sizeof(str_tm_online),
931                                   "\033[36m%2d\033[33m天\033[36m%2d\033[33m时",                                   "\033[36m%2d\033[33m天\033[36m%2d\033[33m时",
932                                   tm_online->tm_mday - 1, tm_online->tm_hour);                                   tm_online->tm_yday, tm_online->tm_hour);
933          }          }
934          else          else
935          {          {


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

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