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

Protected Member Functions

void append_ansi (const char *s, int len)
 Handle appending string with ANSI escape sequences, and other 'special' character processing (such as backspaces).
 
void backspace_buffer (unsigned int count)
 Destructive backspace from end of existing buffer() for specified count characters.
 
void draw () FL_OVERRIDE
 Draws the widget, including a cursor at the end of the buffer.
 
void enforce_history_lines ()
 Enforce 'history_lines' limit on the history buffer by trimming off lines from the top of the buffer.
 
void enforce_stay_at_bottom ()
 Scroll to last line unless someone has manually scrolled the vertical scrollbar away from the bottom.
 
void handle_backspace ()
 Handle a Unicode aware backspace.
 
void unknown_escape ()
 
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.
 
void calc_last_char ()
 Update last display character index.
 
void calc_line_starts (int startLine, int endLine)
 Update the line starts array.
 
void clear_rect (int style, int x, int y, int width, int height) const
 Clear a rectangle with the appropriate background color for style.
 
void display_insert ()
 Scroll the display to bring insertion cursor into view.
 
void draw () FL_OVERRIDE
 Draw the widget.
 
void draw_cursor (int, int)
 Draw a cursor with top center at X, Y.
 
void draw_line_numbers (bool clearAll)
 Refresh the line number area.
 
void draw_range (int start, int end)
 Draw a range of text.
 
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.
 
void draw_text (int X, int Y, int W, int H)
 Refresh a rectangle of the text display.
 
void draw_vline (int visLineNum, int leftClip, int rightClip, int leftCharIndex, int rightCharIndex)
 Draw a single line of text.
 
int empty_vlines () const
 Return true if there are lines visible with no corresponding buffer text.
 
void extend_range_for_styles (int *start, int *end)
 I don't know what this does!
 
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.
 
void find_wrap_range (const char *deletedText, int pos, int nInserted, int nDeleted, int *modRangeStart, int *modRangeEnd, int *linesInserted, int *linesDeleted)
 Wrapping calculations.
 
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.
 
int get_absolute_top_line_number () const
 Returns the absolute (non-wrapped) line number of the first line displayed.
 
int handle_rmb (int readonly)
 Handle right mouse button down events.
 
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.
 
int longest_vline () const
 Find the longest line of all visible lines.
 
void maintain_absolute_top_line_number (int state)
 Line numbering stuff, currently unused.
 
int maintaining_absolute_top_line_number () const
 Returns true if a separate absolute top line number is being maintained.
 
void measure_deleted_lines (int pos, int nDeleted)
 Wrapping calculations.
 
double measure_proportional_character (const char *s, int colNum, int pos) const
 Wrapping calculations.
 
int measure_vline (int visLineNum) const
 Returns the width in pixels of the displayed line pointed to by "visLineNum".
 
void offset_line_starts (int newTopLineNum)
 Offset line start counters for a new vertical scroll position.
 
int position_to_line (int pos, int *lineNum) const
 Convert a position index into a line number offset.
 
int position_to_linecol (int pos, int *lineNum, int *column) const
 Find the line and column number of position pos.
 
void reset_absolute_top_line_number ()
 Reestablish the absolute (non-wrapped) top line number.
 
int scroll_ (int topLineNum, int horizOffset)
 Scrolls the current buffer to start at the specified line and column.
 
double string_width (const char *string, int length, int style) const
 Find the width of a string in the font of a particular style.
 
void update_h_scrollbar ()
 Update horizontal scrollbar.
 
void update_line_starts (int pos, int charsInserted, int charsDeleted, int linesInserted, int linesDeleted, int *scrolled)
 Update line start arrays and variables.
 
void update_v_scrollbar ()
 Update vertical scrollbar.
 
int vline_length (int visLineNum) const
 Count number of bytes in a visible line.
 
int wrap_uses_character (int lineEndPos) const
 Check if the line break is caused by a newline or by line wrapping.
 
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.
 
int xy_to_position (int x, int y, int PosType=CHARACTER_POS) const
 Translate a pixel position into a character index.
 
void xy_to_rowcol (int x, int y, int *row, int *column, int PosType=CHARACTER_POS) const
 Translate pixel coordinates into row and column.
 
- Protected Member Functions inherited from Fl_Group
Fl_Rectbounds ()
 Returns the internal array of widget sizes and positions.
 
void draw_child (Fl_Widget &widget) const
 Forces a child to redraw.
 
