FLTK 1.4.0
Fl_Simple_Terminal Class Reference

This is a continuous text scroll widget for logging and debugging output, much like a terminal. More...

#include <Fl_Simple_Terminal.H>

Inheritance diagram for Fl_Simple_Terminal:
Fl_Text_Display Fl_Group Fl_Widget

Public Member Functions

bool ansi () const
 Get the state of the ANSI flag which enables/disables the handling of ANSI sequences in text. More...
 
void ansi (bool val)
 Enable/disable support of ANSI sequences like "\033[31m", which sets the color/font/weight/size of any text that follows. More...
 
void append (const char *s, int len=-1)
 Appends new string 's' to terminal. More...
 
void clear ()
 Clears the terminal's screen and history. More...
 
int current_style_index () const
 Get the style table index used as the current drawing color/font/weight/size for new text. More...
 
void current_style_index (int)
 Set the style table index used as the current drawing color/font/weight/size for new text. More...
 
 Fl_Simple_Terminal (int X, int Y, int W, int H, const char *l=0)
 Creates a new Fl_Simple_Terminal widget that can be a child of other FLTK widgets.
 
int history_lines () const
 Get the maximum number of terminal history lines last set by history_lines(int). More...
 
void history_lines (int)
 Sets the maximum number of lines for the terminal history. More...
 
int normal_style_index () const
 Gets the style table index used by the ANSI terminal reset sequence "\033[0m". More...
 
void normal_style_index (int)
 Sets the style table index used by the ANSI terminal reset sequence "\033[0m", which resets the current drawing color/font/weight/size to "normal". More...
 
void printf (const char *fmt,...)
 Appends printf formatted messages to the terminal. More...
 
void remove_lines (int start, int count)
 Remove the specified range of lines from the terminal, starting with line 'start' and removing 'count' lines. More...
 
bool stay_at_bottom () const
 Gets the current value of the stay_at_bottom(bool) flag. More...
 
void stay_at_bottom (bool)
 Configure the terminal to remain scrolled to the bottom when possible, chasing the end of the buffer whenever new text is added. More...
 
const Fl_Text_Display::Style_Table_Entrystyle_table () const
 Return the current style table being used. More...
 
void style_table (Fl_Text_Display::Style_Table_Entry *stable, int stable_size, int normal_style_index=0)
 Set a user defined style table, which controls the font colors, faces, weights and sizes available for the terminal's text content. More...
 
int style_table_size () const
 Return the current style table's size (in bytes). More...
 
const char * text () const
 Returns entire text content of the terminal as a single string. More...
 
void text (const char *s, int len=-1)
 Replaces the terminal with new text content in string 's'. More...
 
void vprintf (const char *fmt, va_list ap)
 Appends printf formatted messages to the terminal. More...
 
 ~Fl_Simple_Terminal ()
 Destructor for this widget; removes any internal allocations for the terminal, including text buffer, style buffer, etc.
 
- Public Member Functions inherited from Fl_Text_Display
Fl_Text_Bufferbuffer () const
 Gets the current text buffer associated with the text widget. More...
 
void buffer (Fl_Text_Buffer &buf)
 Sets the current text buffer associated with the text widget. More...
 
void buffer (Fl_Text_Buffer *buf)
 Attach a text buffer to display, replacing the current buffer (if any). More...
 
double col_to_x (double col) const
 Convert a column number into an x pixel position. More...
 
int count_lines (int start, int end, bool start_pos_is_line_start) const
 Count the number of lines between two positions. More...
 
Fl_Color cursor_color () const
 Gets the text cursor color. More...
 
void cursor_color (Fl_Color n)
 Sets the text cursor color. More...
 
int cursor_style () const
 
void cursor_style (int style)
 Sets the text cursor style. More...
 
 Fl_Text_Display (int X, int Y, int W, int H, const char *l=0)
 Creates a new text display widget. More...
 
Fl_Color grammar_underline_color () const
 Gets the underline color for style attribute ATTR_GRAMMAR. More...
 
void grammar_underline_color (Fl_Color color)
 Sets the underline color for style attribute ATTR_GRAMMAR. More...
 
virtual int handle (int e)
 Event handling.
 
void hide_cursor ()
 Hides the text cursor.
 
void highlight_data (Fl_Text_Buffer *styleBuffer, const Style_Table_Entry *styleTable, int nStyles, char unfinishedStyle, Unfinished_Style_Cb unfinishedHighlightCB, void *cbArg)
 Attach (or remove) highlight information in text display and redisplay. More...
 
int in_selection (int x, int y) const
 Check if a pixel position is within the primary selection. More...
 
void insert (const char *text)
 Inserts "text" at the current cursor location. More...
 
int insert_position () const
 Gets the position of the text insertion cursor for text display. More...
 
void insert_position (int newPos)
 Sets the position of the text insertion cursor for text display. More...
 
int line_end (int startPos, bool startPosIsLineStart) const
 Returns the end of a line. More...
 
int line_start (int pos) const
 Return the beginning of a line. More...
 
Fl_Align linenumber_align () const
 Returns the alignment used for line numbers (if enabled).
 
void linenumber_align (Fl_Align val)
 Set alignment for line numbers (if enabled). More...
 
Fl_Color linenumber_bgcolor () const
 Returns the background color used for line numbers (if enabled).
 
void linenumber_bgcolor (Fl_Color val)
 Set the background color used for line numbers (if enabled). More...
 
Fl_Color linenumber_fgcolor () const
 Return the foreground color used for line numbers (if enabled).
 
void linenumber_fgcolor (Fl_Color val)
 Set the foreground color used for line numbers (if enabled). More...
 
Fl_Font linenumber_font () const
 Return the font used for line numbers (if enabled).
 
void linenumber_font (Fl_Font val)
 Set the font used for line numbers (if enabled). More...
 
const char * linenumber_format () const
 Returns the line number printf() format string.
 
void linenumber_format (const char *val)
 Sets the printf() style format string used for line numbers. More...
 
Fl_Fontsize linenumber_size () const
 Return the font size used for line numbers (if enabled).
 
void linenumber_size (Fl_Fontsize val)
 Set the font size used for line numbers (if enabled). More...
 
int linenumber_width () const
 Return the screen area width provided for line numbers.
 
void linenumber_width (int width)
 Set width of screen area for line numbers. More...
 
int move_down ()
 Moves the current insert position down one line. More...
 
int move_left ()
 Moves the current insert position left one character. More...
 
int move_right ()
 Moves the current insert position right one character. More...
 
int move_up ()
 Moves the current insert position up one line. More...
 
void next_word (void)
 Moves the current insert position right one word.
 
void overstrike (const char *text)
 Replaces text at the current insert position. More...
 
int position_style (int lineStartPos, int lineLen, int lineIndex) const
 Find the correct style for a character. More...
 
int position_to_xy (int pos, int *x, int *y) const
 Convert a character index into a pixel position. More...
 
