summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2022-12-18 13:21:22 -0800
committerGreg Ercolano <erco@seriss.com>2022-12-18 13:21:22 -0800
commite7630e045ad3fb654d292e5be5a3af7cfe532c59 (patch)
tree456d8e5160a26581d413890b9e406b7d1f6b29b2 /src
parentb246b6650ab04cbdf3e258b5a75bf928fc46302c (diff)
Added ansi_show_unknown(bool) (default off)
It may be useful to some to have the terminal emit an error character to show unknown escape sequences. Off by default, unknown escape sequences are silently ignored. If enabled, '¿' is inserted instead.
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Simple_Terminal.cxx40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/Fl_Simple_Terminal.cxx b/src/Fl_Simple_Terminal.cxx
index 680b157dd..3f7ade3eb 100644
--- a/src/Fl_Simple_Terminal.cxx
+++ b/src/Fl_Simple_Terminal.cxx
@@ -287,7 +287,6 @@ void Fl_Simple_Terminal::vscroll_cb(Fl_Widget *w, void *data) {
Fl_Simple_Terminal::Fl_Simple_Terminal(int X,int Y,int W,int H,const char *l) : Fl_Text_Display(X,Y,W,H,l) {
history_lines_ = 500; // something 'reasonable'
stay_at_bottom_ = true;
- ansi_ = false;
lines_ = 0; // note: lines!=mNBufferLines when lines are wrapping
scrollaway_ = false;
scrolling_ = false;
@@ -312,6 +311,9 @@ Fl_Simple_Terminal::Fl_Simple_Terminal(int X,int Y,int W,int H,const char *l) :
normal_style_index_ = builtin_normal_index;
current_style_index_ = builtin_normal_index;
current_style_ = 'A' + 0;
+ // ANSI escape seq
+ ansi_ = false;
+ ansi_show_unknown_ = false;
// Intercept vertical scrolling
orig_vscroll_cb_ = mVScrollBar->callback();
orig_vscroll_data_ = mVScrollBar->user_data();
@@ -471,6 +473,23 @@ void Fl_Simple_Terminal::ansi(bool val) {
}
/**
+ See if we should show unknown ANSI sequences with '¿' or not.
+ \see ansi_show_unknown(bool)
+*/
+bool Fl_Simple_Terminal::ansi_show_unknown(void) const {
+ return ansi_show_unknown_;
+}
+
+/**
+ Enable showing unknown ESC sequences with the '¿' character.
+ By default this is off, and unknown escape sequences are silently ignored.
+ \see ansi_show_unknown()
+*/
+void Fl_Simple_Terminal::ansi_show_unknown(bool val) {
+ ansi_show_unknown_ = val;
+}
+
+/**
Return the current style table being used.
This is the value last passed as the 1st argument to
@@ -760,6 +779,16 @@ void Fl_Simple_Terminal::handle_backspace() {
backspace_buffer(1);
}
+// Handle unknown esc sequences
+void Fl_Simple_Terminal::unknown_escape() {
+ if ( ansi_show_unknown() ) {
+ for ( const char *s = "¿"; *s; s++ ) {
+ *ntp_++ = *s; // emit utf-8 encoded char
+ *nsp_++ = current_style(); // use current style
+ }
+ }
+}
+
/**
Handle appending string with ANSI escape sequences, and other 'special'
character processing (such as backspaces).
@@ -782,6 +811,7 @@ void Fl_Simple_Terminal::append_ansi(const char *s, int len) {
if ( escseq.parse_in_progress() ) { // ESC sequence in progress?
switch ( escseq.parse(*sp) ) { // parse until completed or fail
case Fl_Escape_Seq::fail: // parsing error?
+ unknown_escape();
escseq.reset(); // ..reset and continue
++sp;
continue;
@@ -801,10 +831,10 @@ void Fl_Simple_Terminal::append_ansi(const char *s, int len) {
case 'J': // ESC[#J
switch (val) {
case 0: // ESC[0J -- clear to eol
- // unsupported
+ unknown_escape();
break;
case 1: // ESC[1J -- clear to sol
- // unsupported
+ unknown_escape();
break;
case 2: // ESC[2J -- clear visible screen
// NOTE: Currently we clear the /entire screen history/, and
@@ -817,6 +847,9 @@ void Fl_Simple_Terminal::append_ansi(const char *s, int len) {
ntp_ = ntm_; // clear text contents accumulated so far
nsp_ = nsm_; // clear style contents ""
break;
+ default: // all other ESC[#J unsupported
+ unknown_escape();
+ break;
}
break;
// SELECT GRAPHIC RENDITION (SGR)
@@ -831,6 +864,7 @@ void Fl_Simple_Terminal::append_ansi(const char *s, int len) {
break;
// UNSUPPORTED MODES
default:
+ unknown_escape();
break; // unsupported
}
}