/[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.2 by sysadm, Mon Jun 9 15:41:09 2025 UTC Revision 1.3 by sysadm, Tue Jun 10 06:48:23 2025 UTC
# Line 141  void editor_data_cleanup(EDITOR_DATA *p_ Line 141  void editor_data_cleanup(EDITOR_DATA *p_
141          free(p_editor_data);          free(p_editor_data);
142  }  }
143    
144  int editor_data_insert(EDITOR_DATA *p_editor_data, long display_line, long offset,  int editor_data_insert(EDITOR_DATA *p_editor_data, long *p_display_line, long *p_offset,
145                                             const char *str, int str_len, long *p_last_updated_line)                                             const char *str, int str_len, long *p_last_updated_line)
146  {  {
147            long display_line = *p_display_line;
148            long offset = *p_offset;
149            int done = 0;
150          int len;          int len;
151          int display_len;          int display_len;
152          int eol;          int eol;
# Line 227  int editor_data_insert(EDITOR_DATA *p_ed Line 230  int editor_data_insert(EDITOR_DATA *p_ed
230                          return -2;                          return -2;
231                  }                  }
232    
233                  // Copy rest part of current data line since next display line to new data line                  if (last_display_line > display_line)
                 memcpy(p_editor_data->p_data_lines[p_editor_data->data_line_total],  
                            p_editor_data->p_display_lines[display_line + 1],  
                            (size_t)(len_data_line - (p_editor_data->p_display_lines[display_line + 1] - p_data_line)));  
                 p_editor_data->p_data_lines[p_editor_data->data_line_total]  
                                                                    [len_data_line - (p_editor_data->p_display_lines[display_line + 1] - p_data_line)] = '\0';  
   
                 p_data_line = p_editor_data->p_display_lines[display_line + 1];  
                 for (i = display_line + 1; i <= last_display_line; i++)  
234                  {                  {
235                          p_editor_data->p_display_lines[i] +=                          // Copy rest part of current data line (since next display line) to new data line
236                                  (p_editor_data->p_data_lines[p_editor_data->data_line_total] - p_data_line);                          memcpy(p_editor_data->p_data_lines[p_editor_data->data_line_total],
237                                       p_editor_data->p_display_lines[display_line + 1],
238                                       (size_t)(len_data_line - (p_editor_data->p_display_lines[display_line + 1] - p_data_line)));
239                            p_editor_data->p_data_lines[p_editor_data->data_line_total]
240                                                                               [len_data_line - (p_editor_data->p_display_lines[display_line + 1] - p_data_line)] = '\0';
241    
242                            // Relocate rest display lines (since next one) of current data line
243                            p_data_line = p_editor_data->p_display_lines[display_line + 1];
244                            for (i = display_line + 1; i <= last_display_line; i++)
245                            {
246                                    p_editor_data->p_display_lines[i] =
247                                            p_editor_data->p_data_lines[p_editor_data->data_line_total] +
248                                            (p_editor_data->p_display_lines[i] - p_data_line);
249                            }
250                  }                  }
251                    else // last_display_line == display_line
                 // Copy rest part of current display line to buffer  
                 if (offset_data_line >= MAX_EDITOR_DATA_LINE_LENGTH / 2)  
