diff options
Diffstat (limited to 'FL')
| -rw-r--r-- | FL/Fl_Simple_Terminal.H | 64 |
1 files changed, 55 insertions, 9 deletions
diff --git a/FL/Fl_Simple_Terminal.H b/FL/Fl_Simple_Terminal.H index bee182bc4..10ed81bdb 100644 --- a/FL/Fl_Simple_Terminal.H +++ b/FL/Fl_Simple_Terminal.H @@ -123,21 +123,64 @@ protected: Fl_Text_Buffer *sbuf; // style buffer private: - int history_lines_; // max lines allowed in screen history + // Private class to handle parsing ESC sequences + // Holds all state information for parsing esc sequences, + // so sequences can span multiple block read(2) operations, etc. + // + class Fl_Escape_Seq { + public: + static const int maxbuf = 80; + static const int maxvals = 10; + // Return codes + static const int success = 0; // operation succeeded + static const int fail = -1; // operation failed + static const int completed = 1; // multi-step operation completed successfully + private: + char esc_mode_; // escape parsing mode state + char buf_[maxbuf]; // escape sequence being parsed + char *bufp_; // parsing ptr into buf[] + char *bufendp_; // end of buf[] (ptr to last valid buf char) + char *valbufp_; // pointer to first char in buf of integer being parsed + int vals_[maxvals]; // value array for parsing #'s in ESC[#;#;#.. + int vali_; // parsing index into vals_[], 0 if none + + int append_buf(char c); + int append_val(); + + public: + Fl_Escape_Seq(); + void reset(); + char esc_mode() const; + void esc_mode(char val); + int total_vals() const; + int val(int i) const; + bool parse_in_progress() const; + int parse(char c); + }; + +private: + int history_lines_; // max lines allowed in screen history bool stay_at_bottom_; // lets scroller chase last line in buffer bool ansi_; // enables ANSI sequences // scroll management - int lines; // #lines in buffer (optimization: Fl_Text_Buffer slow to calc this) - bool scrollaway; // true when user changed vscroll away from bottom - bool scrolling; // true while scroll callback active + int lines_; // #lines in buffer (optimization: Fl_Text_Buffer slow to calc this) + bool scrollaway_; // true when user changed vscroll away from bottom + bool scrolling_; // true while scroll callback active // Fl_Text_Display vscrollbar's callback+data - Fl_Callback *orig_vscroll_cb; - void *orig_vscroll_data; + Fl_Callback *orig_vscroll_cb_; + void *orig_vscroll_data_; // Style table const Fl_Text_Display::Style_Table_Entry *stable_; // the active style table - int stable_size_; // active style table size (in bytes) - int normal_style_index_; // "normal" style used by "\033[0m" reset sequence - int current_style_index_; // current style used for drawing text + int stable_size_; // active style table size (in bytes) + int normal_style_index_; // "normal" style used by "\033[0m" reset sequence + int current_style_index_; // current style used for drawing text + char current_style_; // current 'style char' (e.g. 'A' = first style entry) + Fl_Escape_Seq escseq; // escape sequence state handler + // 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 *ntp_; // new text ptr (ntp) - points into ntm buffer + char *nsm_; // new style memory (nsm) - malloc()ed by append() for output style + char *nsp_; // new style ptr (nsp) - points into nsm buffer public: Fl_Simple_Terminal(int X,int Y,int W,int H,const char *l=0); @@ -157,6 +200,7 @@ public: int normal_style_index() const; void current_style_index(int); int current_style_index() const; + int current_style() const; // Terminal text management void append(const char *s, int len=-1); @@ -188,6 +232,8 @@ protected: void vscroll_cb2(Fl_Widget*, void*); static void vscroll_cb(Fl_Widget*, void*); void backspace_buffer(unsigned int count); + void handle_backspace(); + void append_ansi(const char *s, int len); }; #endif |