void previous_word (void)
 Moves the current insert position left one word.
 
virtual void recalc_display ()
 Recalculate the display's visible lines and scrollbar sizes.
 
void redisplay_range (int start, int end)
 Marks text from start to end as needing a redraw. More...
 
virtual void resize (int X, int Y, int W, int H)
 Change the size of the displayed text area. More...
 
int rewind_lines (int startPos, int nLines)
 Skip a number of lines back. More...
 
void scroll (int topLineNum, int horizOffset)
 Scrolls the current buffer to start at the specified line and column. More...
 
Fl_Align scrollbar_align () const
 Gets the scrollbar alignment type. More...
 
void scrollbar_align (Fl_Align a)
 Sets the scrollbar alignment type. More...
 
int scrollbar_size () const
 Gets the current size of the scrollbars' troughs, in pixels. More...
 
void scrollbar_size (int newSize)
 Sets the pixel size of the scrollbars' troughs to newSize, in pixels. More...
 
int scrollbar_width () const
 Returns the global value Fl::scrollbar_size() unless a specific scrollbar_width_ has been set. More...
 
void scrollbar_width (int width)
 Sets the global Fl::scrollbar_size(), and forces this instance of the widget to use it. More...
 
Fl_Color secondary_selection_color () const
 Gets the background color for the secondary selection block. More...
 
void secondary_selection_color (Fl_Color color)
 Sets the background color for the secondary selection block. More...
 
int shortcut () const
 
void shortcut (int s)
 
void show_cursor (int b=1)
 Shows the text cursor. More...
 
void show_insert_position ()
 Scrolls the text buffer to show the current insert position. More...
 
int skip_lines (int startPos, int nLines, bool startPosIsLineStart)
 Skip a number of lines forward. More...
 
Fl_Color spelling_underline_color () const
 Gets the underline color for style attribute ATTR_SPELLING. More...
 
void spelling_underline_color (Fl_Color color)
 Sets the underline color for style attribute ATTR_SPELLING. More...
 
Fl_Text_Bufferstyle_buffer () const
 Gets the current style buffer associated with the text widget. More...
 
Fl_Color textcolor () const
 Gets the default color of text in the widget. More...
 
void textcolor (Fl_Color n)
 Sets the default color of text in the widget. More...
 
Fl_Font textfont () const
 Gets the default font used when drawing text in the widget. More...
 
void textfont (Fl_Font s)
 Sets the default font used when drawing text in the widget. More...
 
Fl_Fontsize textsize () const
 Gets the default size of text in the widget. More...
 
void textsize (Fl_Fontsize s)
 Sets the default size of text in the widget. More...
 
int word_end (int pos) const
 Moves the insert position to the end of the current word. More...
 
int word_start (int pos) const
 Moves the insert position to the beginning of the current word. More...
 
void wrap_mode (int wrap, int wrap_margin)
 Set the new text wrap mode. More...
 
int wrapped_column (int row, int column) const
 Nobody knows what this function does. More...
 
int wrapped_row (int row) const
 Nobody knows what this function does. More...
 
double x_to_col (double x) const
 Convert an x pixel position into a column number. More...
 
 ~Fl_Text_Display ()
 Free a text display and release its associated memory. More...
 
- Public Member Functions inherited from Fl_Group
Fl_Widget *& _ddfdesign_kludge ()
 This is for forms compatibility only.
 
void add (Fl_Widget &)
 The widget is removed from its current group (if any) and then added to the end of this group.
 
void add (Fl_Widget *o)
 See void Fl_Group::add(Fl_Widget &w)
 
void add_resizable (Fl_Widget &o)
 Adds a widget to the group and makes it the resizable widget.
 
Fl_Widget *const * array () const
 Returns a pointer to the array of children. More...
 
virtual Fl_Groupas_group ()
 Returns an Fl_Group pointer if this widget is an Fl_Group. More...
 
void begin ()
 Sets the current group so you can build the widget tree by just constructing the widgets. More...
 
Fl_Widgetchild (int n) const
 Returns array()[n]. More...
 
int children () const
 Returns how many child widgets the group has.
 
void clear ()
 Deletes all child widgets from memory recursively. More...
 
unsigned int clip_children ()
 Returns the current clipping mode. More...
 
void clip_children (int c)
 Controls whether the group widget clips the drawing of child widgets to its bounding box. More...
 
virtual int delete_child (int n)
 Removes the widget at index from the group and deletes it. More...
 
void end ()
 Exactly the same as current(this->parent()). More...
 
int find (const Fl_Widget &o) const
 See int Fl_Group::find(const Fl_Widget *w) const.
 
int find (const Fl_Widget *) const
 Searches the child array for the widget and returns the index. More...
 
 Fl_Group (int, int, int, int, const char *=0)
 Creates a new Fl_Group widget using the given position, size, and label string. More...
 
void focus (Fl_Widget *W)
 
void forms_end ()
 This is for forms compatibility only.
 
void init_sizes ()
 Resets the internal array of widget sizes and positions. More...
 
void insert (Fl_Widget &, int i)
 The widget is removed from its current group (if any) and then inserted into this group. More...
 
void insert (Fl_Widget &o, Fl_Widget *before)
 This does insert(w, find(before)). More...
 
void remove (Fl_Widget &)
 Removes a widget from the group but does not delete it. More...
 
void remove (Fl_Widget *o)
 Removes the widget o from the group. More...
 
void remove (int index)
 Removes the widget at index from the group but does not delete it. More...
 
Fl_Widgetresizable () const
 Returns the group's resizable widget. More...
 
void resizable (Fl_Widget &o)
 Sets the group's resizable widget. More...
 
void resizable (Fl_Widget *o)
 The resizable widget defines both the resizing box and the resizing behavior of the group and its children. More...
 
virtual ~Fl_Group ()
 The destructor also deletes all the children. More...
 
- Public Member Functions inherited from Fl_Widget
void _clear_fullscreen ()
 
void _set_fullscreen ()
 
void activate ()
 Activates the widget. More...
 
unsigned int active () const
 Returns whether the widget is active. More...
 
int active_r () const
 Returns whether the widget and all of its parents are active. More...
 
Fl_Align align () const
 Gets the label alignment. More...
 
void align (Fl_Align alignment)
 Sets the label alignment. More...
 
long argument () const
 Gets the current user data (long) argument that is passed to the callback function. More...
 
void argument (long v)
 Sets the current user data (long) argument that is passed to the callback function. More...
 
virtual class Fl_Gl_Windowas_gl_window ()
 Returns an Fl_Gl_Window pointer if this widget is an Fl_Gl_Window. More...
 
virtual Fl_Windowas_window ()
 Returns an Fl_Window pointer if this widget is an Fl_Window. More...
 
Fl_Boxtype box () const
 Gets the box type of the widget. More...
 
void box (Fl_Boxtype new_box)
 Sets the box type for the widget. More...
 
Fl_Callback_p callback () const
 Gets the current callback function for the widget. More...
 
