Skip to content

Commit

Permalink
Merge branch 'stormandco-highlight-traceback'
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Feb 21, 2016
2 parents 7edf2cf + aca0586 commit cd6c78e
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 85 deletions.
2 changes: 1 addition & 1 deletion aiohttp_debugtoolbar/panels/templates/routes.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>
</div>
<div class="collapse" id="collapseSource{{ loop.index }}">
<pre><code class="python">{{ route_info['source'] }}</code></pre>
<pre><code class="language-python">{{ route_info['source'] }}</code></pre>
</div>
</td>
</tr>
Expand Down
12 changes: 9 additions & 3 deletions aiohttp_debugtoolbar/static/css/debugger.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

/* TODO: cleanup unused styles */
input { background-color: #fff; margin: 0; text-align: left;
outline: none !important; }
pre, code, table.source,
Expand Down Expand Up @@ -80,7 +80,7 @@ pre.console div.traceback pre.syntaxerror { background: #eeeeee; border: none;
pre.console div.noframe-traceback pre.syntaxerror { margin-top: 0px; border: none; }

pre.console div.box pre.repr { padding: 0; margin: 0; background-color: white; border: none; }
pre.console div.box table { margin-top: 6px; }
pre.console div.box table { margin-top: 6px; }
pre.console div.box pre { border: none; }
pre.console div.box pre.help { background-color: white; }
pre.console div.box pre.help:hover { cursor: default; }
Expand All @@ -98,4 +98,10 @@ div.box table.source tr.current { background-color: #dddddd; color: #e5762b; }
div.sourceview { overflow: auto; border: 1px solid #ccc; }

div.traceback .btn { margin: 1px 4px 1px 0; }
div.traceback span, div.explanation span { margin: 2px; }
div.traceback span, div.explanation span { margin: 2px; }

div.sourceview span.current {
display: inline-block;
width: 100%;
background-color: #ddd;
}
226 changes: 226 additions & 0 deletions aiohttp_debugtoolbar/static/css/prism.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+git+python+sql&plugins=line-highlight+line-numbers */
/**
* prism.js default theme for JavaScript, CSS and HTML
* Based on dabblet (http://dabblet.com)
* @author Lea Verou
*/

code[class*="language-"],
pre[class*="language-"] {
color: black;
text-shadow: 0 1px white;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
direction: ltr;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;

-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;

-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}

pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
text-shadow: none;
background: #b3d4fc;
}

pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
code[class*="language-"]::selection, code[class*="language-"] ::selection {
text-shadow: none;
background: #b3d4fc;
}

@media print {
code[class*="language-"],
pre[class*="language-"] {
text-shadow: none;
}
}

/* Code blocks */
pre[class*="language-"] {
padding: 1em;
margin: .5em 0;
overflow: auto;
}

:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background: #f5f2f0;
}

/* Inline code */
:not(pre) > code[class*="language-"] {
padding: .1em;
border-radius: .3em;
white-space: normal;
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: slategray;
}

.token.punctuation {
color: #999;
}

.namespace {
opacity: .7;
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
color: #905;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
color: #690;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
color: #a67f59;
background: hsla(0, 0%, 100%, .5);
}

.token.atrule,
.token.attr-value,
.token.keyword {
color: #07a;
}

.token.function {
color: #DD4A68;
}

.token.regex,
.token.important,
.token.variable {
color: #e90;
}

.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}

.token.entity {
cursor: help;
}

pre[data-line] {
position: relative;
padding: 1em 0 1em 3em;
}