252                  {                  {
253                          memcpy(buf_insert + len_insert,                          // Insert blank display line pointing to new data line
254                                     p_editor_data->p_display_lines[display_line] + offset,                          for (i = p_editor_data->display_line_total; i > display_line + 1; i--)
255                                     (size_t)(p_editor_data->display_line_lengths[display_line] - offset));                          {
256                          len_insert += (p_editor_data->display_line_lengths[display_line] - offset);                                  p_editor_data->p_display_lines[i] = p_editor_data->p_display_lines[i - 1];
257                                    p_editor_data->display_line_lengths[i] = p_editor_data->display_line_lengths[i - 1];
258                            }
259                            p_editor_data->p_display_lines[display_line + 1] = p_editor_data->p_data_lines[p_editor_data->data_line_total];
260                            p_editor_data->display_line_lengths[display_line + 1] = 0;
261    
262                            (p_editor_data->display_line_total)++;
263                            last_display_line++;
264                  }                  }
265                  else  
266                    *p_last_updated_line = p_editor_data->display_line_total;
267                    (p_editor_data->data_line_total)++;
268    
269                    if (offset_data_line + str_len + 2 < MAX_EDITOR_DATA_LINE_LENGTH)
270                  {                  {
271                            // Copy rest part of current display line to insert buffer
272                          memcpy(buf_insert,                          memcpy(buf_insert,
273                                     p_editor_data->p_display_lines[display_line] + offset,                                     p_editor_data->p_display_lines[display_line] + offset,
274                                     (size_t)(p_editor_data->display_line_lengths[display_line] - offset));                                     (size_t)(p_editor_data->display_line_lengths[display_line] - offset));
275                          len_insert = (p_editor_data->display_line_lengths[display_line] - offset);                          len_insert = (p_editor_data->display_line_lengths[display_line] - offset);
276                  }                          buf_insert[len_insert] = '\0';
                 buf_insert[len_insert] = '\0';  
277    
278                  if (offset_data_line >= MAX_EDITOR_DATA_LINE_LENGTH / 2)                          // Append str to current display line
                 {  
                         // Add line ending to current display line (data line)  
                         p_editor_data->p_display_lines[display_line][offset] = '\n';  
                         p_editor_data->p_display_lines[display_line][offset + 1] = '\0';  
                         p_editor_data->display_line_lengths[display_line] = offset + 1;  
                 }  
                 else  
                 {  
279                          memcpy(p_editor_data->p_display_lines[display_line] + offset, str, (size_t)str_len);                          memcpy(p_editor_data->p_display_lines[display_line] + offset, str, (size_t)str_len);
280    
281                          // Add line ending to current display line (data line)                          // Add line ending to current display line (data line)
282                          p_editor_data->p_display_lines[display_line][offset + str_len] = '\n';                          p_editor_data->p_display_lines[display_line][offset + str_len] = '\n';
283                          p_editor_data->p_display_lines[display_line][offset + str_len + 1] = '\0';                          p_editor_data->p_display_lines[display_line][offset + str_len + 1] = '\0';
284                          p_editor_data->display_line_lengths[display_line] = offset + str_len + 1;                          p_editor_data->display_line_lengths[display_line] = offset + str_len + 1;
285    
286                            if (!done)
287                            {
288                                    *p_display_line = display_line;
289                                    *p_offset = offset + str_len;
290                                    done = 1;
291                            }
292                    }
293                    else
294                    {
295                            // Append rest part of current display line to insert buffer
296                            memcpy(buf_insert + len_insert,
297                                       p_editor_data->p_display_lines[display_line] + offset,
298                                       (size_t)(p_editor_data->display_line_lengths[display_line] - offset));
299                            len_insert += (p_editor_data->display_line_lengths[display_line] - offset);
300                            buf_insert[len_insert] = '\0';
301    
302                            // Add line ending to current display line (data line)
303                            p_editor_data->p_display_lines[display_line][offset] = '\n';
304                            p_editor_data->p_display_lines[display_line][offset + 1] = '\0';
305                            p_editor_data->display_line_lengths[display_line] = offset + 1;
306                  }                  }
307    
308                  display_line++;                  display_line++;
309                  offset = 0;                  offset = 0;
   
                 *p_last_updated_line = p_editor_data->display_line_total;  
   
                 last_display_line++;  
                 (p_editor_data->display_line_total)++;  
                 (p_editor_data->data_line_total)++;  
