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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Fri May 13 11:13:52 UTC 2011


Revision: 3554
          http://rkward.svn.sourceforge.net/rkward/?rev=3554&view=rev
Author:   tfry
Date:     2011-05-13 11:13:52 +0000 (Fri, 13 May 2011)

Log Message:
-----------
Add a rudimentary CSS for the output, and fix some quirks in the new copy to output features.

Modified Paths:
--------------
    trunk/rkward/rkward/rbackend/rinterface.cpp
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
    trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp

Added Paths:
-----------
    trunk/rkward/rkward/pages/rkward_output.css

Added: trunk/rkward/rkward/pages/rkward_output.css
===================================================================
--- trunk/rkward/rkward/pages/rkward_output.css	                        (rev 0)
+++ trunk/rkward/rkward/pages/rkward_output.css	2011-05-13 11:13:52 UTC (rev 3554)
@@ -0,0 +1,25 @@
+pre.code {
+	margin-left: 2em;
+}
+
+pre.code:before {
+	display: block;
+	content: "> ";
+	width: 2em;
+	color: black;
+	float: left;
+	margin-left: -2em;
+}
+
+pre.output_normal {
+	clear: both;	/* make sure never to float around the "> " marker */
+}
+
+pre.output_warning {
+	clear: both;	/* make sure never to float around the "> " marker */
+	background-color: #ffaaaa;
+}
+
+table {
+	border-spacing: 0px;
+}
\ No newline at end of file

