/[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.110 by sysadm, Thu Oct 16 11:26:16 2025 UTC Revision 1.121 by sysadm, Tue Nov 4 13:49:51 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 by 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 40  Line 32 
32  #define STR_TOP_MIDDLE_MAX_LEN 40  #define STR_TOP_MIDDLE_MAX_LEN 40
33  #define STR_TOP_RIGHT_MAX_LEN 80  #define STR_TOP_RIGHT_MAX_LEN 80
34    
35  static const char *get_time_str(char *s, size_t len)  static size_t get_time_str(char *s, size_t len)
36  {  {
         static const char *weekday[] = {  
                 "天", "一", "二", "三", "四", "五", "六"};  
37          time_t curtime;          time_t curtime;
38          struct tm local_tm;          struct tm local_tm;
39    
40          time(&curtime);          time(&curtime);
41          localtime_r(&curtime, &local_tm);          localtime_r(&curtime, &local_tm);
42          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);
43    
44          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;  
45  }  }
46    
47  void moveto(int row, int col)  void moveto(int row, int col)
# Line 102  void clearscr() Line 85  void clearscr()
85          moveto(0, 0);          moveto(0, 0);
86  }  }
87    
88  int press_any_key()  inline int press_any_key()
89    {
90            return press_any_key_ex("                           \033[1;33m按任意键继续...\033[m", 60);
91    }
92    
93    int press_any_key_ex(const char *msg, int sec)
94  {  {
95            int ch = 0;
96            int duration = 0;
97            time_t t_begin = time(NULL);
98    
99          moveto(SCREEN_ROWS, 0);          moveto(SCREEN_ROWS, 0);
100          clrtoeol();          clrtoeol();
101    
102          prints("                           \033[1;33m按任意键继续...\033[0;37m");          prints(msg);
103          iflush();          iflush();
104    
105          return igetch_t(MIN(MAX_DELAY_TIME, 60));          igetch_reset();
106    
107            do
108            {
109                    ch = igetch_t(sec - duration);
110                    duration = (int)(time(NULL) - t_begin);
111            } while (!SYS_server_exit && ch == 0 && duration < 60);
112    
113            return ch;
114  }  }
115    
116  void set_input_echo(int echo)  void set_input_echo(int echo)
# Line 118  void set_input_echo(int echo) Line 118  void set_input_echo(int echo)
118          if (echo)          if (echo)
119          {          {
120                  outc('\x83'); // ASCII code 131                  outc('\x83'); // ASCII code 131
                 iflush();  
121          }          }
122          else          else
123          {          {
124                  //    outc ('\x85'); // ASCII code 133                  // outc ('\x85'); // ASCII code 133
125                  prints("\xff\xfb\x01\xff\xfb\x03");                  prints("\xff\xfb\x01\xff\xfb\x03");
                 iflush();  
                 igetch(0);  
                 igetch_reset();  
126          }          }
127            iflush();
128  }  }
129    
130  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 148  static int _str_input(char *buffer, int
148    
149                  if (ch == CR)                  if (ch == CR)
150                  {                  {
                         igetch_reset();  
151                          break;                          break;
152                  }                  }
153                  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 165  static int _str_input(char *buffer, int
165                                  offset--;                                  offset--;
166                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
167                                  {                                  {
168                                          while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000)                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
169                                          {                                          {
170                                                  offset--;                                                  offset--;
171                                          }                                          }
# Line 190  static int _str_input(char *buffer, int Line 186  static int _str_input(char *buffer, int
186                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character
187                  {                  {
188                          str_len = 0;                          str_len = 0;
189                          c = (char)(ch & 0b11110000);                          c = (char)(ch & 0xf0);
190                          while (c & 0b10000000)                          while (c & 0x80)
191                          {                          {
192                                  input_str[str_len] = (char)(ch - 256);                                  input_str[str_len] = (char)(ch - 256);
193                                  str_len++;                                  str_len++;
194                                  c = (c & 0b01111111) << 1;                                  c = (c & 0x7f) << 1;
195    
196                                  if ((c & 0b10000000) == 0) // Input completed                                  if ((c & 0x80) == 0) // Input completed
197                                  {                                  {
198                                          break;                                          break;
199                                  }                                  }
# Line 287  int str_input(char *buffer, int buf_size Line 283  int str_input(char *buffer, int buf_size
283          iflush();          iflush();
284    
285          return len;          return len;
286  };  }
287    
288  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)
289  {  {
# Line 322  int get_data(int row, int col, char *pro Line 318  int get_data(int row, int col, char *pro
318    
319                  if (ch == CR)                  if (ch == CR)
320                  {                  {
                         igetch_reset();  
321                          break;                          break;
322                  }                  }
323                  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 336  int get_data(int row, int col, char *pro
336                                  offset--;                                  offset--;
337                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
338                                  {                                  {
339                                          while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000)                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
340                                          {                                          {
341                                                  str_len++;                                                  str_len++;
342                                                  offset--;                                                  offset--;
# Line 371  int get_data(int row, int col, char *pro Line 366  int get_data(int row, int col, char *pro
366                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
367                                  {                                  {
368                                          str_len = 0;                                          str_len = 0;
369                                          c = (char)(buffer[offset] & 0b11110000);                                          c = (char)(buffer[offset] & 0xf0);
370                                          while (c & 0b10000000)                                          while (c & 0x80)
371                                          {                                          {
372                                                  str_len++;                                                  str_len++;
373                                                  c = (c & 0b01111111) << 1;                                                  c = (c & 0x7f) << 1;
374                                          }                                          }
375                                          display_len--;                                          display_len--;
376                                  }                                  }
# Line 405  int get_data(int row, int col, char *pro Line 400  int get_data(int row, int col, char *pro
400                                  offset--;                                  offset--;
401                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
402                                  {                                  {
403                                          while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000)                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
404                                          {                                          {
405                                                  str_len++;                                                  str_len++;
406                                                  offset--;                                                  offset--;
# Line 426  int get_data(int row, int col, char *pro Line 421  int get_data(int row, int col, char *pro
421                                  str_len = 0;                                  str_len = 0;
422                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
423                                  {                                  {
424                                          c = (char)(buffer[offset] & 0b11110000);                                          c = (char)(buffer[offset] & 0xf0);
425                                          while (c & 0b10000000)                                          while (c & 0x80)
426                                          {                                          {
427                                                  str_len++;                                                  str_len++;
428                                                  c = (c & 0b01111111) << 1;                                                  c = (c & 0x7f) << 1;
429                                          }                                          }
430                                          col_cur++;                                          col_cur++;
431                                  }                                  }
# Line 478  int get_data(int row, int col, char *pro Line 473  int get_data(int row, int col, char *pro
473                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character
474                  {                  {
475                          str_len = 0;                          str_len = 0;
476                          c = (char)(ch & 0b11110000);                          c = (char)(ch & 0xf0);
477                          while (c & 0b10000000)                          while (c & 0x80)
478                          {                          {
479                                  input_str[str_len] = (char)(ch - 256);                                  input_str[str_len] = (char)(ch - 256);
480                                  str_len++;                                  str_len++;
481                                  c = (c & 0b01111111) << 1;                                  c = (c & 0x7f) << 1;
482    
483                                  if ((c & 0b10000000) == 0) // Input completed                                  if ((c & 0x80) == 0) // Input completed
484                                  {                                  {
485                                          break;                                          break;
486                                  }                                  }
# Line 704  int display_data(const void *p_data, lon Line 699  int display_data(const void *p_data, lon
699                                          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
700                                          break;                                          break;
701                                  case CR:                                  case CR:
                                         igetch_reset();  
                                 case KEY_SPACE:  
702                                  case KEY_DOWN:                                  case KEY_DOWN:
703                                          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
704                                          {                                          {
# Line 733  int display_data(const void *p_data, lon Line 726  int display_data(const void *p_data, lon
726                                          output_end_row = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
727                                          clrline(output_current_row, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
728                                          break;                                          break;
729                                    case KEY_SPACE:
730                                  case KEY_PGDN:                                  case KEY_PGDN:
731                                          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
732                                          {                                          {
# Line 889  int show_top(const char *str_left, const Line 883  int show_top(const char *str_left, const
883  int show_bottom(const char *msg)  int show_bottom(const char *msg)
884  {  {
885          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
886            int len_str_time;
887          time_t time_online;          time_t time_online;
888          struct tm *tm_online;          struct tm *tm_online;
889          char msg_f[LINE_BUFFER_LEN];          char msg_f[LINE_BUFFER_LEN];
890          int eol;          int eol;
891          int msg_len;          int len_msg;
892          int len;          int len;
893          int len_username;          int len_username;
894          char str_tm_online[LINE_BUFFER_LEN];          char str_tm_online[LINE_BUFFER_LEN];
895    
896          get_time_str(str_time, sizeof(str_time));          len_str_time = (int)get_time_str(str_time, sizeof(str_time));
897    
898          msg_f[0] = '\0';          msg_f[0] = '\0';
899          msg_len = 0;          len_msg = 0;
900          if (msg != NULL)          if (msg != NULL)
901          {          {
902                  strncpy(msg_f, msg, sizeof(msg_f) - 1);                  strncpy(msg_f, msg, sizeof(msg_f) - 1);
903                  msg_f[sizeof(msg_f) - 1] = '\0';                  msg_f[sizeof(msg_f) - 1] = '\0';
904                  len = split_line(msg_f, 23, &eol, &msg_len, 1);                  len = split_line(msg_f, 23, &eol, &len_msg, 1);
905                  msg_f[len] = '\0';                  msg_f[len] = '\0';
906          }          }
907    
# Line 917  int show_bottom(const char *msg) Line 912  int show_bottom(const char *msg)
912          if (tm_online->tm_mday > 1)          if (tm_online->tm_mday > 1)
913          {          {
914                  snprintf(str_tm_online, sizeof(str_tm_online),                  snprintf(str_tm_online, sizeof(str_tm_online),
915                                   "\033[36m%2d\033[33m天\033[36m%2d\033[33m时",                                   "\033[36m%d\033[33md \033[36m%d\033[33m:\033[36m%.2d",
916                                   tm_online->tm_mday - 1, tm_online->tm_hour);                                   tm_online->tm_mday - 1, tm_online->tm_hour, tm_online->tm_min);
917          }          }
918          else          else
919          {          {
920                  snprintf(str_tm_online, sizeof(str_tm_online),                  snprintf(str_tm_online, sizeof(str_tm_online),
921                                   "\033[36m%2d\033[33m时\033[36m%2d\033[33m分",                                   "\033[36m%d\033[33m:\033[36m%.2d",
922                                   tm_online->tm_hour, tm_online->tm_min);                                   tm_online->tm_hour, tm_online->tm_min);
923          }          }
924    
925          moveto(SCREEN_ROWS, 0);          moveto(SCREEN_ROWS, 0);
926          clrtoeol();          clrtoeol();
927          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",
928                     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);
929    
930          return 0;          return 0;
931  }  }


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

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