310          }          }
311    
312          for (i = display_line; len_insert > 0 && i <= last_display_line; i++)          for (i = display_line; len_insert > 0 && i <= last_display_line; i++)
# Line 299  int editor_data_insert(EDITOR_DATA *p_ed Line 323  int editor_data_insert(EDITOR_DATA *p_ed
323                  buf_catenate[p_editor_data->display_line_lengths[i]] = '\0';                  buf_catenate[p_editor_data->display_line_lengths[i]] = '\0';
324    
325                  len = split_line(buf_catenate, SCREEN_COLS - display_len_insert, &eol, &display_len);                  len = split_line(buf_catenate, SCREEN_COLS - display_len_insert, &eol, &display_len);
326                  if (len < offset) // have no space to insert                  if (len < offset) // offset out of current display line
327                  {                  {
328                          offset = 0;                          offset -= len;
329                          continue; // retry at next display line                          continue;
330                  }                  }
331    
332                  // move \n to next display line if current line is full                  // move \n to next display line if current line is full
# Line 317  int editor_data_insert(EDITOR_DATA *p_ed Line 341  int editor_data_insert(EDITOR_DATA *p_ed
341                  len_catenate = len_insert + len;                  len_catenate = len_insert + len;
342                  buf_catenate[len_catenate] = '\0';                  buf_catenate[len_catenate] = '\0';
343    
                 offset = 0;  