void callback (Fl_Callback *cb)
 Sets the current callback function for the widget. More...
 
void callback (Fl_Callback *cb, void *p)
 Sets the current callback function for the widget. More...
 
void callback (Fl_Callback0 *cb)
 Sets the current callback function for the widget. More...
 
void callback (Fl_Callback1 *cb, long p=0)
 Sets the current callback function for the widget. More...
 
unsigned int changed () const
 Checks if the widget value changed since the last callback. More...
 
void clear_active ()
 Marks the widget as inactive without sending events or changing focus. More...
 
void clear_changed ()
 Marks the value of the widget as unchanged. More...
 
void clear_damage (uchar c=0)
 Clears or sets the damage flags. More...
 
void clear_output ()
 Sets a widget to accept input. More...
 
void clear_visible ()
 Hides the widget. More...
 
void clear_visible_focus ()
 Disables keyboard focus navigation with this widget. More...
 
Fl_Color color () const
 Gets the background color of the widget. More...
 
void color (Fl_Color bg)
 Sets the background color of the widget. More...
 
void color (Fl_Color bg, Fl_Color sel)
 Sets the background and selection color of the widget. More...
 
Fl_Color color2 () const
 For back compatibility only. More...
 
void color2 (unsigned a)
 For back compatibility only. More...
 
int contains (const Fl_Widget *w) const
 Checks if w is a child of this widget. More...
 
void copy_label (const char *new_label)
 Sets the current label. More...
 
void copy_tooltip (const char *text)
 Sets the current tooltip text. More...
 
uchar damage () const
 Returns non-zero if draw() needs to be called. More...
 
void damage (uchar c)
 Sets the damage bits for the widget. More...
 
void damage (uchar c, int x, int y, int w, int h)
 Sets the damage bits for an area inside the widget. More...
 
int damage_resize (int, int, int, int)
 Internal use only.
 
void deactivate ()
 Deactivates the widget. More...
 
Fl_Imagedeimage ()
 Gets the image that is used as part of the widget label when in the inactive state. More...
 
const Fl_Imagedeimage () const
 Gets the image that is used as part of the widget label when in the inactive state. More...
 
void deimage (Fl_Image &img)
 Sets the image to use as part of the widget label when in the inactive state. More...
 
void deimage (Fl_Image *img)
 Sets the image to use as part of the widget label when in the inactive state. More...
 
void do_callback ()
 Calls the widget callback function with default arguments. More...
 
void do_callback (Fl_Widget *widget, long arg)
 Calls the widget callback function with arbitrary arguments. More...
 
void do_callback (Fl_Widget *widget, void *arg=0)
 Calls the widget callback function with arbitrary arguments. More...
 
void draw_label (int, int, int, int, Fl_Align) const
 Draws the label in an arbitrary bounding box with an arbitrary alignment. More...
 
int h () const
 Gets the widget height. More...
 
virtual void hide ()
 Makes a widget invisible. More...
 
Fl_Imageimage ()
 Gets the image that is used as part of the widget label when in the active state. More...
 
const Fl_Imageimage () const
 Gets the image that is used as part of the widget label when in the active state. More...
 
void image (Fl_Image &img)
 Sets the image to use as part of the widget label when in the active state. More...
 
void image (Fl_Image *img)
 Sets the image to use as part of the widget label when in the active state. More...
 
int inside (const Fl_Widget *wgt) const
 Checks if this widget is a child of wgt. More...
 
int is_label_copied () const
 Returns whether the current label was assigned with copy_label(). More...
 
const char * label () const
 Gets the current label text. More...
 
void label (const char *text)
 Sets the current label pointer. More...
 
void label (Fl_Labeltype a, const char *b)
 Shortcut to set the label text and type in one call. More...
 
Fl_Color labelcolor () const
 Gets the label color. More...
 
void labelcolor (Fl_Color c)
 Sets the label color. More...
 
Fl_Font labelfont () const
 Gets the font to use. More...
 
void labelfont (Fl_Font f)
 Sets the font to use. More...
 
Fl_Fontsize labelsize () const
 Gets the font size in pixels. More...
 
void labelsize (Fl_Fontsize pix)
 Sets the font size in pixels. More...
 
Fl_Labeltype labeltype () const
 Gets the label type. More...
 
void labeltype (Fl_Labeltype a)
 Sets the label type. More...
 
void measure_label (int &ww, int &hh) const
 Sets width ww and height hh accordingly with the label size. More...
 
unsigned int output () const
 Returns if a widget is used for output only. More...
 
Fl_Groupparent () const
 Returns a pointer to the parent widget. More...
 
void parent (Fl_Group *p)
 Internal use only - "for hacks only". More...
 
void position (int X, int Y)
 Repositions the window or widget. More...
 
void redraw ()
 Schedules the drawing of the widget. More...
 
void redraw_label ()
 Schedules the drawing of the label. More...
 
Fl_Color selection_color () const
 Gets the selection color. More...
 
void selection_color (Fl_Color a)
 Sets the selection color. More...
 
void set_active ()
 Marks the widget as active without sending events or changing focus. More...
 
void set_changed ()
 Marks the value of the widget as changed. More...
 
void set_output ()
 Sets a widget to output only. More...
 
void set_visible ()
 Makes the widget visible. More...
 
void set_visible_focus ()
 Enables keyboard focus navigation with this widget. More...
 
int shortcut_label () const
 Returns whether the widget's label uses '&' to indicate shortcuts. More...
 
void shortcut_label (int value)
 Sets whether the widget's label uses '&' to indicate shortcuts. More...
 
virtual void show ()
 Makes a widget visible. More...
 
void size (int W, int H)
 Changes the size of the widget. More...
 
int take_focus ()
 Gives the widget the keyboard focus. More...
 
unsigned int takesevents () const
 Returns if the widget is able to take events. More...
 
int test_shortcut ()
 Returns true if the widget's label contains the entered '&x' shortcut. More...
 
const char * tooltip () const
 Gets the current tooltip text. More...
 
void tooltip (const char *text)
 Sets the current tooltip text. More...
 
Fl_Windowtop_window () const
 Returns a pointer to the top-level window for the widget. More...
 
Fl_Windowtop_window_offset (int &xoff, int &yoff) const
 Finds the x/y offset of the current widget relative to the top-level window. More...
 
uchar type () const
 Gets the widget type. More...
 
void type (uchar t)
 Sets the widget type. More...
 
int use_accents_menu ()
 Returns non zero if MAC_USE_ACCENTS_MENU flag is set, 0 otherwise.
 
void * user_data () const
 Gets the user data for this widget. More...
 
void user_data (void *v)
 Sets the user data for this widget. More...
 
unsigned int visible () const
 Returns whether a widget is visible. More...
 
unsigned int visible_focus () const
 Checks whether this widget has a visible focus. More...
 
void visible_focus (int v)
 Modifies keyboard focus navigation. More...
 
int visible_r () const
 Returns whether a widget and all its parents are visible. More...
 
