2222**
2323*******************************************************************************/
2424
25- /* *****************************************************************************/
26- // Defines
27- /* *****************************************************************************/
28- // Minimum number of characters present in the buffer before text sections are
29- // appended instead of replacing the whole field
30- #define TERM_SIZE_MIN_APPEND_TEXT 6
31-
3225/* *****************************************************************************/
3326// Include Files
3427/* *****************************************************************************/
3730#include < QRegularExpression>
3831#include < QDebug>
3932
33+ /* *****************************************************************************/
34+ // Constants
35+ /* *****************************************************************************/
36+ const QChar unicode_replacement_char = QChar(0xfffd );
37+
4038/* *****************************************************************************/
4139// Local Functions or Private Members
4240/* *****************************************************************************/
@@ -59,7 +57,6 @@ AutScrollEdit::AutScrollEdit(QWidget *parent) : QPlainTextEdit(parent)
5957 nItemArraySize = 0 ;
6058 mbSliderShown = false ;
6159 dat_out_updated = false ;
62- dat_in_prev_check_len = 0 ;
6360 dat_in_new_len = 0 ;
6461
6562 mstrDatIn.reserve (32768 );
@@ -883,7 +880,6 @@ void AutScrollEdit::clear_dat_in()
883880 // Clears the DatIn buffer
884881 mstrDatIn.clear ();
885882 mintPrevTextSize = 0 ;
886- dat_in_prev_check_len = 0 ;
887883 dat_in_new_len = 0 ;
888884 last_format = pre ;
889885
@@ -1021,15 +1017,14 @@ void AutScrollEdit::update_display()
10211017
10221018 if (vt100_control_mode == VT100_MODE_STRIP)
10231019 {
1024- AutEscape::strip_vt100_formatting (&mstrDatIn, dat_in_prev_check_len );
1020+ AutEscape::strip_vt100_formatting (&mstrDatIn, 0 );
10251021 }
10261022
10271023// TODO: deal with partial VT100 escape codes
10281024
1029- #if 1
10301025 // Replace unprintable characters with escape codes
10311026 int32_t i = mstrDatIn.length () - 1 ;
1032- while (i >= dat_in_prev_check_len )
1027+ while (i >= 0 )
10331028 {
10341029 uint8_t current = (uint8_t )mstrDatIn.at (i);
10351030
@@ -1044,17 +1039,30 @@ void AutScrollEdit::update_display()
10441039
10451040 --i;
10461041 }
1047- #endif
10481042
1049- if (dat_in_prev_check_len != mstrDatIn.length ())
1043+ if (mstrDatIn.length () > 0 )
10501044 {
1051- QString append_data = mstrDatIn. mid (dat_in_prev_check_len) ;
1045+ QString append_data = mstrDatIn;
10521046 QList<vt100_format_code> format;
10531047 int32_t end = 0 ;
10541048
1049+ // Check if we have unicode replacement characters, if so, wait for next chunk
1050+ i = append_data.length () - 1 ;
1051+ while (i >= 0 && append_data[i] == unicode_replacement_char && end < 3 )
1052+ {
1053+ ++end;
1054+ --i;
1055+ }
1056+
1057+ if (end > 0 )
1058+ {
1059+ cannot_parse_bytes += end;
1060+ append_data.remove ((append_data.length () - end), end);
1061+ }
1062+
10551063 if (vt100_control_mode == VT100_MODE_DECODE && vt100_process (&append_data, 0 , &format, &end) == false )
10561064 {
1057- cannot_parse_bytes = append_data.length () - end;
1065+ cannot_parse_bytes + = append_data.length () - end;
10581066 append_data.remove (end, (append_data.length () - end));
10591067 }
10601068
@@ -1186,7 +1194,7 @@ void AutScrollEdit::update_display()
11861194
11871195 // Update previous text size variables
11881196 mintPrevTextSize = dat_in_new_len;
1189- dat_in_prev_check_len = mstrDatIn.length () - cannot_parse_bytes;
1197+ mstrDatIn. remove ( 0 , ( mstrDatIn.length () - cannot_parse_bytes)) ;
11901198
11911199 // Update the cursor position
11921200 this ->update_cursor ();
0 commit comments