344                  len_insert = p_editor_data->display_line_lengths[i] - len;                  len_insert = p_editor_data->display_line_lengths[i] - len;
345                  if (len_insert > 0)                  if (len_insert > 0)
346                  {                  {
# Line 327  int editor_data_insert(EDITOR_DATA *p_ed Line 350  int editor_data_insert(EDITOR_DATA *p_ed
350    
351                  memcpy(p_editor_data->p_display_lines[i], buf_catenate, (size_t)len_catenate);                  memcpy(p_editor_data->p_display_lines[i], buf_catenate, (size_t)len_catenate);
352                  p_editor_data->display_line_lengths[i] = len_catenate;                  p_editor_data->display_line_lengths[i] = len_catenate;
353    
354                    if (!done)
355                    {
356                            *p_display_line = i;
357                            *p_offset = offset + str_len;
358                            done = 1;
359                    }
360    
361                    offset = 0;
362          }          }
363    
364          *p_last_updated_line = MAX(i, *p_last_updated_line);          *p_last_updated_line = MAX(i, *p_last_updated_line);
# Line 358  int editor_data_insert(EDITOR_DATA *p_ed Line 390  int editor_data_insert(EDITOR_DATA *p_ed
390                  p_editor_data->p_display_lines[last_display_line][len_insert] = '\0';                  p_editor_data->p_display_lines[last_display_line][len_insert] = '\0';
391                  p_editor_data->display_line_lengths[last_display_line] = len_insert;                  p_editor_data->display_line_lengths[last_display_line] = len_insert;
392    
393                    if (!done)
394                    {
395                            *p_display_line = last_display_line;
396                            *p_offset = str_len;
397                            done = 1;
398                    }
399    
400                  *p_last_updated_line = MAX(last_display_line, *p_last_updated_line);                  *p_last_updated_line = MAX(last_display_line, *p_last_updated_line);
401          }          }
402    
403          return 0;          if (done && *p_offset >= SCREEN_COLS)
404            {
405                    (*p_display_line)++;
406                    *p_offset = 0;
407    
408                    if (*p_display_line >= p_editor_data->display_line_total)
409                    {
410                            log_error("*p_display_line(%d) >= display_line_total(%d)\n", *p_display_line, p_editor_data->display_line_total);
411                    }
412            }
413    
414            return done;
415  }  }
416    
417  int editor_data_delete(EDITOR_DATA *p_editor_data, long display_line, long offset,  int editor_data_delete(EDITOR_DATA *p_editor_data, long display_line, long offset,
# Line 389  int editor_display(EDITOR_DATA *p_editor Line 439  int editor_display(EDITOR_DATA *p_editor
439          char buffer[MAX_EDITOR_DATA_LINE_LENGTH];          char buffer[MAX_EDITOR_DATA_LINE_LENGTH];
440          EDITOR_CTX ctx;          EDITOR_CTX ctx;
441          int ch = 0;          int ch = 0;
442          char hz_ch[4];          char insert_str[4];
443          int hz_len;          int str_len = 0;
444          int input_ok, screen_current_line;          int input_ok;
445          const int screen_begin_line = 1;          int screen_current_row;
446          int screen_end_line = SCREEN_ROWS - 1;          const int screen_begin_row = 1;
447          const int screen_line_total = screen_end_line - screen_begin_line + 1;          int screen_end_row = SCREEN_ROWS - 1;
448            const int screen_row_total = screen_end_row - screen_begin_row + 1;
449          long int line_current = 0;          long int line_current = 0;
450          long int len;          long int len;
451          int loop;          int loop;
452          int eol, display_len;          int eol, display_len;
453          long row_pos = 1, col_pos = 1;          long row_pos = 1, col_pos = 1;
454            long display_line_in, offset_in;
455            long display_line_out, offset_out;
456            int scroll_rows;
457          long last_updated_line = 0;          long last_updated_line = 0;
458          int insert = 1;          int insert = 1;
459            int i;
460    
461          screen_current_line = screen_begin_line;          screen_current_row = screen_begin_row;
462          clrline(screen_begin_line, SCREEN_ROWS);          clrline(screen_begin_row, SCREEN_ROWS);
463    
464          // update msg_ext with extended key handler          // update msg_ext with extended key handler
465          if (editor_display_key_handler(&ch, &ctx) != 0)          if (editor_display_key_handler(&ch, &ctx) != 0)
# Line 415  int editor_display(EDITOR_DATA *p_editor Line 470  int editor_display(EDITOR_DATA *p_editor
470          loop = 1;          loop = 1;
471          while (!SYS_server_exit && loop)          while (!SYS_server_exit && loop)
472          {          {
473                  if (line_current >= p_editor_data->display_line_total || screen_current_line > screen_end_line)                  if (line_current >= p_editor_data->display_line_total || screen_current_row > screen_end_row)
474                  {                  {
475                          ctx.line_cursor = line_current - screen_current_line + row_pos + 1;                          ctx.line_cursor = line_current - screen_current_row + row_pos + 1;
476    
477                          snprintf(buffer, sizeof(buffer),                          snprintf(buffer, sizeof(buffer),
478                                           "\033[1;44;33m[\033[32m%ld\033[33m;\033[32m%ld\033[33m] "                                           "\033[1;44;33m[\033[32m%ld\033[33m;\033[32m%ld\033[33m] "
# Line 453  int editor_display(EDITOR_DATA *p_editor Line 508  int editor_display(EDITOR_DATA *p_editor
508                                          goto cleanup;                                          goto cleanup;
509                                  }                                  }
510    
511                                  if (ch >= 32 && ch < 127) // printable character                                  if (ch > 127 && ch <= 255) // GBK
512                                    {
513                                            insert_str[str_len] = (char)(ch - 256);
514                                            str_len++;
515                                    }
516                                    else
517                                    {
518                                            str_len = 0;
519                                    }
520    
521                                    if ((ch >= 32 && ch < 127) || (ch > 127 && ch <= 255 && str_len == 2)) // printable character or GBK
522                                  {                                  {
523                                            if (str_len == 0)
524                                            {
525                                                    insert_str[0] = (char)ch;
526                                                    str_len = 1;
527                                            }
528    
529                                          last_updated_line = line_current;                                          last_updated_line = line_current;
530                                            display_line_in = line_current - screen_current_row + row_pos;
531                                            offset_in = col_pos - 1;
532                                            display_line_out = display_line_in;
533                                            offset_out = offset_in;
534    
535                                          if (editor_data_insert(p_editor_data, line_current - screen_current_line + row_pos, col_pos - 1,                                          if (editor_data_insert(p_editor_data, &display_line_out, &offset_out,
536                                                                                     (const char *)&ch, 1, &last_updated_line) < 0)                                                                                     insert_str, str_len, &last_updated_line) < 0)
537                                          {                                          {
538                                                  log_error("editor_data_op(INSERT ch) error\n");                                                  log_error("editor_data_insert(%s) error\n", insert_str);
539                                                    str_len = 0;
540                                          }                                          }
541                                          else                                          else
542                                          {                                          {
543                                                  screen_end_line = MIN(SCREEN_ROWS - 1, screen_current_line + (int)(last_updated_line - line_current));                                                  str_len = 0;
                                                 line_current -= (screen_current_line - row_pos);  
                                                 screen_current_line = (int)row_pos;  
544    
545                                                  col_pos++;                                                  screen_end_row = MIN(SCREEN_ROWS - 1, screen_current_row + (int)(last_updated_line - line_current));
546                                                  if (col_pos <= p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos])                                                  line_current -= (screen_current_row - row_pos);
547                                                  {                                                  screen_current_row = (int)row_pos;
                                                         continue;  
                                                 }  
                                                 col_pos = 1;  
                                                 ch = KEY_DOWN;  
                                         }  
                                 }  
                                 else if (ch > 127 && ch <= 255) // CJK character  
                                 {  
                                         hz_ch[hz_len] = (char)(ch - 256);  
                                         hz_len++;  
548    
549                                          if (hz_len == 2) // GBK                                                  scroll_rows = MAX(0, (int)(display_line_out - display_line_in) - (screen_end_row - screen_current_row));
                                         {  
                                                 hz_len = 0;  
                                                 last_updated_line = line_current;  
550    
551                                                  if (editor_data_insert(p_editor_data, line_current - screen_current_line + row_pos, col_pos - 1,                                                  if (scroll_rows > 0)
                                                                                            hz_ch, 2, &last_updated_line) < 0)  
552                                                  {                                                  {
553                                                          log_error("editor_data_op(INSERT hz) error\n");                                                          moveto(SCREEN_ROWS, 0);
554                                                  }                                                          clrtoeol();
555                                                  else                                                          for (i = 0; i < scroll_rows; i++)
556                                                  {                                                          {
557                                                          screen_end_line = MIN(SCREEN_ROWS - 1, screen_current_line + (int)(last_updated_line - line_current));                                                                  prints("\033[S"); // Scroll up 1 line
558                                                          line_current -= (screen_current_line - row_pos);                                                          }
                                                         screen_current_line = (int)row_pos;  
559    
560                                                          col_pos += 2;                                                          screen_current_row -= scroll_rows;
561                                                          if (col_pos <= p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos])                                                          if (screen_current_row < screen_begin_row)
562                                                          {                                                          {
563                                                                  continue;                                                                  line_current += (screen_begin_row - screen_current_row);
564                                                                    screen_current_row = screen_begin_row;
565                                                          }                                                          }
566                                                          col_pos = 1;                                                          row_pos = screen_end_row;
567                                                          ch = KEY_DOWN;                                                  }
568                                                    else // if (scroll_lines == 0)
569                                                    {
570                                                            row_pos += (display_line_out - display_line_in);
571                                                  }                                                  }
572                                                    col_pos = offset_out + 1;
573    
574                                                    continue;
575                                          }                                          }
576                                  }                                  }
577                                  else if (ch == KEY_DEL) // Del                                  else if (ch == KEY_DEL) // Del
578                                  {                                  {
579                                          last_updated_line = line_current;                                          last_updated_line = line_current;
580    
581                                          if (editor_data_delete(p_editor_data, line_current - screen_current_line + row_pos, col_pos - 1,                                          if (editor_data_delete(p_editor_data, line_current - screen_current_row + row_pos, col_pos - 1,
582                                                                                     &last_updated_line) < 0)                                                                                     &last_updated_line) < 0)
583                                          {                                          {
584                                                  log_error("editor_data_op(DELETE) error\n");                                                  log_error("editor_data_delete() error\n");
585                                          }                                          }
586                                          else                                          else
587                                          {                                          {
588                                                  screen_end_line = MIN(SCREEN_ROWS - 1, screen_current_line + (int)(last_updated_line - line_current));                                                  screen_end_row = MIN(SCREEN_ROWS - 1, screen_current_row + (int)(last_updated_line - line_current));
589                                          }                                          }
590    
591                                          continue;                                          continue;
592                                  }                                  }
593    
                                 hz_len = 0;  
   
594                                  switch (ch)                                  switch (ch)
595                                  {                                  {
596                                  case KEY_NULL:                                  case KEY_NULL:
# Line 539  int editor_display(EDITOR_DATA *p_editor Line 603  int editor_display(EDITOR_DATA *p_editor
603                                          col_pos = 1;                                          col_pos = 1;
604                                          break;                                          break;
605                                  case KEY_CTRL_RIGHT:                                  case KEY_CTRL_RIGHT:
606                                          col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]);                                          col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]);
607                                          break;                                          break;
608                                  case KEY_CTRL_UP:                                  case KEY_CTRL_UP:
609                                          row_pos = screen_begin_line;                                          row_pos = screen_begin_row;
610                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]));                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]));
611                                          break;                                          break;
612                                  case KEY_CTRL_DOWN:                                  case KEY_CTRL_DOWN:
613                                          row_pos = SCREEN_ROWS - 1;                                          row_pos = SCREEN_ROWS - 1;
614                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]));                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]));
615                                          break;                                          break;
616                                  case KEY_INS:                                  case KEY_INS:
617                                          insert = !insert;                                          insert = !insert;
# Line 555  int editor_display(EDITOR_DATA *p_editor Line 619  int editor_display(EDITOR_DATA *p_editor
619                                  case KEY_HOME:                                  case KEY_HOME:
620                                          row_pos = 1;                                          row_pos = 1;
621                                          col_pos = 1;                                          col_pos = 1;
622                                          if (line_current - screen_current_line < 0) // Reach begin                                          if (line_current - screen_current_row < 0) // Reach begin
623                                          {                                          {
624                                                  break;                                                  break;
625                                          }                                          }
626                                          line_current = 0;                                          line_current = 0;
627                                          screen_current_line = screen_begin_line;                                          screen_current_row = screen_begin_row;
628                                          screen_end_line = SCREEN_ROWS - 1;                                          screen_end_row = SCREEN_ROWS - 1;
629                                          clrline(screen_begin_line, SCREEN_ROWS);                                          clrline(screen_begin_row, SCREEN_ROWS);
630                                          break;                                          break;
631                                  case KEY_END:                                  case KEY_END:
632                                          if (p_editor_data->display_line_total < screen_line_total)                                          if (p_editor_data->display_line_total < screen_row_total)
633                                          {                                          {
634                                                  row_pos = p_editor_data->display_line_total;                                                  row_pos = p_editor_data->display_line_total;
635                                                  col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]);                                                  col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]);
636                                                  break;                                                  break;
637                                          }                                          }
638                                          line_current = p_editor_data->display_line_total - screen_line_total;                                          line_current = p_editor_data->display_line_total - screen_row_total;
639                                          screen_current_line = screen_begin_line;                                          screen_current_row = screen_begin_row;
640                                          screen_end_line = SCREEN_ROWS - 1;                                          screen_end_row = SCREEN_ROWS - 1;
641                                          row_pos = screen_line_total;                                          row_pos = screen_row_total;
642                                          col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]);                                          col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]);
643                                          clrline(screen_begin_line, SCREEN_ROWS);                                          clrline(screen_begin_row, SCREEN_ROWS);
644                                          break;                                          break;
645                                  case KEY_LEFT:                                  case KEY_LEFT:
646                                          if (col_pos > 1)                                          if (col_pos > 1)
# Line 586  int editor_display(EDITOR_DATA *p_editor Line 650  int editor_display(EDITOR_DATA *p_editor
650                                          }                                          }
651                                          col_pos = SCREEN_COLS; // continue to KEY_UP                                          col_pos = SCREEN_COLS; // continue to KEY_UP
652                                  case KEY_UP:                                  case KEY_UP:
653                                          if (row_pos > screen_begin_line)                                          if (row_pos > screen_begin_row)
654                                          {                                          {
655                                                  row_pos--;                                                  row_pos--;
656                                                  col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]));                                                  col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]));
657                                                  break;                                                  break;
658                                          }                                          }
659                                          if (line_current - screen_current_line < 0) // Reach begin                                          if (line_current - screen_current_row < 0) // Reach begin
660                                          {                                          {
661                                                  col_pos = 1;                                                  col_pos = 1;
662                                                  break;                                                  break;
663                                          }                                          }
664                                          line_current -= screen_current_line;                                          line_current -= screen_current_row;
665                                          screen_current_line = screen_begin_line;                                          screen_current_row = screen_begin_row;
666                                          // screen_end_line = begin_line;                                          // screen_end_line = begin_line;
667                                          // prints("\033[T"); // Scroll down 1 line                                          // prints("\033[T"); // Scroll down 1 line
668                                          screen_end_line = SCREEN_ROWS - 1; // Legacy Fterm only works with this line                                          screen_end_row = SCREEN_ROWS - 1; // Legacy Fterm only works with this line
669                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]));                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]));
670                                          break;                                          break;
671                                  case CR:                                  case CR:
672                                          break;                                          break;
673                                  case KEY_SPACE:                                  case KEY_SPACE:
674                                          break;                                          break;
675                                  case KEY_RIGHT:                                  case KEY_RIGHT:
676                                          if (col_pos < p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos])                                          if (col_pos < p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos])
677                                          {                                          {
678                                                  col_pos++;                                                  col_pos++;
679                                                  break;                                                  break;
680                                          }                                          }
681                                          col_pos = 1; // continue to KEY_DOWN                                          col_pos = 1; // continue to KEY_DOWN
682                                  case KEY_DOWN:                                  case KEY_DOWN:
683                                          if (row_pos < MIN(screen_line_total, p_editor_data->display_line_total))                                          if (row_pos < MIN(screen_row_total, p_editor_data->display_line_total))
684                                          {                                          {
685                                                  row_pos++;                                                  row_pos++;
686                                                  col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]));                                                  col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]));
687                                                  break;                                                  break;
688                                          }                                          }
689                                          if (line_current + (screen_line_total - (screen_current_line - screen_begin_line)) >= p_editor_data->display_line_total) // Reach end                                          if (line_current + (screen_row_total - (screen_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end
690                                          {                                          {
691                                                  col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]);                                                  col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]);
692                                                  break;                                                  break;
693                                          }                                          }
694                                          screen_current_line--;                                          line_current += (screen_row_total - (screen_current_row - screen_begin_row));
695                                          screen_end_line = SCREEN_ROWS - 1;                                          screen_current_row = screen_row_total;
696                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]));                                          screen_end_row = SCREEN_ROWS - 1;
697                                            col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]));
698                                          moveto(SCREEN_ROWS, 0);                                          moveto(SCREEN_ROWS, 0);
699                                          clrtoeol();                                          clrtoeol();
700                                          prints("\033[S"); // Scroll up 1 line                                          prints("\033[S"); // Scroll up 1 line
701                                          break;                                          break;
702                                  case KEY_PGUP:                                  case KEY_PGUP:
703                                          if (line_current - screen_current_line < 0) // Reach begin                                          if (line_current - screen_current_row < 0) // Reach begin
704                                          {                                          {
705                                                  break;                                                  break;
706                                          }                                          }
707                                          line_current -= ((screen_line_total - 1) + (screen_current_line - screen_begin_line));                                          line_current -= ((screen_row_total - 1) + (screen_current_row - screen_begin_row));
708                                          if (line_current < 0)                                          if (line_current < 0)
709                                          {                                          {
710                                                  line_current = 0;                                                  line_current = 0;
711                                          }                                          }
712                                          screen_current_line = screen_begin_line;                                          screen_current_row = screen_begin_row;
713                                          screen_end_line = SCREEN_ROWS - 1;                                          screen_end_row = SCREEN_ROWS - 1;
714                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]));                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]));
715                                          clrline(screen_begin_line, SCREEN_ROWS);                                          clrline(screen_begin_row, SCREEN_ROWS);
716                                          break;                                          break;
717                                  case KEY_PGDN:                                  case KEY_PGDN:
718                                          if (line_current + screen_line_total - (screen_current_line - screen_begin_line) >= p_editor_data->display_line_total) // Reach end                                          if (line_current + screen_row_total - (screen_current_row - screen_begin_row) >= p_editor_data->display_line_total) // Reach end
719                                          {                                          {
720                                                  break;                                                  break;
721                                          }                                          }
722                                          line_current += (screen_line_total - 1) - (screen_current_line - screen_begin_line);                                          line_current += (screen_row_total - 1) - (screen_current_row - screen_begin_row);
723                                          if (line_current + screen_line_total > p_editor_data->display_line_total) // No enough lines to display                                          if (line_current + screen_row_total > p_editor_data->display_line_total) // No enough lines to display
724                                          {                                          {
725                                                  line_current = p_editor_data->display_line_total - screen_line_total;                                                  line_current = p_editor_data->display_line_total - screen_row_total;
726                                          }                                          }
727                                          screen_current_line = screen_begin_line;                                          screen_current_row = screen_begin_row;
728                                          screen_end_line = SCREEN_ROWS - 1;                                          screen_end_row = SCREEN_ROWS - 1;
729                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]));                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]));
730                                          clrline(screen_begin_line, SCREEN_ROWS);                                          clrline(screen_begin_row, SCREEN_ROWS);
731                                          break;                                          break;
732                                  case KEY_ESC:                                  case KEY_ESC:
733                                          break;                                          break;
# Line 677  int editor_display(EDITOR_DATA *p_editor Line 742  int editor_display(EDITOR_DATA *p_editor
742                                          show_help = 1;                                          show_help = 1;
743                                  case KEY_F5:                                  case KEY_F5:
744                                          // Refresh after display help information                                          // Refresh after display help information
745                                          line_current -= (screen_current_line - screen_begin_line);                                          line_current -= (screen_current_row - screen_begin_row);
746                                          screen_current_line = screen_begin_line;                                          screen_current_row = screen_begin_row;
747                                          screen_end_line = SCREEN_ROWS - 1;                                          screen_end_row = SCREEN_ROWS - 1;
748                                          clrline(screen_begin_line, SCREEN_ROWS);                                          clrline(screen_begin_row, SCREEN_ROWS);
749                                          break;                                          break;
750                                  case 0: // Refresh bottom line                                  case 0: // Refresh bottom line
751                                          break;                                          break;
# Line 710  int editor_display(EDITOR_DATA *p_editor Line 775  int editor_display(EDITOR_DATA *p_editor
775                  memcpy(buffer, (const char *)p_editor_data->p_display_lines[line_current], (size_t)len);                  memcpy(buffer, (const char *)p_editor_data->p_display_lines[line_current], (size_t)len);
776                  buffer[len] = '\0';                  buffer[len] = '\0';
777    
778                  moveto(screen_current_line, 0);                  moveto(screen_current_row, 0);
779                  clrtoeol();                  clrtoeol();
780                  prints("%s", buffer);                  prints("%s", buffer);
781                  line_current++;                  line_current++;
782                  screen_current_line++;                  screen_current_row++;
783          }          }
784    
785  cleanup:  cleanup:


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

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