Modified: trunk/rkward/rkward/rbackend/rinterface.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rinterface.cpp	2011-05-13 08:28:49 UTC (rev 3553)
+++ trunk/rkward/rkward/rbackend/rinterface.cpp	2011-05-13 11:13:52 UTC (rev 3554)
@@ -364,20 +364,21 @@
 		}
 
 		if (num_active_output_record_requests) {
-			if (output->type >= previous_output_type) {
-				if (!recorded_output.isEmpty ()) recorded_output.append ("</pre>\n");
+			if (output->type != ROutput::Error) {	// NOTE: skip error output. It has already been written as a warning.
+				if (output->type != previous_output_type) {
+					if (!recorded_output.isEmpty ()) recorded_output.append ("</pre>\n");
 
-				if (output->type == ROutput::Output) recorded_output.append ("<pre class=\"output_normal\">");
-				else if (output->type == ROutput::Warning) recorded_output.append ("<pre class=\"output_warning\">");
-				else if (output->type == ROutput::Error) recorded_output.append ("<pre class=\"output_error\">");
-				else {
-					RK_ASSERT (false);
-					recorded_output.append ("<pre>");
+					if (output->type == ROutput::Output) recorded_output.append ("<pre class=\"output_normal\">");
+					else if (output->type == ROutput::Warning) recorded_output.append ("<pre class=\"output_warning\">");
+					else {
+						RK_ASSERT (false);
+						recorded_output.append ("<pre>");
+					}
+
+					previous_output_type = output->type;
 				}
-
-				previous_output_type = output->type;
+				recorded_output.append (Qt::escape (output->output));
 			}
-			recorded_output.append (Qt::escape (output->output));
 		}
 
 		bool first = true;
@@ -477,6 +478,8 @@
 	} else if (call == "set.output.file") {
 		RK_ASSERT (calllist.count () == 2);
 		RKOutputWindowManager::self ()->setCurrentOutputPath (calllist.value (1));
+	} else if (call == "getCSSlink") {
+		return (QStringList (QString ("<link rel=\"StyleSheet\" type=\"text/css\" href=\"file://" + RKCommonFunctions::getRKWardDataDir () + "pages/rkward_output.css" "\"/>\n")));
 	} else if (call == "wdChange") {
 		// in case of separate processes, apply new working directory in frontend, too.
 		QDir::setCurrent (calllist.value (1));

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2011-05-13 08:28:49 UTC (rev 3553)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2011-05-13 11:13:52 UTC (rev 3554)
@@ -132,10 +132,10 @@
 	assign (".rk.output.html.file", x, as.environment ("package:rkward"))
 
 	if (!file.exists (x)) {
-		.rk.cat.output (paste ("<?xml version=\"1.0\" encoding=\"", .Call ("rk.locale.name"), "\"?>\n", sep=""));
-		.rk.cat.output ("<html><head><title>RKWard Output</title></head>\n<body>\n")
+		.rk.cat.output (paste ("<?xml version=\"1.0\" encoding=\"", .Call ("rk.locale.name"), "\"?>\n", sep=""))
+		.rk.cat.output (paste ("<html><head>\n<title>RKWard Output</title>\n", .rk.do.plain.call ("getCSSlink"), "</head>\n<body>\n", sep=""))
 		# This initial output mostly to indicate the output is really there, just empty for now
-		.rk.cat.output (paste ("<pre>RKWard output initialized on", date (), "</pre>\n"));
+		.rk.cat.output (paste ("<pre>RKWard output initialized on", date (), "</pre>\n"))
 	}
 
 	# needs to come after initialization, so initialization alone does not trigger an update during startup

Modified: trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp	2011-05-13 08:28:49 UTC (rev 3553)
+++ trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp	2011-05-13 11:13:52 UTC (rev 3554)
@@ -1073,19 +1073,19 @@
 	if (!iface) return (QString ("<pre>") + r_command + "</pre>");
 
 	doc->setText (r_command);
+	if (r_command.endsWith ("\n")) doc->removeLine (doc->lines () - 1);
 	setHighlighting (doc, mode);
 	QString ret;
 
 	QString opening;
 	KTextEditor::Attribute::Ptr m_defaultAttribute = iface->defaultStyle(KTextEditor::HighlightInterface::dsNormal);
 	if ( !m_defaultAttribute ) {
-		opening = "<pre class=\"%5\">";
+		opening = "<pre class=\"%3\">";
 	} else {
-		opening = QString("<pre style='%1%2%3%4' class=\"%5\">")
+		opening = QString("<pre style='%1%2' class=\"%3\">")
 				.arg(m_defaultAttribute->fontBold() ? "font-weight:bold;" : "")
-				.arg(m_defaultAttribute->fontItalic() ? "text-style:italic;" : "")
-				.arg("color:" + m_defaultAttribute->foreground().color().name() + ';');
-//				.arg("background-color:" + m_defaultAttribute->background().color().name() + ';');
+				.arg(m_defaultAttribute->fontItalic() ? "text-style:italic;" : "");
+				// Note: copying the default text/background colors is pointless in our case, and leads to subtle inconsistencies.
 	}
 
 	const KTextEditor::Attribute::Ptr noAttrib(0);
@@ -1094,13 +1094,18 @@
 	enum {
 		Command,
 		Output,
+		Warning,
 		None
 	} previous_chunk = None;
 	for (int i = 0; i < doc->lines (); ++i)
 	{
 		const QString &line = doc->line(i);
+		QList<KTextEditor::HighlightInterface::AttributeBlock> attribs = iface->lineAttributes(i);
+		int lineStart = 0;
+
 		if (mode == RInteractiveSession) {
-			if (line.startsWith (">") || line.startsWith ("+")) {
+			if (line.startsWith ("> ") || line.startsWith ("+ ")) {
+				lineStart = 2;	// skip the prompt. Prompt will be indicated by the CSS, instead
 				if (previous_chunk != Command) {
 					if (previous_chunk != None) ret.append ("</pre>");
 					ret.append (opening.arg ("code"));
@@ -1112,16 +1117,15 @@
 					ret.append (opening.arg ("output_normal"));
 					previous_chunk = Output;
 				}
+				ret.append (Qt::escape (line) + "\n");	// don't copy output "highlighting". It is set using CSS, instead
+				continue;
 			}
 		}
 
-		QList<KTextEditor::HighlightInterface::AttributeBlock> attribs = iface->lineAttributes(i);
-
-		int lineStart = 0;
-		int remainingChars = line.length();
 		int handledUntil = lineStart;
-
+		int remainingChars = line.length() - handledUntil;
 		foreach ( const KTextEditor::HighlightInterface::AttributeBlock& block, attribs ) {
+			if ((block.start + block.length) <= handledUntil) continue;
 			int start = qMax(block.start, lineStart);
 			if ( start > handledUntil ) {
 				ret += exportText( line.mid( handledUntil, start - handledUntil ), noAttrib, m_defaultAttribute );
@@ -1135,7 +1139,7 @@
 			ret += exportText( line.mid( handledUntil, remainingChars ), noAttrib, m_defaultAttribute );
 		}
 
-		if (i < (doc->lines () - 1)) ret.append ("\n");
+		if (i <= (doc->lines () - 1)) ret.append ("\n");
 	}
 	ret.append ("</pre>\n");
 


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