/[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.120 by sysadm, Tue Oct 28 05:08:50 2025 UTC Revision 1.128 by sysadm, Sat Nov 8 09:05:59 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 29  Line 21 
21  #include <string.h>  #include <string.h>
22  #include <stdlib.h>  #include <stdlib.h>
23  #include <unistd.h>  #include <unistd.h>
24    #include <wchar.h>
25  #include <sys/param.h>  #include <sys/param.h>
26  #include <sys/stat.h>  #include <sys/stat.h>
27  #include <sys/shm.h>  #include <sys/shm.h>
28  #include <sys/types.h>  #include <sys/types.h>
29    
30  #define ACTIVE_BOARD_HEIGHT 8  const char CTRL_SEQ_CLR_LINE[] = "\033[K";
31    
32  #define STR_TOP_LEFT_MAX_LEN 80  static const int ACTIVE_BOARD_HEIGHT = 8;
33  #define STR_TOP_MIDDLE_MAX_LEN 40  
34  #define STR_TOP_RIGHT_MAX_LEN 80  static const int STR_TOP_LEFT_MAX_LEN = 80;
35    static const int STR_TOP_MIDDLE_MAX_LEN = 40;
36    static const int STR_TOP_RIGHT_MAX_LEN = 80;
37    
38  static size_t get_time_str(char *s, size_t len)  static size_t get_time_str(char *s, size_t len)
39  {  {
# Line 135  void set_input_echo(int echo) Line 130  void set_input_echo(int echo)
130          iflush();          iflush();
131  }  }
132    
133  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)
134  {  {
135          int ch;          int ch;
136          int offset = 0;          int offset = 0;
137          int eol;          int eol;
138          int display_len;          int display_len;
139          char input_str[4];          char input_str[5];
140          int str_len = 0;          int str_len = 0;
141            wchar_t wcs[2];
142          char c;          char c;
143    
144          buffer[buf_size - 1] = '\0';          buffer[buf_size - 1] = '\0';
# Line 152  static int _str_input(char *buffer, int Line 148  static int _str_input(char *buffer, int
148    
149          while (!SYS_server_exit)          while (!SYS_server_exit)
150          {          {
151                  ch = igetch_t(MIN(MAX_DELAY_TIME, 60));                  ch = igetch_t(MIN(BBS_max_user_idle_time, 60));
152    
153                  if (ch == CR)                  if (ch == CR)
154                  {                  {
# Line 217  static int _str_input(char *buffer, int Line 213  static int _str_input(char *buffer, int
213                                          break;                                          break;
214                                  }                                  }
215                          }                          }
216                            input_str[str_len] = '\0';
217    
218                          if (str_len == 0) // Incomplete input                          if (str_len == 0) // Incomplete input
219                          {                          {
220                                  continue;                                  continue;
221                          }                          }
222    
223                          if (offset + str_len > buf_size - 1 || display_len + 2 > max_display_len) // No enough space for Chinese character                          if (mbstowcs(wcs, input_str, 1) == (size_t)-1)
224                            {
225                                    log_error("mbstowcs() error\n");
226                            }
227                            if (offset + str_len > buf_size - 1 || display_len + (UTF8_fixed_width ? 2 : wcwidth(wcs[0])) > max_display_len) // No enough space for Chinese character
228                          {                          {
229                                  outc('\a');                                  outc('\a');
230                                  iflush();                                  iflush();
# Line 279  static int _str_input(char *buffer, int Line 280  static int _str_input(char *buffer, int
280          return offset;          return offset;
281  }  }
282    
283  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)
284  {  {
285          int len;          int len;
286    
# Line 301  int get_data(int row, int col, char *pro Line 302  int get_data(int row, int col, char *pro
302          int offset = 0;          int offset = 0;
303          int eol;          int eol;
304          int display_len;          int display_len;
305          char input_str[4];          char input_str[5];
306          int str_len = 0;          int str_len = 0;
307            wchar_t wcs[2];
308            int wc_len;
309          char c;          char c;
310    
311          buffer[buf_size - 1] = '\0';          buffer[buf_size - 1] = '\0';
# Line 322  int get_data(int row, int col, char *pro Line 325  int get_data(int row, int col, char *pro
325    
326          while (!SYS_server_exit)          while (!SYS_server_exit)
327          {          {
328                  ch = igetch_t(MIN(MAX_DELAY_TIME, 60));                  ch = igetch_t(MIN(BBS_max_user_idle_time, 60));
329    
330                  if (ch == CR)                  if (ch == CR)
331                  {                  {
# Line 349  int get_data(int row, int col, char *pro Line 352  int get_data(int row, int col, char *pro
352                                                  str_len++;                                                  str_len++;
353                                                  offset--;                                                  offset--;
354                                          }                                          }
355                                          display_len--;  
356                                          col_cur--;                                          if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1)
357                                            {
358                                                    log_error("mbstowcs() error\n");
359                                            }
360                                            wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
361    
362                                            if (wc_len == 2)
363                                            {
364                                                    display_len--;
365                                                    col_cur--;
366                                            }
367                                  }                                  }
368    
369                                  memmove(buffer + offset, buffer + offset + str_len, (size_t)(len - offset - str_len));                                  memmove(buffer + offset, buffer + offset + str_len, (size_t)(len - offset - str_len));
# Line 413  int get_data(int row, int col, char *pro Line 426  int get_data(int row, int col, char *pro
426                                                  str_len++;                                                  str_len++;
427                                                  offset--;                                                  offset--;
428                                          }                                          }
429                                          col_cur--;  
430                                            if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1)
431                                            {
432                                                    log_error("mbstowcs() error\n");
433                                            }
434                                            wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
435    
436                                            if (wc_len == 2)
437                                            {
438                                                    col_cur--;
439                                            }
440                                  }                                  }
441                                  col_cur--;                                  col_cur--;
442    
# Line 435  int get_data(int row, int col, char *pro Line 458  int get_data(int row, int col, char *pro
458                                                  str_len++;                                                  str_len++;
459                                                  c = (c & 0x7f) << 1;                                                  c = (c & 0x7f) << 1;
460                                          }                                          }
461                                          col_cur++;  
462                                            if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1)
463                                            {
464                                                    log_error("mbstowcs() error\n");
465                                            }
466                                            wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
467    
468                                            if (wc_len == 2)
469                                            {
470                                                    col_cur++;
471                                            }
472                                  }                                  }
473                                  else                                  else
474                                  {                                  {
# Line 504  int get_data(int row, int col, char *pro Line 537  int get_data(int row, int col, char *pro
537                                          break;                                          break;
538                                  }                                  }
539                          }                          }
540                            input_str[str_len] = '\0';
541    
542                          if (str_len == 0) // Incomplete input                          if (str_len == 0) // Incomplete input
543                          {                          {
544                                  continue;                                  continue;
545                          }                          }
546    
547                          if (len + str_len > buf_size - 1 || display_len + 2 > max_display_len) // No enough space for Chinese character                          if (mbstowcs(wcs, input_str, 1) == (size_t)-1)
548                            {
549                                    log_error("mbstowcs() error\n");
550                            }
551                            wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
552    
553                            if (len + str_len > buf_size - 1 ||
554                                    display_len + wc_len > max_display_len) // No enough space for Chinese character
555                          {                          {
556                                  outc('\a');                                  outc('\a');
557                                  iflush();                                  iflush();
# Line 521  int get_data(int row, int col, char *pro Line 562  int get_data(int row, int col, char *pro
562                          memcpy(buffer + offset, input_str, (size_t)str_len);                          memcpy(buffer + offset, input_str, (size_t)str_len);
563                          len += str_len;                          len += str_len;
564                          buffer[len] = '\0';                          buffer[len] = '\0';
565                          display_len += 2;                          display_len += wc_len;
566    
567                          moveto(row, col_cur);                          moveto(row, col_cur);
568                          prints("%s", buffer + offset);                          prints("%s", buffer + offset);
569                          prints("%*s", max_display_len - display_len, "");                          prints("%*s", max_display_len - display_len, "");
570    
571                          col_cur += 2;                          col_cur += wc_len;
572    
573                          moveto(row, col_cur);                          moveto(row, col_cur);
574                          iflush();                          iflush();
# Line 598  int display_data(const void *p_data, lon Line 639  int display_data(const void *p_data, lon
639          loop = 1;          loop = 1;
640          while (!SYS_server_exit && loop)          while (!SYS_server_exit && loop)
641          {          {
642                  if (eof_exit > 0 && line_current >= display_line_total && display_line_total <= screen_row_total)                  if (eof_exit > 0 && line_current >= display_line_total)
643                  {                  {
644                          if (eof_exit == 1)                          if (eof_exit == 1)
645                          {                          {
# Line 653  int display_data(const void *p_data, lon Line 694  int display_data(const void *p_data, lon
694                          input_ok = 0;                          input_ok = 0;
695                          while (!SYS_server_exit && !input_ok)                          while (!SYS_server_exit && !input_ok)
696                          {                          {
697                                  ch = igetch_t(MAX_DELAY_TIME);                                  ch = igetch_t(BBS_max_user_idle_time);
698                                  input_ok = 1;                                  input_ok = 1;
699    
700                                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)                                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
# Line 808  cleanup: Line 849  cleanup:
849          return ch;          return ch;
850  }  }
851    
852  static int display_file_key_handler(int *p_key, DISPLAY_CTX *p_ctx)  int display_file_key_handler(int *p_key, DISPLAY_CTX *p_ctx)
853  {  {
854          switch (*p_key)          switch (*p_key)
855          {          {
# Line 900  int show_bottom(const char *msg) Line 941  int show_bottom(const char *msg)
941          int len;          int len;
942          int len_username;          int len_username;
943          char str_tm_online[LINE_BUFFER_LEN];          char str_tm_online[LINE_BUFFER_LEN];
944            int len_str_tm_online;
945    
946          len_str_time = (int)get_time_str(str_time, sizeof(str_time));          len_str_time = (int)get_time_str(str_time, sizeof(str_time));
947    
# Line 929  int show_bottom(const char *msg) Line 971  int show_bottom(const char *msg)
971                                   "\033[36m%d\033[33m:\033[36m%.2d",                                   "\033[36m%d\033[33m:\033[36m%.2d",
972                                   tm_online->tm_hour, tm_online->tm_min);                                   tm_online->tm_hour, tm_online->tm_min);
973          }          }
974            len_str_tm_online = str_length(str_tm_online, 1);
975    
976          moveto(SCREEN_ROWS, 0);          moveto(SCREEN_ROWS, 0);
977          clrtoeol();          clrtoeol();
978          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",
979                     str_time, msg_f, 61 - len_str_time - len_msg - len_username, "", BBS_username, str_tm_online);                     str_time, msg_f, 65 - len_str_time - len_msg - len_username - len_str_tm_online,
980                       "", BBS_username, str_tm_online);
981    
982          return 0;          return 0;
983  }  }


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

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