/[LeafOK_CVS]/lbbs/src/editor.c
ViewVC logotype

Diff of /lbbs/src/editor.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.50 by sysadm, Sun Oct 19 07:42:53 2025 UTC Revision 1.55 by sysadm, Sat Nov 8 08:21:31 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                                     editor.h  -  description  /*
3                                                           -------------------   * editor
4          copyright            : (C) 2004-2025 by Leaflet   *   - user interactive full-screen text editor
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 24  Line 16 
16  #include "str_process.h"  #include "str_process.h"
17  #include <stdlib.h>  #include <stdlib.h>
18  #include <string.h>  #include <string.h>
19    #include <wchar.h>
20  #include <sys/param.h>  #include <sys/param.h>
21    
22  #define EDITOR_ESC_DISPLAY_STR "\033[32m*\033[m"  enum _editor_constant_t
23  #define EDITOR_MEM_POOL_LINE_PER_CHUNK 1000  {
24  #define EDITOR_MEM_POOL_CHUNK_LIMIT (MAX_EDITOR_DATA_LINES / EDITOR_MEM_POOL_LINE_PER_CHUNK + 1)          EDITOR_MEM_POOL_LINE_PER_CHUNK = 1000,
25            EDITOR_MEM_POOL_CHUNK_LIMIT = (MAX_EDITOR_DATA_LINES / EDITOR_MEM_POOL_LINE_PER_CHUNK + 1),
26    };
27    
28    static const char EDITOR_ESC_DISPLAY_STR[] = "\033[32m*\033[m";
29    
30  static MEMORY_POOL *p_mp_data_line;  static MEMORY_POOL *p_mp_data_line;
31  static MEMORY_POOL *p_mp_editor_data;  static MEMORY_POOL *p_mp_editor_data;
# Line 632  static int editor_display_key_handler(in Line 629  static int editor_display_key_handler(in
629          {          {
630          case 0: // Set msg          case 0: // Set msg
631                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),
632                                   "| 退出[\033[32mCtrl-W\033[33m] |");                                   "| 退出[\033[32mCtrl-W\033[33m] | [\033[32m%s\033[33m]",
633                                     (UTF8_fixed_width ? "定宽" : "变宽"));
634                  break;                  break;
635          case KEY_CSI:          case KEY_CSI:
636                  *p_key = KEY_ESC;                  *p_key = KEY_ESC;
# Line 648  int editor_display(EDITOR_DATA *p_editor Line 646  int editor_display(EDITOR_DATA *p_editor
646          char buffer[MAX_EDITOR_DATA_LINE_LENGTH];          char buffer[MAX_EDITOR_DATA_LINE_LENGTH];
647          EDITOR_CTX ctx;          EDITOR_CTX ctx;
648          int ch = 0;          int ch = 0;
649          char input_str[4];          char input_str[5];
650            wchar_t wcs[2];
651          char c;          char c;
652          int str_len = 0;          int str_len = 0;
653          int input_ok;          int input_ok;
# Line 708  int editor_display(EDITOR_DATA *p_editor Line 707  int editor_display(EDITOR_DATA *p_editor
707                          iflush();                          iflush();
708    
709                          str_len = 0;                          str_len = 0;
710                          ch = igetch_t(MAX_DELAY_TIME);                          ch = igetch_t(BBS_max_user_idle_time);
711                          while (!SYS_server_exit)                          while (!SYS_server_exit)
712                          {                          {
713                                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)                                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
# Line 748  int editor_display(EDITOR_DATA *p_editor Line 747  int editor_display(EDITOR_DATA *p_editor
747                                                          break;                                                          break;
748                                                  }                                                  }
749                                          }                                          }
750                                            input_str[str_len] = '\0';
751                                  }                                  }
752    
753                                  if ((ch >= 32 && ch < 127) || str_len >= 2 || // Printable character or multi-byte character                                  if ((ch >= 32 && ch < 127) || str_len >= 2 || // Printable character or multi-byte character
# Line 825  int editor_display(EDITOR_DATA *p_editor Line 825  int editor_display(EDITOR_DATA *p_editor
825                                                          }                                                          }
826                                                          if (offset_out > 0)                                                          if (offset_out > 0)
827                                                          {                                                          {
828                                                                  col_pos += (str_len == 1 ? 1 : 2);                                                                  if (mbstowcs(wcs, input_str, 1) == (size_t)-1)
829                                                                    {
830                                                                            log_error("mbstowcs() error\n");
831                                                                    }
832                                                                    col_pos += (str_len == 1 ? 1 : (UTF8_fixed_width ? 2 : wcwidth(wcs[0])));
833                                                          }                                                          }
834                                                  }                                                  }
835                                          }                                          }
# Line 863  int editor_display(EDITOR_DATA *p_editor Line 867  int editor_display(EDITOR_DATA *p_editor
867    
868                                                  offset_in = split_line(p_editor_data->p_display_lines[line_current - output_current_row + row_pos],                                                  offset_in = split_line(p_editor_data->p_display_lines[line_current - output_current_row + row_pos],
869                                                                                             (int)col_pos - 1, &eol, &display_len, 0);                                                                                             (int)col_pos - 1, &eol, &display_len, 0);
870                                                  if (offset_in >= 1 && p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in - 1] < 0) // UTF8                                                  col_pos = display_len;
                                                 {  
                                                         col_pos = display_len - 1;  
                                                 }  
                                                 else  
                                                 {  
                                                         col_pos = display_len;  
                                                 }  
   
871                                                  if (col_pos < 1 && line_current - output_current_row + row_pos >= 0)                                                  if (col_pos < 1 && line_current - output_current_row + row_pos >= 0)
872                                                  {                                                  {
873                                                          row_pos--;                                                          row_pos--;
# Line 1028  int editor_display(EDITOR_DATA *p_editor Line 1024  int editor_display(EDITOR_DATA *p_editor
1024                                  case KEY_LEFT:                                  case KEY_LEFT:
1025                                          offset_in = split_line(p_editor_data->p_display_lines[line_current - output_current_row + row_pos],                                          offset_in = split_line(p_editor_data->p_display_lines[line_current - output_current_row + row_pos],
1026                                                                                     (int)col_pos - 1, &eol, &display_len, 0);                                                                                     (int)col_pos - 1, &eol, &display_len, 0);
1027                                            col_pos = display_len;
1028                                          if (offset_in >= 1 && p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in - 1] < 0) // UTF8                                          if (offset_in >= 1 && p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in - 1] < 0) // UTF8
1029                                          {                                          {
1030                                                  col_pos = display_len - 1;                                                  split_line(p_editor_data->p_display_lines[line_current - output_current_row + row_pos],
1031                                          }                                                                     (int)col_pos - 1, &eol, &display_len, 0);
1032                                          else                                                  if (display_len == col_pos - 2)
1033                                          {                                                  {
1034                                                  col_pos = display_len;                                                          col_pos--;
1035                                                    }
1036                                          }                                          }
1037                                          if (col_pos >= 1)                                          if (col_pos >= 1)
1038                                          {                                          {
# Line 1063  int editor_display(EDITOR_DATA *p_editor Line 1061  int editor_display(EDITOR_DATA *p_editor
1061                                  case KEY_RIGHT:                                  case KEY_RIGHT:
1062                                          offset_in = split_line(p_editor_data->p_display_lines[line_current - output_current_row + row_pos],                                          offset_in = split_line(p_editor_data->p_display_lines[line_current - output_current_row + row_pos],
1063                                                                                     (int)col_pos - 1, &eol, &display_len, 0);                                                                                     (int)col_pos - 1, &eol, &display_len, 0);
1064                                            col_pos = display_len + 2;
1065                                          if (offset_in < p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] &&                                          if (offset_in < p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] &&
1066                                                  p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in] < 0) // UTF8                                                  p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in] < 0) // UTF8
1067                                          {                                          {
1068                                                  col_pos = display_len + 3;                                                  split_line(p_editor_data->p_display_lines[line_current - output_current_row + row_pos] + offset_in,
1069                                          }                                                                     1, &eol, &display_len, 0);
1070                                          else                                                  if (display_len == 0)
1071                                          {                                                  {
1072                                                  col_pos = display_len + 2;                                                          col_pos++;
1073                                                    }
1074                                          }                                          }
1075                                          if (col_pos <= p_editor_data->display_line_widths[line_current - output_current_row + row_pos])                                          if (col_pos <= p_editor_data->display_line_widths[line_current - output_current_row + row_pos])
1076                                          {                                          {
# Line 1164  int editor_display(EDITOR_DATA *p_editor Line 1164  int editor_display(EDITOR_DATA *p_editor
1164                                          break;                                          break;
1165                                  }                                  }
1166    
1167                                  ch = igetch_t(MAX_DELAY_TIME);                                  ch = igetch_t(BBS_max_user_idle_time);
1168                          }                          }
1169    
1170                          continue;                          continue;


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

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