.line-highlight {
position: absolute;
left: 0;
right: 0;
padding: inherit 0;
margin-top: 1em; /* Same as .prism’s padding-top */

background: hsla(24, 20%, 50%,.08);
background: -moz-linear-gradient(left, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
background: -webkit-linear-gradient(left, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
background: -o-linear-gradient(left, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
background: linear-gradient(left, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));

pointer-events: none;

line-height: inherit;
white-space: pre;
}

.line-highlight:before,
.line-highlight[data-end]:after {
content: attr(data-start);
position: absolute;
top: .4em;
left: .6em;
min-width: 1em;
padding: 0 .5em;
background-color: hsla(24, 20%, 50%,.4);
color: hsl(24, 20%, 95%);
font: bold 65%/1.5 sans-serif;
text-align: center;
vertical-align: .3em;
border-radius: 999px;
text-shadow: none;
box-shadow: 0 1px white;
}

.line-highlight[data-end]:after {
content: attr(data-end);
top: auto;
bottom: .4em;
}
pre.line-numbers {
position: relative;
padding-left: 3.8em;
counter-reset: linenumber;
}

pre.line-numbers > code {
position: relative;
}

.line-numbers .line-numbers-rows {
position: absolute;
pointer-events: none;
top: 0;
font-size: 100%;
left: -3.8em;
width: 3em; /* works for line-numbers below 1000 lines */
letter-spacing: -1px;
border-right: 1px solid #999;

-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;

}

.line-numbers-rows > span {
pointer-events: none;
display: block;
counter-increment: linenumber;
}

.line-numbers-rows > span:before {
content: counter(linenumber);
color: #999;
display: block;
padding-right: 0.8em;
text-align: right;
}
56 changes: 38 additions & 18 deletions aiohttp_debugtoolbar/static/js/debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ pyramid_debugtoolbar_require([
*/
if (EVALEX)
$('<button class="btn btn-xs btn-default pull-right">' +
'<span class="glyphicon glyphicon-console pull-right" aria-hidden="true"></span></button>')
'<span class="glyphicon glyphicon-console pull-right" ' +
'aria-hidden="true"></span></button>')
.attr('title', 'Open an interactive python shell in this frame')
.click(function() {
consoleNode = openShell(consoleNode, target, frameID);
Expand All @@ -45,29 +46,48 @@ pyramid_debugtoolbar_require([
* Show sourcecode
*/
var sourceButton = $('<button class="btn btn-xs btn-default pull-right">' +
'<span class="glyphicon glyphicon-file pull-right" aria-hidden="true"></span></button>')
'<span class="glyphicon glyphicon-file pull-right" ' +
'aria-hidden="true"></span></button>')
.attr('title', 'Display the sourcecode for this frame')
.click(function() {
.click(function () {
if (!sourceView)
$('h2', sourceView =
$('<div class="box"><h2>View Source</h2><div class="sourceview">' +
'<table></table></div>')
'<pre></pre></div>')
.insertBefore('div.explanation'))
.css('cursor', 'pointer')
.click(function() {
.click(function () {
sourceView.slideUp('fast');
});
$.get(window.DEBUG_TOOLBAR_ROOT_PATH + '/source',
{frm: frameID, token: window.DEBUGGER_TOKEN}, function(data) {
$('table', sourceView)
.replaceWith(data);
if (!sourceView.is(':visible'))
sourceView.slideDown('fast', function() {
$.get(window.DEBUG_TOOLBAR_ROOT_PATH + '/source',
{frm: frameID, token: window.DEBUGGER_TOKEN}, function (data) {
var dataLine;
var inFrame = data.inFrame;
inFrame[0]++;
if (inFrame !== null && inFrame[0] !== inFrame[1]) {
dataLine = '' + inFrame[0] + '-' + (inFrame[1]);
//if (data.line !== inFrame[0] && data.line !== inFrame[1]) {
dataLine += (',' + data.line);
//}
} else {
dataLine = '' + data.line
}
var code = '<pre data-line="' + dataLine + '"><code id="pDebugTracebackSrc"' +
'class="language-python">'
+ data.source + '</code></pre>';

$('pre', sourceView)
.replaceWith(code);

Prism.highlightElement(document.querySelector('#pDebugTracebackSrc'));

if (!sourceView.is(':visible'))
sourceView.slideDown('fast', function () {
focusSourceBlock();
});
else
focusSourceBlock();
});
else
focusSourceBlock();
});
});
return false;
})
.prependTo(target);
Expand Down Expand Up @@ -187,15 +207,15 @@ pyramid_debugtoolbar_require([
* Focus the current block in the source view.
*/
function focusSourceBlock() {
var tmp, line = $('table.source tr.current');
var tmp, line = $('pre code .line-highlight');
for (var i = 0; i < 7; i++) {
tmp = line.prev();
if (!(tmp && tmp.is('.in-frame')))
break
break;
line = tmp;
}
var container = $('div.sourceview');
container.scrollTop(line.offset().top);
$('html, body').scrollTop(line.offset().top);
}
});
$.noConflict(true);
Expand Down
Loading

0 comments on commit cd6c78e

Please sign in to comment.