int w () const
 Gets the widget width. More...
 
Fl_When when () const
 Returns the conditions under which the callback is called. More...
 
void when (uchar i)
 Sets the flags used to decide when a callback is called. More...
 
Fl_Windowwindow () const
 Returns a pointer to the nearest parent window up the widget hierarchy. More...
 
int x () const
 Gets the widget position in its window. More...
 
int y () const
 Gets the widget position in its window. More...
 
virtual ~Fl_Widget ()
 Destroys the widget. More...
 

Protected Member Functions

virtual void draw ()
 Draws the widget, including a cursor at the end of the buffer. More...
 
void enforce_history_lines ()
 Enforce 'history_lines' limit on the history buffer by trimming off lines from the top of the buffer. More...
 
void enforce_stay_at_bottom ()
 Scroll to last line unless someone has manually scrolled the vertical scrollbar away from the bottom. More...
 
void vscroll_cb2 (Fl_Widget *, void *)
 
- Protected Member Functions inherited from Fl_Text_Display
void absolute_top_line_number (int oldFirstChar)
 Re-calculate absolute top line number for a change in scroll position. More...
 
void calc_last_char ()
 Update last display character index. More...
 
void calc_line_starts (int startLine, int endLine)
 Update the line starts array. More...
 
void clear_rect (int style, int x, int y, int width, int height) const
 Clear a rectangle with the appropriate background color for style. More...
 
void display_insert ()
 Scroll the display to bring insertion cursor into view. More...
 
void draw_cursor (int, int)
 Draw a cursor with top center at X, Y. More...
 
void draw_line_numbers (bool clearAll)
 Refresh the line number area. More...
 
void draw_range (int start, int end)
 Draw a range of text. More...
 
void draw_string (int style, int x, int y, int toX, const char *string, int nChars) const
 Draw a text segment in a single style. More...
 
void draw_text (int X, int Y, int W, int H)
 Refresh a rectangle of the text display. More...
 
void draw_vline (int visLineNum, int leftClip, int rightClip, int leftCharIndex, int rightCharIndex)
 Draw a single line of text. More...
 
int empty_vlines () const
 Return true if there are lines visible with no corresponding buffer text. More...
 
void extend_range_for_styles (int *start, int *end)
 I don't know what this does! More...
 
void find_line_end (int pos, bool start_pos_is_line_start, int *lineEnd, int *nextLineStart) const
 Finds both the end of the current line and the start of the next line. More...
 
void find_wrap_range (const char *deletedText, int pos, int nInserted, int nDeleted, int *modRangeStart, int *modRangeEnd, int *linesInserted, int *linesDeleted)
 Wrapping calculations. More...
 
int find_x (const char *s, int len, int style, int x) const
 Find the index of the character that lies at the given x position / closest cursor position. More...
 
int get_absolute_top_line_number () const
 Returns the absolute (non-wrapped) line number of the first line displayed. More...
 
int handle_vline (int mode, int lineStart, int lineLen, int leftChar, int rightChar, int topClip, int bottomClip, int leftClip, int rightClip) const
 Universal pixel machine. More...
 
int longest_vline () const
 Find the longest line of all visible lines. More...
 
void maintain_absolute_top_line_number (int state)
 Line numbering stuff, currently unused. More...
 
int maintaining_absolute_top_line_number () const
 Returns true if a separate absolute top line number is being maintained. More...
 
void measure_deleted_lines (int pos, int nDeleted)
 Wrapping calculations. More...
 
double measure_proportional_character (const char *s, int colNum, int pos) const
 Wrapping calculations. More...
 
int measure_vline (int visLineNum) const
 Returns the width in pixels of the displayed line pointed to by "visLineNum". More...
 
void offset_line_starts (int newTopLineNum)
 Offset line start counters for a new vertical scroll position. More...
 
int position_to_line (int pos, int *lineNum) const
 Convert a position index into a line number offset. More...
 
int position_to_linecol (int pos, int *lineNum, int *column) const
 Find the line and column number of position pos. More...
 
void reset_absolute_top_line_number ()
 Reestablish the absolute (non-wrapped) top line number. More...
 
int scroll_ (int topLineNum, int horizOffset)
 Scrolls the current buffer to start at the specified line and column. More...
 
double string_width (const char *string, int length, int style) const
 Find the width of a string in the font of a particular style. More...
 
void update_h_scrollbar ()
 Update horizontal scrollbar. More...
 
void update_line_starts (int pos, int charsInserted, int charsDeleted, int linesInserted, int linesDeleted, int *scrolled)
 Update line start arrays and variables. More...
 
void update_v_scrollbar ()
 Update vertical scrollbar. More...
 
int vline_length (int visLineNum) const
 Count number of bytes in a visible line. More...
 
int wrap_uses_character (int lineEndPos) const
 Check if the line break is caused by a newline or by line wrapping. More...
 
void wrapped_line_counter (Fl_Text_Buffer *buf, int startPos, int maxPos, int maxLines, bool startPosIsLineStart, int styleBufOffset, int *retPos, int *retLines, int *retLineStart, int *retLineEnd, bool countLastLineMissingNewLine=true) const
 Wrapping calculations. More...
 
int xy_to_position (int x, int y, int PosType=CHARACTER_POS) const
 Translate a pixel position into a character index. More...
 
void xy_to_rowcol (int x, int y, int *row, int *column, int PosType=CHARACTER_POS) const
 Translate pixel coordinates into row and column. More...
 
- Protected Member Functions inherited from Fl_Group
Fl_Rectbounds ()
 Returns the internal array of widget sizes and positions. More...
 
void draw_child (Fl_Widget &widget) const
 Forces a child to redraw. More...
 
void draw_children ()
 Draws all children of the group. More...
 
void draw_outside_label (const Fl_Widget &widget) const
 Parents normally call this to draw outside labels of child widgets.
 
int * sizes ()
 Returns the internal array of widget sizes and positions. More...
 
void update_child (Fl_Widget &widget) const
 Draws a child only if it needs it. More...
 
- Protected Member Functions inherited from Fl_Widget
void clear_flag (unsigned int c)
 Clears a flag in the flags mask.
 
void draw_backdrop () const
 If FL_ALIGN_IMAGE_BACKDROP is set, the image or deimage will be drawn.
 
void draw_box () const
 Draws the widget box according its box style.
 
void draw_box (Fl_Boxtype t, Fl_Color c) const
 Draws a box of type t, of color c at the widget's position and size.
 
void draw_box (Fl_Boxtype t, int x, int y, int w, int h, Fl_Color c) const
 Draws a box of type t, of color c at the position X,Y and size W,H.
 
void draw_focus () const
 Draws a focus rectangle around the widget. More...
 
void draw_focus (Fl_Boxtype t, int X, int Y, int W, int H) const
 Draws a focus rectangle around the widget. More...
 
