Skip to content
Browse files

fix for issue 55: monospaced output

  • Loading branch information...
1 parent ad5c828 commit b196bb0619d2c570b9c87d4d4d565facf6fdddc4 Danny Yoo committed Mar 22, 2012
Showing with 41 additions and 22 deletions.
  1. +15 −3 war/js/mzscheme-vm/evaluator.js
  2. +26 −19 war/js/mzscheme-vm/support.js
View
18 war/js/mzscheme-vm/evaluator.js
@@ -95,11 +95,23 @@ var Evaluator = (function() {
helpers.maybeCallAfterAttach(dom);
});
+
this.aState.setDisplayHook(function(aStr) {
var dom = document.createElement("span");
- dom.style["white-space"] = "pre";
- var node = document.createTextNode(aStr);
- dom.appendChild(node);
+ dom.style["white-space"] = "pre";
+ dom.style["font-family"] = "monospace";
+ var chunks = aStr.split("\n");
+ if (chunks.length > 0) {
+ dom.appendChild(document.createTextNode(chunks[0]));
+ }
+ var newlineDiv;
+ var i;
+ for (i = 1; i < chunks.length; i++) {
+ newlineDiv = document.createElement("br");
+ newlineDiv.style.clear = 'left';
+ dom.appendChild(newlineDiv);
+ dom.appendChild(document.createTextNode(chunks[i]));
+ }
dom = that.transformDom(dom);
that.write(dom);
helpers.maybeCallAfterAttach(dom);
View
45 war/js/mzscheme-vm/support.js
@@ -8175,6 +8175,7 @@ var toDomNode = function(x, cache) {
if (typeof(x) == 'object') {
if (cache.containsKey(x)) {
var node = document.createElement("span");
+ node.style['font-family'] = 'monospace';
node.appendChild(document.createTextNode("..."));
return node;
}
@@ -8183,46 +8184,52 @@ var toDomNode = function(x, cache) {
if (x == undefined || x == null) {
var node = document.createElement("span");
+ node.style['font-family'] = 'monospace';
node.appendChild(document.createTextNode("#<undefined>"));
return node;
}
if (typeof(x) == 'string') {
- var wrapper = document.createElement("span");
- wrapper.style["white-space"] = "pre";
- var node = document.createTextNode(toWrittenString(x));
- wrapper.appendChild(node);
- return wrapper;
+ return textToDomNode(toWrittenString(x));
}
if (typeof(x) != 'object' && typeof(x) != 'function') {
- var node = document.createElement("span");
- node.appendChild(document.createTextNode(x.toString()));
- return node;
+ return textToDomNode(x.toString());
}
var returnVal;
if (x.nodeType) {
returnVal = x;
} else if (typeof(x.toDomNode) !== 'undefined') {
returnVal = x.toDomNode(cache);
- } else if (typeof(x.toWrittenString) !== 'undefined') {
-
- var node = document.createElement("span");
- node.appendChild(document.createTextNode(x.toWrittenString(cache)));
- returnVal = node;
+ } else if (typeof(x.toWrittenString) !== 'undefined') {
+ returnVal = textToDomNode(x.toWrittenString(cache))
} else if (typeof(x.toDisplayedString) !== 'undefined') {
- var node = document.createElement("span");
- node.appendChild(document.createTextNode(x.toDisplayedString(cache)));
- returnVal = node;
+ returnVal = textToDomNode(x.toDisplayedString(cache));
} else {
- var node = document.createElement("span");
- node.appendChild(document.createTextNode(x.toString()));
- returnVal = node;
+ returnVal = textToDomNode(x.toString());
}
cache.remove(x);
return returnVal;
};
+var textToDomNode = function(text) {
+ var chunks = text.split("\n");
+ var i;
+ var wrapper = document.createElement("span");
+ var newlineDiv;
+ wrapper.style['font-family'] = 'monospace';
+ wrapper.style["white-space"] = "pre";
+ if (chunks.length > 0) {
+ wrapper.appendChild(document.createTextNode(chunks[0]));
+ }
+ for (i = 1; i < chunks.length; i++) {
+ newlineDiv = document.createElement("div");
+ newlineDiv.style.clear = 'left';
+ wrapper.appendChild(newlineDiv);
+ wrapper.appendChild(document.createTextNode(chunks[i]));
+ }
+ return wrapper;
+};

0 comments on commit b196bb0

Please sign in to comment.
Something went wrong with that request. Please try again.