[rkward-cvs] SF.net SVN: rkward:[4300] trunk/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Sep 13 10:55:33 UTC 2012


Revision: 4300
          http://rkward.svn.sourceforge.net/rkward/?rev=4300&view=rev
Author:   tfry
Date:     2012-09-13 10:55:33 +0000 (Thu, 13 Sep 2012)
Log Message:
-----------
Fix handling of CRs in the console.
Note: This does not fix handling of CRs in other places, such as the output window.

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/rkconsole.cpp

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2012-09-11 20:34:19 UTC (rev 4299)
+++ trunk/rkward/ChangeLog	2012-09-13 10:55:33 UTC (rev 4300)
@@ -1,3 +1,4 @@
+- Fixed: Wrong handling of carriage returns ('\r') in the console window				TODO: also fix for the command log and other places
 - Fixed: Spinboxes had wrong initial values
 - Omit comments on missing function calls in dialog code windows (e.g., if prepare() is unused, there's no "## Prepare" in the output either)
 - Output markup is now more XHTML compliant and easier to parse

Modified: trunk/rkward/rkward/rkconsole.cpp
===================================================================
--- trunk/rkward/rkward/rkconsole.cpp	2012-09-11 20:34:19 UTC (rev 4299)
+++ trunk/rkward/rkward/rkconsole.cpp	2012-09-13 10:55:33 UTC (rev 4300)
@@ -664,8 +664,27 @@
 	RK_TRACE (APP);
 
 	int start_line = doc->lines () -1;
-	doc->insertText (doc->documentEnd (), output->output);
 
+	// split by and handle carriage returns
+	const QString outstr = output->output;
+	int start_pos = 0;
+	int end_pos = outstr.size () - 1;
+	QChar c;
+	for (int pos = 0; pos <= end_pos; ++pos) {
+		c = output->output.at (pos);
+		if (c == '\r') {
+			/* NOTE: My first approach was to split the whole string by newlines, and insert each line separately. This allowed for a minor
+			 * optimization when hitting a carriage return (the string before the '\r' could simply be ignored, then), however it caused
+			 * around 10% slowdown when printing large amounts of output.
+			 * Thus, instead, when hitting a CR, we first insert everything before that into the document, then reset the line. */
+			doc->insertText (doc->documentEnd (), outstr.mid (start_pos, pos - start_pos));
+			doc->removeLine (doc->lines () - 1);
+			doc->insertLine (doc->lines (), QString ());
+			start_pos = pos + 1;
+		}
+	}
+	if (start_pos <= end_pos) doc->insertText (doc->documentEnd (), outstr.mid (start_pos, end_pos - start_pos + 1));
+
 	int end_line = doc->lines () -1;
 	if (output->type != ROutput::Output) {
 		KTextEditor::MarkInterface *markiface = qobject_cast<KTextEditor::MarkInterface*> (doc);

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the rkward-tracker mailing list