void draw_focus (Fl_Boxtype t, int x, int y, int w, int h, Fl_Color bg) const
 Draws a focus box for the widget at the given position and size. More...
 
void draw_label () const
 Draws the widget's label at the defined label position. More...
 
void draw_label (int, int, int, int) const
 Draws the label in an arbitrary bounding box. More...
 
 Fl_Widget (int x, int y, int w, int h, const char *label=0L)
 Creates a widget at the given position and size. More...
 
unsigned int flags () const
 Gets the widget flags mask.
 
void h (int v)
 Internal use only. More...
 
void set_flag (unsigned int c)
 Sets a flag in the flags mask.
 
void w (int v)
 Internal use only. More...
 
void x (int v)
 Internal use only. More...
 
void y (int v)
 Internal use only. More...
 

Static Protected Member Functions

static void vscroll_cb (Fl_Widget *, void *)
 
- Static Protected Member Functions inherited from Fl_Text_Display
static void buffer_modified_cb (int pos, int nInserted, int nDeleted, int nRestyled, const char *deletedText, void *cbArg)
 This is called whenever the buffer is modified. More...
 
static void buffer_predelete_cb (int pos, int nDeleted, void *cbArg)
 This is called before any characters are deleted. More...
 
static void h_scrollbar_cb (Fl_Scrollbar *w, Fl_Text_Display *d)
 Callback for drag or valueChanged on horizontal scrollbar.
 
static void scroll_timer_cb (void *)
 Timer callback for scroll events. More...
 
static void v_scrollbar_cb (Fl_Scrollbar *w, Fl_Text_Display *d)
 Callback for drag or valueChanged on vertical scrollbar.
 

Protected Attributes

Fl_Text_Bufferbuf
 
Fl_Text_Buffersbuf
 
- Protected Attributes inherited from Fl_Text_Display
int damage_range1_end
 
int damage_range1_start
 
int damage_range2_end
 
int damage_range2_start
 
int display_insert_position_hint
 
int dragging
 
int dragPos
 
int dragType
 
Fl_Color grammar_underline_color_
 
Fl_Align linenumber_align_
 
Fl_Color linenumber_bgcolor_
 
Fl_Color linenumber_fgcolor_
 
Fl_Font linenumber_font_
 
const char * linenumber_format_
 
Fl_Fontsize linenumber_size_
 
int mAbsTopLineNum
 
Fl_Text_BuffermBuffer
 
double mColumnScale
 
int mContinuousWrap
 
Fl_Color mCursor_color
 
int mCursorOldY
 
int mCursorOn
 
int mCursorPos
 
int mCursorPreferredXPos
 
int mCursorStyle
 
int mCursorToHint
 
int mFirstChar
 
void * mHighlightCBArg
 
int mHorizOffset
 
int mHorizOffsetHint
 
Fl_ScrollbarmHScrollBar
 
int mLastChar
 
int mLineNumLeft
 
int mLineNumWidth
 
int * mLineStarts
 
int mMaxsize
 
int mModifyingTabDistance
 
int mNBufferLines
 
int mNeedAbsTopLineNum
 
int mNLinesDeleted
 
int mNStyles
 
int mNVisibleLines
 
Fl_Text_BuffermStyleBuffer
 
const Style_Table_EntrymStyleTable
 
int mSuppressResync
 
int mTopLineNum
 
int mTopLineNumHint
 
Unfinished_Style_Cb mUnfinishedHighlightCB
 
char mUnfinishedStyle
 
Fl_ScrollbarmVScrollBar
 
int mWrapMarginPix
 
Fl_Align scrollbar_align_
 
int scrollbar_width_
 
Fl_Color secondary_selection_color_
 
int shortcut_
 
Fl_Color spelling_underline_color_
 
struct {
   int   h
 
   int   w
 
   int   x
 
   int   y
 
text_area
 
Fl_Color textcolor_
 
Fl_Font textfont_
 
Fl_Fontsize textsize_
 

Additional Inherited Members

- Public Types inherited from Fl_Text_Display
enum  {
  NORMAL_CURSOR , CARET_CURSOR , DIM_CURSOR , BLOCK_CURSOR ,
  HEAVY_CURSOR , SIMPLE_CURSOR
}
 text display cursor shapes enumeration More...
 
enum  { CURSOR_POS , CHARACTER_POS }
 the character position is the left edge of a character, whereas the cursor is thought to be between the centers of two consecutive characters.
 
enum  {
  DRAG_NONE = -2 , DRAG_START_DND = -1 , DRAG_CHAR = 0 , DRAG_WORD = 1 ,
  DRAG_LINE = 2
}
 drag types - they match Fl::event_clicks() so that single clicking to start a collection selects by character, double clicking selects by word and triple clicking selects by line.
 
enum  { WRAP_NONE , WRAP_AT_COLUMN , WRAP_AT_PIXEL , WRAP_AT_BOUNDS }
 wrap types - used in wrap_mode() More...
 
enum  {
  ATTR_BGCOLOR = 0x0001 , ATTR_BGCOLOR_EXT_ = 0x0002 , ATTR_BGCOLOR_EXT = 0x0003 , ATTR_UNDERLINE = 0x0004 ,
  ATTR_GRAMMAR = 0x0008 , ATTR_SPELLING = 0x000C , ATTR_STRIKE_THROUGH = 0x0010 , ATTR_LINES_MASK = 0x001C
}
 attribute flags in Style_Table_Entry.attr More...
 
typedef void(* Unfinished_Style_Cb) (int, void *)
 
- Static Public Member Functions inherited from Fl_Group
static Fl_Groupcurrent ()
 Returns the currently active group. More...
 
static void current (Fl_Group *g)
 Sets the current group. More...
 
- Static Public Member Functions inherited from Fl_Widget
static void default_callback (Fl_Widget *widget, void *data)
 The default callback for all widgets that don't set a callback. More...
 
static unsigned int label_shortcut (const char *t)
 Returns the Unicode value of the '&x' shortcut in a given text. More...
 
static int test_shortcut (const char *, const bool require_alt=false)
 Returns true if the given text t contains the entered '&x' shortcut. More...
 
- Protected Types inherited from Fl_Text_Display
enum  {
  DRAW_LINE , FIND_INDEX , FIND_INDEX_FROM_ZERO , GET_WIDTH ,
  FIND_CURSOR_INDEX
}
 
- Protected Types inherited from Fl_Widget
enum  {
  INACTIVE = 1<<0 , INVISIBLE = 1<<1 , OUTPUT = 1<<2 , NOBORDER = 1<<3 ,
  FORCE_POSITION = 1<<4 , NON_MODAL = 1<<5 , SHORTCUT_LABEL = 1<<6 , CHANGED = 1<<7 ,
  OVERRIDE = 1<<8 , VISIBLE_FOCUS = 1<<9 , COPIED_LABEL = 1<<10 , CLIP_CHILDREN = 1<<11 ,
  MENU_WINDOW = 1<<12 , TOOLTIP_WINDOW = 1<<13 , MODAL = 1<<14 , NO_OVERLAY = 1<<15 ,
  GROUP_RELATIVE = 1<<16 , COPIED_TOOLTIP = 1<<17 , FULLSCREEN = 1<<18 , MAC_USE_ACCENTS_MENU = 1<<19 ,
  NEEDS_KEYBOARD = 1<<20 , USERFLAG3 = 1<<29 , USERFLAG2 = 1<<30 , USERFLAG1 = 1<<31
}
 flags possible values enumeration. More...
 

Detailed Description

This is a continuous text scroll widget for logging and debugging output, much like a terminal.

Includes printf() for appending messages, a line limit for the screen history size, ANSI sequences to control text color, font face, font weight and font size.

This is useful in place of using stdout/stderr for logging messages when no terminal is available, such as when an application is invoked from a desktop shortcut, dock, or file browser.

Like a regular console terminal, the vertical scrollbar 'tracks' the bottom of the buffer as new output is added. If the user scrolls away from the bottom, this 'tracking' feature is temporarily suspended, so the user can browse the terminal history without fighting the scrollbar when new text is added asynchronously. When the user returns the scroller to the bottom of the display, the scrollbar's tracking resumes.

Features include:

