summaryrefslogtreecommitdiff
path: root/src/Fl_Text_Buffer.cxx
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2017-10-08 20:38:36 +0000
committerGreg Ercolano <erco@seriss.com>2017-10-08 20:38:36 +0000
commitd0e1d16ae899addf544c765ec8d50d8e095455df (patch)
tree8c9546496b86cfebf33a311989422b8e53435791 /src/Fl_Text_Buffer.cxx
parent73f1c43474b20e49f2ff62665cc6883a43a987ae (diff)
Added printf() and vprintf() to Fl_Text_Buffer
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12483 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Text_Buffer.cxx')
-rw-r--r--src/Fl_Text_Buffer.cxx44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/Fl_Text_Buffer.cxx b/src/Fl_Text_Buffer.cxx
index d63da183f..6b46dd497 100644
--- a/src/Fl_Text_Buffer.cxx
+++ b/src/Fl_Text_Buffer.cxx
@@ -292,6 +292,50 @@ void Fl_Text_Buffer::insert(int pos, const char *text)
}
+/**
+ Can be used by subclasses that need their own printf() style functionality.
+ e.g. Fl_Simple_Terminal::printf() would wrap around this method.
+ \note The expanded string is currently limited to 1024 characters.
+ \param[in] fmt is a printf format string for the message text.
+ \param[in] ap is a va_list created by va_start() and closed with va_end(),
+ which the caller is responsible for handling.
+*/
+void Fl_Text_Buffer::vprintf(const char *fmt, va_list ap) {
+ char buffer[1024]; // XXX: 1024 should be user configurable
+ ::vsnprintf(buffer, 1024, fmt, ap);
+ buffer[1024-1] = 0; // XXX: MICROSOFT
+ append(buffer);
+}
+
+
+/**
+ Appends printf formatted messages to the end of the buffer.
+ Example:
+ \code
+ #include <FL/Fl_Text_Display.H>
+ int main(..) {
+ :
+ // Create a text display widget and assign it a text buffer
+ Fl_Text_Display *tdsp = new Fl_Text_Display(..);
+ Fl_Text_Buffer *tbuf = new Fl_Text_Buffer();
+ tdsp->buffer(tbuf);
+ :
+ // Append three lines of formatted text to the buffer
+ tbuf->printf("The current date is: %s.\nThe time is: %s\n", date_str, time_str);
+ tbuf->printf("The current PID is %ld.\n", (long)getpid());
+ :
+ \endcode
+ \note The expanded string is currently limited to 1024 characters.
+ \param[in] fmt is a printf format string for the message text.
+*/
+void Fl_Text_Buffer::printf(const char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ Fl_Text_Buffer::vprintf(fmt,ap);
+ va_end(ap);
+}
+
+
/*
Replace a range of text with new text.
Start and end must be at a character boundary.