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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon Mar 12 22:18:55 UTC 2007


Revision: 1565
          http://svn.sourceforge.net/rkward/?rev=1565&view=rev
Author:   tfry
Date:     2007-03-12 15:18:55 -0700 (Mon, 12 Mar 2007)

Log Message:
-----------
use the new R_WriteConsoleEx for R >= 2.5, and highlight warnings/errors in log/console

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/TODO
    trunk/rkward/rkward/rbackend/rcommand.cpp
    trunk/rkward/rkward/rbackend/rcommand.h
    trunk/rkward/rkward/rbackend/rembedinternal.cpp
    trunk/rkward/rkward/rkconsole.cpp
    trunk/rkward/rkward/windows/rkcommandlog.cpp
    trunk/rkward/rkward/windows/rkcommandlog.h

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2007-03-12 21:31:39 UTC (rev 1564)
+++ trunk/rkward/ChangeLog	2007-03-12 22:18:55 UTC (rev 1565)
@@ -1,3 +1,4 @@
+- warnings and errors are highlighted in command log / console (warnings only for R >= 2.5.x)
 - plugin generated commands are run in a local() environment, allowing for more consise code		TODO: document, adjust examples, adjust plugins, etc.
 - also support filename completion in the console (mode of completion is determined by heuristic means)
 - initial support for R's Sys.setlocale(), and Encoding of CHARSXPs

Modified: trunk/rkward/TODO
===================================================================
--- trunk/rkward/TODO	2007-03-12 21:31:39 UTC (rev 1564)
+++ trunk/rkward/TODO	2007-03-12 22:18:55 UTC (rev 1565)
@@ -201,8 +201,8 @@
 	- RCommandStack
 
 Configuration:
-	- additional console options:
-		- color highlighting for warnings/errors (once we can identify them reliably)
+	- additional console/log options:
+		- color highlighting for warnings/errors
 	- additional R engine options:
 		- stack size (commandline arg --map-ppsize)
 		- disable html help

Modified: trunk/rkward/rkward/rbackend/rcommand.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rcommand.cpp	2007-03-12 21:31:39 UTC (rev 1564)
+++ trunk/rkward/rkward/rbackend/rcommand.cpp	2007-03-12 22:18:55 UTC (rev 1565)
@@ -2,7 +2,7 @@
                           rcommand.cpp  -  description
                              -------------------
     begin                : Mon Nov 11 2002
-    copyright            : (C) 2002, 2006 by Thomas Friedrichsmeier
+    copyright            : (C) 2002, 2006, 2007 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -113,7 +113,7 @@
 	RK_TRACE (RBACKEND);
 
 	QString ret;