  • history_lines(int) can define a maximum size for the terminal screen history
  • stay_at_bottom(bool) can be used to cause the terminal to keep scrolled to the bottom
  • ansi(bool) enables ANSI sequences within the text to control text colors
  • style_table() can be used to define custom color/font/weight/size combinations

What this widget is NOT is a full terminal emulator; it does NOT handle stdio redirection, pipes, pseudo ttys, termio character cooking, keyboard input processing, screen addressing, random cursor positioning, curses(3) compatibility, or VT100/xterm emulation.

It is a simple text display widget that leverages the features of the Fl_Text_Display base class to handle terminal-like behavior, such as logging events or debug information.

Example use:

#include <FL/Fl_Simple_Terminal.H>
:
tty = new Fl_Simple_Terminal(...);
tty->ansi(true); // enable use of "\033[#m"
:
tty->printf("The time is now: \033[32m%s\033[0m", date_time_str);
Fl_Simple_Terminal(int X, int Y, int W, int H, const char *l=0)
Creates a new Fl_Simple_Terminal widget that can be a child of other FLTK widgets.
Definition: Fl_Simple_Terminal.cxx:82

Example application:

#include <time.h> //START
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Simple_Terminal.H>
#define TERMINAL_HEIGHT 120
// Globals
Fl_Double_Window *G_win = 0;
Fl_Box *G_box = 0;
Fl_Simple_Terminal *G_tty = 0;
// Append a date/time message to the terminal every 2 seconds
void tick_cb(void *data) {
time_t lt = time(NULL);
G_tty->printf("Timer tick: \033[32m%s\033[0m\n", ctime(&lt));
Fl::repeat_timeout(2.0, tick_cb, data);
}
int main(int argc, char **argv) {
G_win = new Fl_Double_Window(500, 200+TERMINAL_HEIGHT, "Your App");
G_win->begin();
G_box = new Fl_Box(0, 0, G_win->w(), 200,
"Your app GUI in this area.\n\n"
"Your app's debugging output in tty below");
// Add simple terminal to bottom of app window for scrolling history of status messages.
G_tty = new Fl_Simple_Terminal(0,200,G_win->w(),TERMINAL_HEIGHT);
G_tty->ansi(true); // enable use of "\033[32m"
G_win->end();
G_win->resizable(G_win);
G_win->show();
Fl::add_timeout(0.5, tick_cb);
return Fl::run();
} //END
This widget simply draws its box, and possibly its label.
Definition: Fl_Box.H:32
The Fl_Double_Window provides a double-buffered window.
Definition: Fl_Double_Window.H:31
void show()
Puts the window on the screen.
Definition: Fl_Double_Window.cxx:45
void end()
Exactly the same as current(this->parent()).
Definition: Fl_Group.cxx:73
void begin()
Sets the current group so you can build the widget tree by just constructing the widgets.
Definition: Fl_Group.cxx:67
void resizable(Fl_Widget &o)
Sets the group's resizable widget.
Definition: Fl_Group.H:127
This is a continuous text scroll widget for logging and debugging output, much like a terminal.
Definition: Fl_Simple_Terminal.H:120
void ansi(bool val)
Enable/disable support of ANSI sequences like "\033[31m", which sets the color/font/weight/size of an...
Definition: Fl_Simple_Terminal.cxx:254
void printf(const char *fmt,...)
Appends printf formatted messages to the terminal.
Definition: Fl_Simple_Terminal.cxx:664
void w(int v)
Internal use only.
Definition: Fl_Widget.H:128
static void add_timeout(double t, Fl_Timeout_Handler, void *=0)
Adds a one-shot timeout callback.
Definition: Fl.cxx:237
static int run()
Calls Fl::wait()repeatedly as long as any windows are displayed.
Definition: Fl.cxx:503
static void repeat_timeout(double t, Fl_Timeout_Handler, void *=0)
Repeats a timeout callback from the expiration of the previous timeout, allowing for more accurate ti...
Definition: Fl.cxx:241

Style Tables For Color/Font/Fontsize Control

Internally this widget derives from Fl_Text_Display, and therefore inherits some of its idiosyncracies. In particular, when colors are used, the base class's concept of a 'style table' is used.

The 'style table' is similar to a color mapped image; where each pixel is a single value that is an index into a table of colors to minimize per-pixel memory use.

The style table has a similar goal; since every character in the terminal can potentially be a different color, instead of managing several integer attribute values per-character, a single character for each character is used as an index into the style table, choosing one of the available color/font/weight/size values available. This saves on as much as 3 to 4 times the memory use, useful when there's a large amount of text.

When ansi() is set to 'true', ANSI sequences of the form "\033[#m" can be used to select different colors, font faces, font weights (bold,italic..), and font sizes, where '#' is the index number into the style table. Example:

"\033[0mThis text uses the 1st entry in the style table\n"
"\033[1mThis text uses the 2nd entry in the style table\n"
"\033[2mThis text uses the 3rd entry in the style table\n"
etc..

There is a built-in style table that provides some commonly used ANSI colors for "\033[30m" through "\033[37m" (blk,red,grn,yel,blu,mag,cyn,wht), and a brighter version of those colors for "\033[40" through "\033[47m". See ansi(bool) for more info.

You can also supply a custom style table using style_table(Style_Table_Entry*,int,int), allowing you to define your own color/font/weight/size combinations. See that method's docs for more info.

All style index numbers are rounded to the size of the style table (via modulus) to protect the style array from overruns.

Member Function Documentation

◆ ansi() [1/2]

bool Fl_Simple_Terminal::ansi ( ) const

Get the state of the ANSI flag which enables/disables the handling of ANSI sequences in text.

When true, ANSI sequences in the text stream control color, font and font sizes of text (e.g. "\033[41mThis is Red\033[0m"). For more info, see ansi(bool).

See also
ansi(bool)

◆ ansi() [2/2]

void Fl_Simple_Terminal::ansi ( bool  val)

Enable/disable support of ANSI sequences like "\033[31m", which sets the color/font/weight/size of any text that follows.

If enabled, ANSI sequences of the form "\033[#m" can be used to change font color, face, and size, where '#' is an index number into the current style table. These "escape sequences" are hidden from view.

If disabled, the textcolor() / textfont() / textsize() methods define the color and font for all text in the terminal. ANSI sequences are not handled specially, and rendered as raw text.

A built-in style table is provided, but you can configure a custom style table using style_table(Style_Table_Entry*,int,int) for your own colors and fonts.

The built-in style table supports these ANSI sequences:

ANSI Sequence  Color Name      Font Face + Size  Remarks
-------------  --------------  ----------------  -----------------------
"\033[0m"      "Normal"        FL_COURIER, 14    Resets to default color/font/weight/size
"\033[30m"     Medium Black    FL_COURIER, 14
"\033[31m"     Medium Red      FL_COURIER, 14
"\033[32m"     Medium Green    FL_COURIER, 14
"\033[33m"     Medium Yellow   FL_COURIER, 14
"\033[34m"     Medium Blue     FL_COURIER, 14
"\033[35m"     Medium Magenta  FL_COURIER, 14
"\033[36m"     Medium Cyan     FL_COURIER, 14
"\033[37m"     Medium White    FL_COURIER, 14    The color when "\033[0m" reset is used
"\033[40m"     Bright Black    FL_COURIER, 14
"\033[41m"     Bright Red      FL_COURIER, 14
"\033[42m"     Bright Green    FL_COURIER, 14
"\033[43m"     Bright Yellow   FL_COURIER, 14
"\033[44m"     Bright Blue     FL_COURIER, 14
"\033[45m"     Bright Magenta  FL_COURIER, 14
"\033[46m"     Bright Cyan     FL_COURIER, 14
"\033[47m"     Bright White    FL_COURIER, 14

Here's example code demonstrating the use of ANSI codes to select the built-in colors, and how it looks in the terminal:

Fl_Simple_Terminal built-in ANSI sequences
Note
Changing the ansi(bool) value clears the buffer and forces a redraw().
Enabling ANSI mode overrides textfont(), textsize(), textcolor() completely, which are controlled instead by current_style_index() and the current style_table().
See also
style_table(Style_Table_Entry*,int,int), current_style_index(), normal_style_index()

◆ append()

void Fl_Simple_Terminal::append ( const char *  s,
int  len = -1 
)

Appends new string 's' to terminal.

The string can contain UTF-8, crlf's, and ANSI sequences are also supported when ansi(bool) is set to 'true'.

Parameters
sstring to append.
lenoptional length of string can be specified if known to save the internals from having to call strlen()
See also
printf(), vprintf(), text(), clear()

◆ clear()

void Fl_Simple_Terminal::clear ( )

Clears the terminal's screen and history.

Cursor moves to top of window.

◆ current_style_index() [1/2]

int Fl_Simple_Terminal::current_style_index ( ) const

Get the style table index used as the current drawing color/font/weight/size for new text.

This value is also controlled by the ANSI sequence "\033[#m", where # would be a new style index value. So if the application executes: term->append("\033[4mTesting"), then current_style_index() returns 4.

See also
current_style_index(int)

◆ current_style_index() [2/2]

void Fl_Simple_Terminal::current_style_index ( int  val)

Set the style table index used as the current drawing color/font/weight/size for new text.

For example:

:
tty->ansi(true);
tty->append("Some normal text.\n");
tty->current_style_index(2); // same as "\033[2m"
tty->append("This text will be green.\n");
tty->current_style_index(tty->normal_style_index()); // same as "\033[0m"
tty->append("Back to normal text.\n");
:

This value can also be changed by an ANSI sequence like "\033[#m", where # would be a new style index value. So if the application executes: term->append("\033[4mTesting"), then current_style_index() will be left set to 4.

The index number specified should be within the number of items in the current style table. Values larger than the table will be clamped to the size of the table with a modulus operation.

Effective only when ansi(bool) is 'true'.

◆ draw()

void Fl_Simple_Terminal::draw ( void  )
protectedvirtual

Draws the widget, including a cursor at the end of the buffer.

This is needed since currently Fl_Text_Display doesn't provide a reliable way to always do this.

Reimplemented from Fl_Text_Display.

◆ enforce_history_lines()

void Fl_Simple_Terminal::enforce_history_lines ( )
protected

Enforce 'history_lines' limit on the history buffer by trimming off lines from the top of the buffer.

This is a protected member called automatically by the public API functions. Only internal methods or subclasses adjusting the internal buffer directly should need to call this.

◆ enforce_stay_at_bottom()

void Fl_Simple_Terminal::enforce_stay_at_bottom ( )
protected

Scroll to last line unless someone has manually scrolled the vertical scrollbar away from the bottom.

This is a protected member called automatically by the public API functions. Only internal methods or subclasses adjusting the internal buffer directly should need to call this.

◆ history_lines() [1/2]

int Fl_Simple_Terminal::history_lines ( ) const

Get the maximum number of terminal history lines last set by history_lines(int).

-1 indicates an unlimited scroll history.

See also
history_lines(int)

◆ history_lines() [2/2]

void Fl_Simple_Terminal::history_lines ( int  maxlines)

Sets the maximum number of lines for the terminal history.

The new limit value is automatically enforced on the current screen history, truncating off any lines that exceed the new limit.

When a limit is set, the buffer is trimmed as new text is appended, ensuring the buffer never displays more than the specified number of lines.

The default maximum is 500 lines.

Parameters
maxlinesMaximum number of lines kept on the terminal buffer history. Use -1 for an unlimited scroll history. A value of 0 is not recommended.

◆ normal_style_index() [1/2]

int Fl_Simple_Terminal::normal_style_index ( ) const

Gets the style table index used by the ANSI terminal reset sequence "\033[0m".

This is the value last set by normal_style_index(int), or as set by the 3rd argument to style_table(Style_Table_Entry*,int,int).

See also
normal_style_index(int), ansi(bool), style_table(Style_Table_Entry*,int,int)

◆ normal_style_index() [2/2]

void Fl_Simple_Terminal::normal_style_index ( int  val)

Sets the style table index used by the ANSI terminal reset sequence "\033[0m", which resets the current drawing color/font/weight/size to "normal".

Effective only when ansi(bool) is 'true'.

See also
ansi(bool), style_table(Style_Table_Entry*,int,int)
Note
Changing this value does not change the current drawing color. To change that, use current_style_index(int).

◆ printf()

void Fl_Simple_Terminal::printf ( const char *  fmt,
  ... 
)

Appends printf formatted messages to the terminal.

The string can contain UTF-8, crlf's, and ANSI sequences are also supported when ansi(bool) is set to 'true'.

Example:

#include <FL/Fl_Simple_Terminal.H>
int main(..) {
:
// Create a simple terminal, and append some messages to it
:
// Append three lines of formatted text to the buffer
tty->printf("The current date is: %s.\nThe time is: %s\n", date_str, time_str);
tty->printf("The current PID is %ld.\n", (long)getpid());
:
Note
See Fl_Text_Buffer::vprintf() for limitations.
Parameters
[in]fmtis a printf format string for the message text.

◆ remove_lines()

void Fl_Simple_Terminal::remove_lines ( int  start,
int  count 
)

Remove the specified range of lines from the terminal, starting with line 'start' and removing 'count' lines.

This method is used to enforce the history limit.

Parameters
start– starting line to remove
count– number of lines to remove

◆ stay_at_bottom() [1/2]

bool Fl_Simple_Terminal::stay_at_bottom ( ) const

Gets the current value of the stay_at_bottom(bool) flag.

When true, the terminal tries to keep the scrollbar scrolled to the bottom when new text is added.

See also
stay_at_bottom(bool)

◆ stay_at_bottom() [2/2]

void Fl_Simple_Terminal::stay_at_bottom ( bool  val)

Configure the terminal to remain scrolled to the bottom when possible, chasing the end of the buffer whenever new text is added.

If disabled, the terminal behaves more like a text display widget; the scrollbar does not chase the bottom of the buffer.

If the user scrolls away from the bottom, this 'chasing' feature is temporarily disabled. This prevents the user from having to fight the scrollbar chasing the end of the buffer while browsing when new text is also being added asynchronously. When the user returns the scroller to the bottom of the display, the chasing behavior resumes.

The default is 'true'.

◆ style_table() [1/2]

const Fl_Text_Display::Style_Table_Entry * Fl_Simple_Terminal::style_table ( ) const

Return the current style table being used.

This is the value last passed as the 1st argument to style_table(Style_Table_Entry*,int,int). If no style table was defined, the built-in style table is returned.

ansi(bool) must be set to 'true' for the style table to be used at all.

See also
style_table(Style_Table_Entry*,int,int)

◆ style_table() [2/2]

void Fl_Simple_Terminal::style_table ( Fl_Text_Display::Style_Table_Entry stable,
int  stable_size,
int  normal_style_index = 0 
)

Set a user defined style table, which controls the font colors, faces, weights and sizes available for the terminal's text content.

ansi(bool) must be set to 'true' for the defined style table to be used at all.

If 'stable' is NULL, then the "built in" style table is used. For info about the built-in colors, see ansi(bool).

Which style table entry used for drawing depends on the value last set by current_style_index(), or by the ANSI sequence "\033[#m", where '#' is the index into the style table array, the index limited to the size of the array via modulus.

If the index# passed via "\033[#m" is larger than the number of elements in the table, the value is clamped via modulus. So for a 10 element table, the following ANSI codes would all be equivalent, selecting the 5th element in the table: "\033[5m", "\033[15m", "\033[25m", etc. This is because 5==(15%10)==(25%10), etc.

A special exception is made for "\033[0m", which is supposed to "reset" the current style table to default color/font/weight/size, as last set by normal_style_index, or by the API method normal_style_index(int).

In cases like the built-in style table, where the 17th item is the "normal" color, the 'normal_style_index' is set to 17 so that "\033[0m" resets to that color, instead of the first element in the table.

If you want "\033[0m" to simply pick the first element in the table, then set 'normal_style_index' to 0.

An example of defining a custom style table (white courier 14, red courier 14, and white helvetica 14):

int main() {
:
// Our custom style table
// Font Color Font Face Font Size Index ANSI Sequence
// ---------- ---------------- --------- ----- -------------
{ FL_WHITE, FL_COURIER_BOLD, 14 }, // 0 "\033[0m" ("default")
{ FL_RED, FL_COURIER_BOLD, 14 }, // 1 "\033[1m"
{ FL_WHITE, FL_HELVETICA, 14 } // 2 "\033[2m"
};
// Create terminal, enable ANSI and our style table
tty = new Fl_Simple_Terminal(..);
tty->ansi(true); // enable ANSI codes
tty->style_table(&mystyle[0], sizeof(mystyle), 0); // use our custom style table
:
// Now write to terminal, with ANSI that uses our style table
tty->printf("\033[0mNormal Text\033[1mRed Courier Text\n");
tty->append("\033[2mWhite Helvetica\033[0mBack to normal.\n");
:
const Fl_Font FL_COURIER_BOLD
Courier bold.
Definition: Enumerations.H:992
const Fl_Font FL_HELVETICA
Helvetica (or Arial) normal (0)
Definition: Enumerations.H:987
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
Note
Changing the style table clear()s the terminal.
You currently can't control /background/ color of text, a limitation of Fl_Text_Display's current implementation.
The caller is responsible for managing the memory of the style table.
Until STR#3412 is repaired, Fl_Text_Display has scrolling bug if the style table's font size != textsize()
Parameters
stable- the style table, an array of structs of the type Fl_Text_Display::Style_Table_Entry. Can be NULL to use the default style table (see ansi(bool)).
stable_size- the sizeof() the style table (in bytes). Set this to 0 if 'stable' is NULL.
normal_style_index- the style table index# used when the special ANSI sequence "\033[0m" is encountered. Normally use 0 so that sequence selects the first item in the table. Only use different values if a different entry in the table should be the default. This value should not be larger than the number of items in the table, or it will be clamped with a modulus operation. This value is ignored if stable is NULL.

◆ style_table_size()

int Fl_Simple_Terminal::style_table_size ( ) const

Return the current style table's size (in bytes).

This is the value last passed as the 2nd argument to style_table(Style_Table_Entry*,int,int).

◆ text() [1/2]

const char * Fl_Simple_Terminal::text ( ) const

Returns entire text content of the terminal as a single string.

This includes the screen history, as well as the visible onscreen content.

◆ text() [2/2]

void Fl_Simple_Terminal::text ( const char *  s,
int  len = -1 
)

Replaces the terminal with new text content in string 's'.

The string can contain UTF-8, crlf's, and ANSI sequences are also supported when ansi(bool) is set to 'true'.

Old terminal content is completely cleared.

Parameters
sstring to append.
lenoptional length of string can be specified if known to save the internals from having to call strlen()
See also
append(), printf(), vprintf(), clear()

◆ vprintf()

void Fl_Simple_Terminal::vprintf ( const char *  fmt,
va_list  ap 
)

Appends printf formatted messages to the terminal.

Subclasses can use this to implement their own printf() functionality.

The string can contain UTF-8, crlf's, and ANSI sequences are also supported when ansi(bool) is set to 'true'.

Note
The expanded string is currently limited to 1024 characters.
Parameters
fmtis a printf format string for the message text.
apis a va_list created by va_start() and closed with va_end(), which the caller is responsible for handling.

The documentation for this class was generated from the following files: