/[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.26 by sysadm, Sat May 3 06:24:54 2025 UTC Revision 1.36 by sysadm, Tue May 6 05:31:26 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2                                                    screen.c  -  description                                                    screen.c  -  description
3                                                           -------------------                                                           -------------------
4          begin                : Mon Oct 18 2004          Copyright            : (C) 2004-2025 by Leaflet
5          copyright            : (C) 2004 by Leaflet          Email                : leaflet@leafok.com
         email                : leaflet@leafok.com  
6   ***************************************************************************/   ***************************************************************************/
7    
8  /***************************************************************************  /***************************************************************************
9   *                                                                         *   *                                                                         *
10   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
11   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
12   *   the Free Software Foundation; either version 2 of the License, or     *   *   the Free Software Foundation; either version 3 of the License, or     *
13   *   (at your option) any later version.                                   *   *   (at your option) any later version.                                   *
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
# Line 76  void clearscr() Line 75  void clearscr()
75    
76  int press_any_key()  int press_any_key()
77  {  {
         igetch(1);  
   
78          moveto(screen_rows, 0);          moveto(screen_rows, 0);
79          clrtoeol();          clrtoeol();
80    
# Line 106  void set_input_echo(int echo) Line 103  void set_input_echo(int echo)
103    
104  static int _str_input(char *buffer, int buffer_length, int echo_mode)  static int _str_input(char *buffer, int buffer_length, int echo_mode)
105  {  {
106          char buf[256], ch;          int c, offset = 0, i, hz = 0;
         int c, offset = 0, len, loop = 1, i, hz = 0;  
107    
108          for (i = 0; i < buffer_length && buffer[i] != '\0'; i++)          for (i = 0; i < buffer_length && buffer[i] != '\0'; i++)
109          {          {
110                  offset++;                  offset++;
111          }          }
112    
113          igetch(1);          while ((c = igetch_t(60)))
   
         while (c = igetch_t(60))  
114          {          {
115                  if (c == KEY_NULL || c == KEY_TIMEOUT || c == CR)                  if (c == KEY_NULL || c == KEY_TIMEOUT || c == CR)
116                  {                  {
117                            igetch(1); // Cleanup remaining '\n' in the buffer
118                          break;                          break;
119                  }                  }
120                  if (c == LF)                  if (c == LF)
# Line 130  static int _str_input(char *buffer, int Line 125  static int _str_input(char *buffer, int
125                  {                  {
126                          if (offset > 0)                          if (offset > 0)
127                          {                          {
128                                  buffer[--offset] = '\0';                                  offset--;
129                                  prints("\b \b");                                  if (buffer[offset] < 0 || buffer[offset] > 127)
130                                  //            clrtoeol ();                                  {
131                                            prints("\033[D \033[D");
132                                            offset--;
133                                            if (offset < 0) // should not happen
134                                            {
135                                                    log_error("Offset of buffer is negative\n");
136                                                    offset = 0;
137                                            }
138                                    }
139                                    buffer[offset] = '\0';
140                                    prints("\033[D \033[D");
141                                  iflush();                                  iflush();
142                          }                          }
143                          continue;                          continue;
# Line 143  static int _str_input(char *buffer, int Line 148  static int _str_input(char *buffer, int
148                  }                  }
149                  if (c > 127 && c <= 255)                  if (c > 127 && c <= 255)
150                  {                  {
151                            if (!hz && offset + 2 > buffer_length) // No enough space for Chinese character
152                            {
153                                    igetch(1); // Cleanup remaining input
154                                    outc('\a');
155                                    iflush();
156                                    continue;
157                            }
158                          hz = (!hz);                          hz = (!hz);
159                  }                  }
160                  if (offset >= buffer_length)                  if (offset >= buffer_length)
161                  {                  {
162                          outc('\a');                          outc('\a');
163                            iflush();
164                          continue;                          continue;
165                  }                  }
166                  buffer[offset++] = (char)c;                  buffer[offset++] = (char)c;
# Line 167  static int _str_input(char *buffer, int Line 180  static int _str_input(char *buffer, int
180                  }                  }
181          }          }
182    
         prints("\r\n");  
         iflush();  
   
183          return offset;          return offset;
184  }  }
185    
186  int str_input(char *buffer, int buffer_length, int echo_mode)  int str_input(char *buffer, int buffer_length, int echo_mode)
187  {  {
188          int offset;          int len;
189    
190          memset(buffer, '\0', buffer_length);          buffer[0] = '\0';
191    
192          offset = _str_input(buffer, buffer_length, echo_mode);          len = _str_input(buffer, buffer_length, echo_mode);
193    
194          return offset;          prints("\r\n");
195            iflush();
196    
197            return len;
198  };  };
199    
200  int get_data(int row, int col, char *prompt, char *buffer, int buffer_length, int echo_mode)  int get_data(int row, int col, char *prompt, char *buffer, int buffer_length, int echo_mode)
201  {  {
202          int len;          int len;
203    
204            igetch(1); // Cleanup input buffer
205    
206          moveto(row, col);          moveto(row, col);
207          prints(prompt);          prints(prompt);
208          prints(buffer);          prints(buffer);
# Line 202  int display_file(const char *filename) Line 217  int display_file(const char *filename)
217  {  {
218          char buffer[LINE_BUFFER_LEN];          char buffer[LINE_BUFFER_LEN];
219          FILE *fin;          FILE *fin;
220          int i;          size_t i;
221    
222          if ((fin = fopen(filename, "r")) == NULL)          if ((fin = fopen(filename, "r")) == NULL)
223          {          {
# Line 229  int display_file(const char *filename) Line 244  int display_file(const char *filename)
244  int display_file_ex(const char *filename, int begin_line, int wait)  int display_file_ex(const char *filename, int begin_line, int wait)
245  {  {
246          char buffer[LINE_BUFFER_LEN];          char buffer[LINE_BUFFER_LEN];
         char temp[LINE_BUFFER_LEN];  
247          int ch = 0;          int ch = 0;
248          int input_ok, line, max_lines;          int input_ok, line, max_lines;
249          long int c_line_current = 0, c_line_total = 0;          long int c_line_current = 0;
250            long int c_line_total = 0;
251          FILE *fin;          FILE *fin;
         struct stat f_stat;  
252          long *p_line_offsets;          long *p_line_offsets;
253          int len;          long int len;
254          int percentile;          long int percentile;
255            int loop = 1;
256    
257          if ((fin = fopen(filename, "r")) == NULL)          if ((fin = fopen(filename, "r")) == NULL)
258          {          {
# Line 253  int display_file_ex(const char *filename Line 268  int display_file_ex(const char *filename
268          line = begin_line;          line = begin_line;
269          max_lines = screen_rows - 1;          max_lines = screen_rows - 1;
270    
271          while (c_line_current < c_line_total)          while (loop)
272          {          {
273                  if (line >= max_lines)                  if (c_line_current >= c_line_total && c_line_total <= screen_rows - 2)
274                  {                  {
275                          percentile = (c_line_current - (line - 1) + (screen_rows - 2)) * 100 / c_line_total;                          if (wait)
276                            {
277                                    ch = press_any_key();
278                            }
279                            else
280                            {
281                                    iflush();
282                            }
283    
284                            loop = 0;
285                            break;
286                    }
287    
288                    if (c_line_current >= c_line_total || line >= max_lines)
289                    {
290                            if (c_line_current - (line - 1) + (screen_rows - 2) < c_line_total)
291                            {
292                                    percentile = (c_line_current - (line - 1) + (screen_rows - 2)) * 100 / c_line_total;
293                            }
294                            else
295                            {
296                                    percentile = 100;
297                            }
298    
299                          moveto(screen_rows, 0);                          moveto(screen_rows, 0);
300                          prints("\033[1;44;32m下面还有喔 (%d%%)\033[33m   │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │     \033[m",                          prints("\033[1;44;32m%s (%d%%)%s\033[33m  │ 结束 ← <q> │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │     \033[m",
301                                     percentile);                                     (percentile < 100 ? "下面还有喔" : "没有更多了"), percentile,
302                                       (percentile < 10 ? "  " : (percentile < 100 ? " " : "")));
303                          iflush();                          iflush();
304    
305                          input_ok = 0;                          input_ok = 0;
# Line 279  int display_file_ex(const char *filename Line 317  int display_file_ex(const char *filename
317                                          c_line_current -= line;                                          c_line_current -= line;
318                                          line = begin_line;                                          line = begin_line;
319                                          max_lines = begin_line + 1;                                          max_lines = begin_line + 1;
320                                          prints("\033[1T"); // Scroll down 1 line                                          prints("\033[T"); // Scroll down 1 line
321                                            // max_lines = screen_rows - 1; // Legacy Fterm only works with this line
322                                          break;                                          break;
323                                  case KEY_DOWN:                                  case KEY_DOWN:
324                                  case CR:                                  case CR:
# Line 292  int display_file_ex(const char *filename Line 331  int display_file_ex(const char *filename
331                                          max_lines = screen_rows - 1;                                          max_lines = screen_rows - 1;
332                                          moveto(screen_rows, 0);                                          moveto(screen_rows, 0);
333                                          clrtoeol();                                          clrtoeol();
334                                          prints("\033[1S"); // Scroll up 1 line                                          prints("\033[S"); // Scroll up 1 line
335                                          break;                                          break;
336                                  case KEY_PGUP:                                  case KEY_PGUP:
337                                  case Ctrl('B'):                                  case Ctrl('B'):
# Line 331  int display_file_ex(const char *filename Line 370  int display_file_ex(const char *filename
370                                  case KEY_LEFT:                                  case KEY_LEFT:
371                                  case 'q':                                  case 'q':
372                                  case 'Q':                                  case 'Q':
373                                          c_line_current = c_line_total;                                          loop = 0;
                                         wait = 0;  
374                                          break;                                          break;
375                                  case '?':                                  case '?':
376                                  case 'h':                                  case 'h':
377                                  case 'H':                                  case 'H':
378                                          // Display help information                                          // Display help information
379                                          strcpy(temp, app_home_dir);                                          display_file_ex(DATA_READ_HELP, begin_line, 1);
                                         strcat(temp, "data/read_help.txt");  
                                         display_file_ex(temp, begin_line, 1);  
380    
381                                          // Refresh after display help information                                          // Refresh after display help information
382                                          c_line_current -= (line - 1);                                          c_line_current -= (line - 1);
# Line 364  int display_file_ex(const char *filename Line 400  int display_file_ex(const char *filename
400                          log_error("Error length exceeds buffer size: %d\n", len);                          log_error("Error length exceeds buffer size: %d\n", len);
401                          len = LINE_BUFFER_LEN - 1;                          len = LINE_BUFFER_LEN - 1;
402                  }                  }
403                  if (fgets(buffer, len + 1, fin) == NULL)                  if (fgets(buffer, (int)len + 1, fin) == NULL)
404                  {                  {
405                          log_error("Reach EOF\n");                          log_error("Reach EOF\n");
406                          break;                          break;
# Line 376  int display_file_ex(const char *filename Line 412  int display_file_ex(const char *filename
412                  line++;                  line++;
413          }          }
414    
         iflush();  
   
         if (wait)  
         {  
                 ch = press_any_key();  
         }  
   
415          free(p_line_offsets);          free(p_line_offsets);
416          fclose(fin);          fclose(fin);
417    
# Line 393  int show_top(char *status) Line 422  int show_top(char *status)
422  {  {
423          char buffer[LINE_BUFFER_LEN];          char buffer[LINE_BUFFER_LEN];
424    
425          str_space(buffer, 20 - strlen(BBS_current_section_name));          str_space(buffer, 20 - (int)strnlen(BBS_current_section_name, sizeof(BBS_current_section_name)));
426    
427          moveto(1, 0);          moveto(1, 0);
428          clrtoeol();          clrtoeol();
# Line 408  int show_top(char *status) Line 437  int show_top(char *status)
437  int show_bottom(char *msg)  int show_bottom(char *msg)
438  {  {
439          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
         char str_time_onine[20];  
440          char buffer[LINE_BUFFER_LEN];          char buffer[LINE_BUFFER_LEN];
441          time_t time_online;          time_t time_online;
442          struct tm *tm_online;          struct tm *tm_online;
443    
444          get_time_str(str_time, sizeof(str_time));          get_time_str(str_time, sizeof(str_time));
445          str_space(buffer, 33 - strlen(BBS_username));          str_space(buffer, 33 - (int)strnlen(BBS_username, sizeof(BBS_username)));
446    
447          time_online = time(0) - BBS_login_tm;          time_online = time(0) - BBS_login_tm;
448          tm_online = gmtime(&time_online);          tm_online = gmtime(&time_online);
# Line 437  int show_active_board() Line 465  int show_active_board()
465          char buffer[LINE_BUFFER_LEN];          char buffer[LINE_BUFFER_LEN];
466          FILE *fin;          FILE *fin;
467          static int line;          static int line;
468          int len;          unsigned int len;
469          int end_of_line;          int end_of_line;
470    
         sprintf(filename, "%sdata/active_board.txt", app_home_dir);  
   
471          clrline(3, 2 + ACTIVE_BOARD_HEIGHT);          clrline(3, 2 + ACTIVE_BOARD_HEIGHT);
472    
473          if ((fin = fopen(filename, "r")) == NULL)          if ((fin = fopen(DATA_ACTIVE_BOARD, "r")) == NULL)
474          {          {
475                  log_error("Unable to open file %s\n", filename);                  log_error("Unable to open file %s\n", filename);
476                  return -1;                  return -1;


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

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