FLTK
Fl_Simple_Terminal.H
1 //
2 // A simple terminal widget for Fast Light Tool Kit (FLTK).
3 //
4 // Copyright 1998-2011 by Bill Spitzak and others.
5 // Copyright 2017 by Greg Ercolano.
6 //
7 // This library is free software. Distribution and use rights are outlined in
8 // the file "COPYING" which should have been included with this file. If this
9 // file is missing or damaged, see the license at:
10 //
11 // https://www.fltk.org/COPYING.php
12 //
13 // Please see the following page on how to report bugs and issues:
14 //
15 // https://www.fltk.org/bugs.php
16 //
17 
18 /* \file
19  Fl_Simple_Terminal widget . */
20 
21 #ifndef Fl_Simple_Terminal_H
22 #define Fl_Simple_Terminal_H
23 
24 #include "Fl_Export.H"
25 #include <FL/Fl_Text_Display.H>
26 
120 class FL_EXPORT Fl_Simple_Terminal : public Fl_Text_Display {
121 protected:
122  Fl_Text_Buffer *buf; // text buffer
123  Fl_Text_Buffer *sbuf; // style buffer
124 
125 private:
126  int history_lines_; // max lines allowed in screen history
127  bool stay_at_bottom_; // lets scroller chase last line in buffer
128  bool ansi_; // enables ANSI sequences
129  // scroll management
130  int lines; // #lines in buffer (optimization: Fl_Text_Buffer slow to calc this)
131  bool scrollaway; // true when user changed vscroll away from bottom
132  bool scrolling; // true while scroll callback active
133  // Fl_Text_Display vscrollbar's callback+data
134  Fl_Callback *orig_vscroll_cb;
135  void *orig_vscroll_data;
136  // Style table
137  const Fl_Text_Display::Style_Table_Entry *stable_; // the active style table
138  int stable_size_; // active style table size (in bytes)
139  int normal_style_index_; // "normal" style used by "\033[0m" reset sequence
140  int current_style_index_; // current style used for drawing text
141 
142 public:
143  Fl_Simple_Terminal(int X,int Y,int W,int H,const char *l=0);
145 
146  // Terminal options
147  void stay_at_bottom(bool);
148  bool stay_at_bottom() const;
149  void history_lines(int);
150  int history_lines() const;
151  void ansi(bool val);
152  bool ansi() const;
153  void style_table(Fl_Text_Display::Style_Table_Entry *stable, int stable_size, int normal_style_index=0);
154  const Fl_Text_Display::Style_Table_Entry *style_table() const;
155  int style_table_size() const;
156  void normal_style_index(int);
157  int normal_style_index() const;
158  void current_style_index(int);
159  int current_style_index() const;
160 
161  // Terminal text management
162  void append(const char *s, int len=-1);
163  void text(const char *s, int len=-1);
164  const char* text() const;
165  void printf(const char *fmt, ...);
166  void vprintf(const char *fmt, va_list ap);
167  void clear();
168  void remove_lines(int start, int count);
169 
170 private:
171  // Methods blocking public access to the subclass
172  // These are subclass methods that would give unexpected
173  // results if used. By making them private, we effectively
174  // "block" them.
175  //
176  // TODO: There are probably other Fl_Text_Display methods that
177  // need to be blocked.
178  //
179  void insert(const char*) { }
180 
181 protected:
182  // Fltk
183  virtual void draw();
184 
185  // Internal methods
186  void enforce_stay_at_bottom();
187  void enforce_history_lines();
188  void vscroll_cb2(Fl_Widget*, void*);
189  static void vscroll_cb(Fl_Widget*, void*);
190 };
191 
192 #endif
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:85
void() Fl_Callback(Fl_Widget *, void *)
Default callback type definition for all fltk widgets (by far the most used)
Definition: Fl_Widget.H:32
This structure associates the color, font, and font size of a string to draw with an attribute mask m...
Definition: Fl_Text_Display.H:144
This class manages Unicode text displayed in one or more Fl_Text_Display widgets. ...
Definition: Fl_Text_Buffer.H:196
void clear()
Deletes all child widgets from memory recursively.
Definition: Fl_Group.cxx:388
void insert(const char *text)
Inserts "text" at the current cursor location.
Definition: Fl_Text_Display.cxx:971
This is a continuous text scroll widget for logging and debugging output, much like a terminal...
Definition: Fl_Simple_Terminal.H:120
virtual void draw()
Draw the widget.
Definition: Fl_Text_Display.cxx:3726
Rich text display widget.
Definition: Fl_Text_Display.H:78