-	for (QValueList<ROutput*>::const_iterator it = output_list.begin (); it != output_list.end (); ++it) {
+	for (ROutputList::const_iterator it = output_list.begin (); it != output_list.end (); ++it) {
 		if ((*it)->type == ROutput::Error) {
 			ret.append ((*it)->output);
 		}
@@ -125,7 +125,7 @@
 	RK_TRACE (RBACKEND);
 
 	QString ret;
-	for (QValueList<ROutput*>::const_iterator it = output_list.begin (); it != output_list.end (); ++it) {
+	for (ROutputList::const_iterator it = output_list.begin (); it != output_list.end (); ++it) {
 		if ((*it)->type == ROutput::Output) {
 			ret.append ((*it)->output);
 		}
@@ -137,7 +137,7 @@
 	RK_TRACE (RBACKEND);
 
 	QString ret;
-	for (QValueList<ROutput*>::const_iterator it = output_list.begin (); it != output_list.end (); ++it) {
+	for (ROutputList::const_iterator it = output_list.begin (); it != output_list.end (); ++it) {
 		if ((*it)->type == ROutput::Warning) {
 			ret.append ((*it)->output);
 		}
@@ -149,7 +149,7 @@
 	RK_TRACE (RBACKEND);
 
 	QString ret;
-	for (QValueList<ROutput*>::const_iterator it = output_list.begin (); it != output_list.end (); ++it) {
+	for (ROutputList::const_iterator it = output_list.begin (); it != output_list.end (); ++it) {
 		ret.append ((*it)->output);
 	}
 	return ret;

Modified: trunk/rkward/rkward/rbackend/rcommand.h
===================================================================
--- trunk/rkward/rkward/rbackend/rcommand.h	2007-03-12 21:31:39 UTC (rev 1564)
+++ trunk/rkward/rkward/rbackend/rcommand.h	2007-03-12 22:18:55 UTC (rev 1565)
@@ -2,7 +2,7 @@
                           rcommand.h  -  description
                              -------------------
     begin                : Mon Nov 11 2002
-    copyright            : (C) 2002, 2006 by Thomas Friedrichsmeier
+    copyright            : (C) 2002, 2006, 2007 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -71,12 +71,14 @@
 	enum ROutputType {
 		Output,			/**< normal output */
 		Warning,		/**< R warning */
-		Error				/**< R error */
+		Error			/**< R error */
 	};
 	ROutputType type;
 	QString output;
 };
 
+typedef QValueList<ROutput*> ROutputList;
+
 /*
 struct RGetValueRequest {
 private:
@@ -197,6 +199,7 @@
 /** Remove a receiver from the list. This may be needed when a listener wants to self-destruct, to make sure we don't try to send any further info there */
 	void removeReceiver (RCommandReceiver *receiver);
 	void addTypeFlag (int flag) { _type |= flag; };
+	ROutputList &getOutput () { return output_list; };
 private:
 friend class RThread;
 friend class RInterface;
@@ -204,7 +207,7 @@
 	void finished ();
 /** new output was generated. Pass on to receiver(s) */
 	void newOutput (ROutput *output);
-	QValueList<ROutput*> output_list;
+	ROutputList output_list;
 	QString _command;
 	int _type;
 	int _flags;

Modified: trunk/rkward/rkward/rbackend/rembedinternal.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rembedinternal.cpp	2007-03-12 21:31:39 UTC (rev 1564)
+++ trunk/rkward/rkward/rbackend/rembedinternal.cpp	2007-03-12 22:18:55 UTC (rev 1565)
@@ -184,16 +184,19 @@
 	return 0;
 }
 
+#ifdef R_2_5
+void RWriteConsoleEx (char *buf, int buflen, int type) {
+	RK_TRACE (RBACKEND);
+
+	REmbedInternal::this_pointer->handleOutput (REmbedInternal::this_pointer->current_locale_codec->toUnicode (buf, buflen), buflen, type == 0);
+}
+#else
 void RWriteConsole (char *buf, int buflen) {
 	RK_TRACE (RBACKEND);
 
-/*	RCallbackArgs args;
-	args.type = RCallbackArgs::RWriteConsole;
-	args.chars_a = &buf;
-	args.int_a = buflen;
-	REmbedInternal::this_pointer->handleStandardCallback (&args); */
 	REmbedInternal::this_pointer->handleOutput (REmbedInternal::this_pointer->current_locale_codec->toUnicode (buf, buflen), buflen, true);
 }
+#endif
 
 void RResetConsole () {
 	RK_TRACE (RBACKEND);
@@ -340,7 +343,12 @@
 	ptr_R_Suicide = RSuicide;
 	ptr_R_ShowMessage = RShowMessage;			// when exactly does this ever get used?
 	ptr_R_ReadConsole = RReadConsole;
+#ifdef R_2_5
+	ptr_R_WriteConsoleEx = RWriteConsoleEx;
+	ptr_R_WriteConsole = 0;
+#else
 	ptr_R_WriteConsole = RWriteConsole;
+#endif
 	ptr_R_ResetConsole = RResetConsole;
 	ptr_R_FlushConsole = RFlushConsole;
 	ptr_R_ClearerrConsole = RClearerrConsole;

Modified: trunk/rkward/rkward/rkconsole.cpp
===================================================================
--- trunk/rkward/rkward/rkconsole.cpp	2007-03-12 21:31:39 UTC (rev 1564)
+++ trunk/rkward/rkward/rkconsole.cpp	2007-03-12 22:18:55 UTC (rev 1565)
@@ -545,13 +545,18 @@
 void RKConsole::newOutput (RCommand *, ROutput *output) {
 	RK_TRACE (APP);
 
-// TODO: handle different types of output, once we can differentiate between them
-//	insertAt (output->output, doc->numLines()-1, paragraphLength (doc->numLines() - 1));
+	int start_line = doc->numLines () -1;
 	if (output_continuation) {
 		editInterface (doc)->insertText (doc->numLines () -1, editInterface (doc)->lineLength (doc->numLines () -1), output->output);
 	} else {
 		editInterface (doc)->insertText (doc->numLines () -1, 0, output->output);
 	}
+	int end_line = doc->numLines () -1;
+	if (output->type != ROutput::Output) {
+		for (int line = start_line; line < end_line; ++line) {
+			doc->addMark (line, KTextEditor::MarkInterface::BreakpointActive);
+		}
+	}
 
 	if (RKSettingsModuleConsole::maxConsoleLines ()) {
 		uint c = (uint) doc->numLines();

Modified: trunk/rkward/rkward/windows/rkcommandlog.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkcommandlog.cpp	2007-03-12 21:31:39 UTC (rev 1564)
+++ trunk/rkward/rkward/windows/rkcommandlog.cpp	2007-03-12 22:18:55 UTC (rev 1565)
@@ -2,7 +2,7 @@
                           rkcommandlog  -  description
                              -------------------
     begin                : Sun Nov 3 2002
-    copyright            : (C) 2002, 2004, 2005 2006,2007 by Thomas Friedrichsmeier
+    copyright            : (C) 2002, 2004, 2005 2006, 2007 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -101,7 +101,7 @@
 	command_input_shown = command->id ();
 }
 
-void RKCommandLog::addOutputNoCheck (RCommand *command, const QString &output) {
+void RKCommandLog::addOutputNoCheck (RCommand *command, ROutput *output) {
 	RK_TRACE (APP);
 
 	if (command->type () & RCommand::User) {
@@ -111,16 +111,21 @@
 	} else if (command->type () & RCommand::Plugin) {
 		log_view->setColor (Qt::blue);
 	}
+	log_view->setBold (true);
+	if (output->type != ROutput::Output) {
+		log_view->setParagraphBackgroundColor (log_view->paragraphs () - 1, QColor (255, 200, 200));
+	}
 
-    log_view->setBold (true);
+	log_view->insert (output->output);
 
-	log_view->insert (output);
+	if (output->type != ROutput::Output) {
+		log_view->setParagraphBackgroundColor (log_view->paragraphs () - 1, QColor (255, 255, 255));
+	}
+	log_view->setBold (false);
+	log_view->setColor (Qt::black);
 
 	checkRaiseWindow (command);
 	linesAdded ();
-
-	log_view->setBold (false);
-	log_view->setColor (Qt::black);
 }
 
 void RKCommandLog::checkRaiseWindow (RCommand *command) {
@@ -140,7 +145,7 @@
 
 	if (RKSettingsModuleWatch::shouldShowInput (command)) addInputNoCheck (command);
 
-	addOutputNoCheck (command, output_fragment->output);
+	addOutputNoCheck (command, output_fragment);
 }
 
 void RKCommandLog::rCommandDone (RCommand *command) {
@@ -154,15 +159,23 @@
 	if (command->failed ()) {
 		if (RKSettingsModuleWatch::shouldShowError (command)) {
 			if (!RKSettingsModuleWatch::shouldShowInput (command)) addInputNoCheck (command);
-			if (!RKSettingsModuleWatch::shouldShowOutput (command)) addOutputNoCheck (command, command->fullOutput ());
+			if (!RKSettingsModuleWatch::shouldShowOutput (command)) {
+				ROutputList out_list = command->getOutput ();
+				for (ROutputList::const_iterator it = out_list.constBegin (); it != out_list.constEnd (); ++it) {
+					addOutputNoCheck (command, *it);
+				}
+			}
 			if (command->error ().isEmpty ()) {
+				ROutput dummy_output;
+				dummy_output.type = ROutput::Error;
 				if (command->errorIncomplete ()) {
-					addOutputNoCheck (command, i18n ("Incomplete statement.\n"));
+					dummy_output.output = i18n ("Incomplete statement.\n");
 				} else if (command->errorSyntax ()) {
-					addOutputNoCheck (command, i18n ("Syntax error.\n"));
+					dummy_output.output = i18n ("Syntax error.\n");
 				} else {
-					addOutputNoCheck (command, i18n ("An unspecified error occurred while running the command.\n"));
+					dummy_output.output = i18n ("An unspecified error occurred while running the command.\n");
 				}
+				addOutputNoCheck (command, &dummy_output);
 			}
 		}
 	}

Modified: trunk/rkward/rkward/windows/rkcommandlog.h
===================================================================
--- trunk/rkward/rkward/windows/rkcommandlog.h	2007-03-12 21:31:39 UTC (rev 1564)
+++ trunk/rkward/rkward/windows/rkcommandlog.h	2007-03-12 22:18:55 UTC (rev 1565)
@@ -63,7 +63,7 @@
 	void runSelection ();
 private:
 	void addInputNoCheck (RCommand *command);
-	void addOutputNoCheck (RCommand *command, const QString &output);
+	void addOutputNoCheck (RCommand *command, ROutput *output);
 	void checkRaiseWindow (RCommand *command);
 /** internal helper function, called whenever a line/lines have been added. Check whether log is longer than maximum setting. Scroll to the bottom */
 	void linesAdded ();


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