void draw_children ()
 Draws all children of the group.
 
void draw_outside_label (const Fl_Widget &widget) const
 Parents normally call this to draw outside labels of child widgets.
 
virtual int on_insert (Fl_Widget *, int)
 Allow derived groups to act when a widget is added as a child.
 
virtual int on_move (int, int)
 Allow derived groups to act when a widget is moved within the group.
 
virtual void on_remove (int)
 Allow derived groups to act when a child widget is removed from the group.
 
int * sizes ()
 Returns the internal array of widget sizes and positions.
 
void update_child (Fl_Widget &widget) const
 Draws a child only if it needs it.
 
- 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.
 
void draw_focus (Fl_Boxtype t, int X, int Y, int W, int H) const
 Draws a focus rectangle around the widget.
 
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.
 
void draw_label () const
 Draws the widget's label at the defined label position.
 
void draw_label (int, int, int, int) const
 Draws the label in an arbitrary bounding box.
 
 Fl_Widget (int x, int y, int w, int h, const char *label=0L)
 Creates a widget at the given position and size.
 
unsigned int flags () const
 Gets the widget flags mask.
 
void h (int v)
 Internal use only.
 
void set_flag (unsigned int c)
 Sets a flag in the flags mask.
 
void w (int v)
 Internal use only.
 
void x (int v)
 Internal use only.
 
void y (int v)
 Internal use only.
 

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.
 
static void buffer_predelete_cb (int pos, int nDeleted, void *cbArg)
 This is called before any characters are deleted.
 
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.
 
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.
 
static void current (Fl_Group *g)
 Sets the current group.
 
- 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.
 
static unsigned int label_shortcut (const char *t)
 Returns the Unicode value of the '&x' shortcut in a given text.
 
static int test_shortcut (const char *, const bool require_alt=false)
 Returns true if the given text t contains the entered '&x' shortcut.
 
- 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 , IMAGE_BOUND = 1<<21 , DEIMAGE_BOUND = 1<<22 , AUTO_DELETE_USER_DATA = 1<<23 ,
  MAXIMIZED = 1<<24 , 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);
This is a continuous text scroll widget for logging and debugging output, much like a terminal.
Definition Fl_Simple_Terminal.H:120

Example application:

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()

◆ ansi_show_unknown() [1/2]

bool Fl_Simple_Terminal::ansi_show_unknown ( void  ) const

See if we should show unknown ANSI sequences with '¿' or not.

See also
ansi_show_unknown(bool)

◆ ansi_show_unknown() [2/2]

void Fl_Simple_Terminal::ansi_show_unknown ( bool  val)

Enable showing unknown ESC sequences with the '¿' character.

By default this is off, and unknown escape sequences are silently ignored.

See also
ansi_show_unknown()

◆ 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 if ansi(bool) is set to 'true', ANSI 'ESC' sequences (such as ESC[1m) and other control characters (such as backspace) are handled.

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()

◆ backspace_buffer()

void Fl_Simple_Terminal::backspace_buffer ( unsigned int  count)
protected

Destructive backspace from end of existing buffer() for specified count characters.

Takes into account multi-byte (Unicode) chars. So if count is 3, last 3 chars are deleted from end of buffer.

◆ clear()

void Fl_Simple_Terminal::clear ( )

Clears the terminal's screen and history.

Cursor moves to top of window.

◆ current_style()

int Fl_Simple_Terminal::current_style ( ) const

Get the current style char used for style buffer.

This character appends in parallel with any text in the text buffer to specify the per-character styling. This is typically 'A' for the first entry, 'B' for the second entry, etc.

This value is changed by current_style_index(int).

See also
current_style_index(int)

◆ 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_Group.

◆ 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.

◆ handle_backspace()

void Fl_Simple_Terminal::handle_backspace ( )
protected

Handle a Unicode aware backspace.

This flushes the string parsed so far to Fl_Text_Display, then lets Fl_Text_Display handle the unicode aware backspace.

◆ 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());
:
void printf(const char *fmt,...)
Appends printf formatted messages to the terminal.
Definition Fl_Simple_Terminal.cxx:973
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:1051
const Fl_Font FL_HELVETICA
Helvetica (or Arial) normal (0)
Definition Enumerations.H:1046
This structure associates the color, font, and font size of a string to draw with an attribute mask m...
Definition Fl_Text_Display.H:145
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: