Skip to content
Browse files

Partially fix "fixConsole" function which was breaking on some outputs

  • Loading branch information...
1 parent ddffe2b commit 30d73331585db1cc477919b009aef9dc78646325 @jamesgao committed Oct 14, 2010
Showing with 14 additions and 15 deletions.
  1. +1 −1 IPython/frontend/html/ipythonhttp.py
  2. +12 −14 IPython/frontend/html/js/notebook.js
  3. +1 −0 IPython/frontend/html/notebook.html
View
2 IPython/frontend/html/ipythonhttp.py
@@ -79,7 +79,7 @@ def main():
kernel_manager.start_channels()
#Start the web server
- os.system("xdg-open http://localhost:8080/notebook")
+# os.system("xdg-open http://localhost:8080/notebook")
server = IPyHttpServer((args.ip, 8080), IPyHttpHandler)
server.serve_forever()
View
26 IPython/frontend/html/js/notebook.js
@@ -2,23 +2,21 @@ function fixConsole(txt) {
//Fixes escaped console commands, IE colors. Turns them into HTML
//Unfortunately, the "semantics" of html and console are very
//different, so fancy things *will* break
- var attrib = {"30":"cblack", "31":"cred","32":"cgreen", "34":"cblue", "01":"cbold"}
+ var attrib = {"30":"cblack", "31":"cred","32":"cgreen", "34":"cblue", "36":"ccyan", "01":"cbold"}
txt = txt.replace("<","&lt;").replace(">", "&gt;")
- //Must remove first \033[0m to eliminate pairing errors
-// txt = txt.replace(/\033\[0m/, "")
- //Phase 1: substitute <span> for html
- var re = /\033\[([\d;]+?)m(.*?)\033\[0m/g
- txt = txt.replace(re, "<span class='[[$1]]'>$2</span>")
- //Phase 2: substitute class in span with correct attributes
- re = /\[\[([\d;]+?)\]\]/
+ var re = /\033\[([\d;]+?)m/
+ var opened = false
while (re.test(txt)) {
- var match = re.exec(txt)
- var cmds = match[1].split(";")
- var reps = []
- for (var j in cmds)
- reps.push(attrib[cmds[j]])
- txt = txt.replace( match[0], reps.join(" ") )
+ var cmds = re.exec(txt)[1].split(";")
+ var close = opened?"</span>":""
+ opened = cmds[0] == "0"?false:true
+ var rep = []
+ for (var i in cmds)
+ rep.push(attrib[cmds[i]])
+ var open = rep.length > 0?"<span class=\""+rep.join(" ")+"\">":""
+ txt = txt.replace(re, close + open)
}
+ if (opened) txt += "</span>"
return txt
}
function comet() {
View
1 IPython/frontend/html/notebook.html
@@ -7,6 +7,7 @@
<style type="text/css">
pre, p { margin:0px; }
.cblue { color: blue }
+ .ccyan { color: teal }
.cgreen { color: green }
.cyellow { color: yellow }
.cred { color: red }

0 comments on commit 30d7333

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