Skip to content

Commit

Permalink
Partially fix "fixConsole" function which was breaking on some outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgao committed Oct 21, 2010
1 parent ddffe2b commit 30d7333
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion IPython/frontend/html/ipythonhttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
26 changes: 12 additions & 14 deletions IPython/frontend/html/js/notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions IPython/frontend/html/notebook.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 30d7333

Please sign in to comment.