mirror of
https://github.com/fltk/fltk.git
synced 2026-05-28 20:06:18 +08:00
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.
This commit is contained in:
@@ -161,7 +161,6 @@ private:
|
|||||||
private:
|
private:
|
||||||
int history_lines_; // max lines allowed in screen history
|
int history_lines_; // max lines allowed in screen history
|
||||||
bool stay_at_bottom_; // lets scroller chase last line in buffer
|
bool stay_at_bottom_; // lets scroller chase last line in buffer
|
||||||
bool ansi_; // enables ANSI sequences
|
|
||||||
// scroll management
|
// scroll management
|
||||||
int lines_; // #lines in buffer (optimization: Fl_Text_Buffer slow to calc this)
|
int lines_; // #lines in buffer (optimization: Fl_Text_Buffer slow to calc this)
|
||||||
bool scrollaway_; // true when user changed vscroll away from bottom
|
bool scrollaway_; // true when user changed vscroll away from bottom
|
||||||
@@ -175,7 +174,10 @@ private:
|
|||||||
int normal_style_index_; // "normal" style used by "\033[0m" reset sequence
|
int normal_style_index_; // "normal" style used by "\033[0m" reset sequence
|
||||||
int current_style_index_; // current style used for drawing text
|
int current_style_index_; // current style used for drawing text
|
||||||
char current_style_; // current 'style char' (e.g. 'A' = first style entry)
|
char current_style_; // current 'style char' (e.g. 'A' = first style entry)
|
||||||
|
// ANSI escape seq
|
||||||
Fl_Escape_Seq escseq; // escape sequence state handler
|
Fl_Escape_Seq escseq; // escape sequence state handler
|
||||||
|
bool ansi_; // enables ANSI sequences
|
||||||
|
bool ansi_show_unknown_; // show '¿' for unknown ESC sequences (default: off)
|
||||||
// String parsing vars initialized/used by append(), used by handle_backspace() etc.
|
// String parsing vars initialized/used by append(), used by handle_backspace() etc.
|
||||||
char *ntm_; // new text memory (ntm) - malloc()ed by append() for output text
|
char *ntm_; // new text memory (ntm) - malloc()ed by append() for output text
|
||||||
char *ntp_; // new text ptr (ntp) - points into ntm buffer
|
char *ntp_; // new text ptr (ntp) - points into ntm buffer
|
||||||
@@ -193,6 +195,8 @@ public:
|
|||||||
int history_lines() const;
|
int history_lines() const;
|
||||||
void ansi(bool val);
|
void ansi(bool val);
|
||||||
bool ansi() const;
|
bool ansi() const;
|
||||||
|
void ansi_show_unknown(bool val);
|
||||||
|
bool ansi_show_unknown() const;
|
||||||
void style_table(Fl_Text_Display::Style_Table_Entry *stable, int stable_size, int normal_style_index=0);
|
void style_table(Fl_Text_Display::Style_Table_Entry *stable, int stable_size, int normal_style_index=0);
|
||||||
const Fl_Text_Display::Style_Table_Entry *style_table() const;
|
const Fl_Text_Display::Style_Table_Entry *style_table() const;
|
||||||
int style_table_size() const;
|
int style_table_size() const;
|
||||||
@@ -234,6 +238,7 @@ protected:
|
|||||||
void backspace_buffer(unsigned int count);
|
void backspace_buffer(unsigned int count);
|
||||||
void handle_backspace();
|
void handle_backspace();
|
||||||
void append_ansi(const char *s, int len);
|
void append_ansi(const char *s, int len);
|
||||||
|
void unknown_escape();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -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) {
|
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'
|
history_lines_ = 500; // something 'reasonable'
|
||||||
stay_at_bottom_ = true;
|
stay_at_bottom_ = true;
|
||||||
ansi_ = false;
|
|
||||||
lines_ = 0; // note: lines!=mNBufferLines when lines are wrapping
|
lines_ = 0; // note: lines!=mNBufferLines when lines are wrapping
|
||||||
scrollaway_ = false;
|
scrollaway_ = false;
|
||||||
scrolling_ = 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;
|
normal_style_index_ = builtin_normal_index;
|
||||||
current_style_index_ = builtin_normal_index;
|
current_style_index_ = builtin_normal_index;
|
||||||
current_style_ = 'A' + 0;
|
current_style_ = 'A' + 0;
|
||||||
|
// ANSI escape seq
|
||||||
|
ansi_ = false;
|
||||||
|
ansi_show_unknown_ = false;
|
||||||
// Intercept vertical scrolling
|
// Intercept vertical scrolling
|
||||||
orig_vscroll_cb_ = mVScrollBar->callback();
|
orig_vscroll_cb_ = mVScrollBar->callback();
|
||||||
orig_vscroll_data_ = mVScrollBar->user_data();
|
orig_vscroll_data_ = mVScrollBar->user_data();
|
||||||
@@ -470,6 +472,23 @@ void Fl_Simple_Terminal::ansi(bool val) {
|
|||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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.
|
Return the current style table being used.
|
||||||
|
|
||||||
@@ -760,6 +779,16 @@ void Fl_Simple_Terminal::handle_backspace() {
|
|||||||
backspace_buffer(1);
|
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'
|
Handle appending string with ANSI escape sequences, and other 'special'
|
||||||
character processing (such as backspaces).
|
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?
|
if ( escseq.parse_in_progress() ) { // ESC sequence in progress?
|
||||||
switch ( escseq.parse(*sp) ) { // parse until completed or fail
|
switch ( escseq.parse(*sp) ) { // parse until completed or fail
|
||||||
case Fl_Escape_Seq::fail: // parsing error?
|
case Fl_Escape_Seq::fail: // parsing error?
|
||||||
|
unknown_escape();
|
||||||
escseq.reset(); // ..reset and continue
|
escseq.reset(); // ..reset and continue
|
||||||
++sp;
|
++sp;
|
||||||
continue;
|
continue;
|
||||||
@@ -801,10 +831,10 @@ void Fl_Simple_Terminal::append_ansi(const char *s, int len) {
|
|||||||
case 'J': // ESC[#J
|
case 'J': // ESC[#J
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case 0: // ESC[0J -- clear to eol
|
case 0: // ESC[0J -- clear to eol
|
||||||
// unsupported
|
unknown_escape();
|
||||||
break;
|
break;
|
||||||
case 1: // ESC[1J -- clear to sol
|
case 1: // ESC[1J -- clear to sol
|
||||||
// unsupported
|
unknown_escape();
|
||||||
break;
|
break;
|
||||||
case 2: // ESC[2J -- clear visible screen
|
case 2: // ESC[2J -- clear visible screen
|
||||||
// NOTE: Currently we clear the /entire screen history/, and
|
// 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
|
ntp_ = ntm_; // clear text contents accumulated so far
|
||||||
nsp_ = nsm_; // clear style contents ""
|
nsp_ = nsm_; // clear style contents ""
|
||||||
break;
|
break;
|
||||||
|
default: // all other ESC[#J unsupported
|
||||||
|
unknown_escape();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// SELECT GRAPHIC RENDITION (SGR)
|
// SELECT GRAPHIC RENDITION (SGR)
|
||||||
@@ -831,6 +864,7 @@ void Fl_Simple_Terminal::append_ansi(const char *s, int len) {
|
|||||||
break;
|
break;
|
||||||
// UNSUPPORTED MODES
|
// UNSUPPORTED MODES
|
||||||
default:
|
default:
|
||||||
|
unknown_escape();
|
||||||
break; // unsupported
|
break; // unsupported
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user