Skip to content

Commit

Permalink
Debug output viewer tweaks
Browse files Browse the repository at this point in the history
- Decrease font size
- Do a better job of pinning to bottom
- Disable submit button when clearing output
- Filter ANSI color codes from slow lines
  • Loading branch information
dstillman committed Jul 25, 2017
1 parent eb1cecf commit e3947e7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion chrome/content/zotero/debugViewer.html
Expand Up @@ -55,7 +55,7 @@
margin-top: 38px;
padding: 10px 9px;
font-family: Monaco, Consolas, Inconsolata, monospace;
font-size: 9pt;
font-size: 8pt;
}

#errors {
Expand Down
24 changes: 15 additions & 9 deletions chrome/content/zotero/debugViewer.js
Expand Up @@ -3,8 +3,18 @@
var interval = 1000;
var intervalID;
var stopping = false;
var scrolling = false;
var autoscroll = true;

function start() {
// If scrolled to the bottom of the page, stay there
document.body.onscroll = function (event) {
if (!scrolling) {
autoscroll = atPageBottom();
}
scrolling = false;
};

updateErrors().then(function () {
if (stopping) return;

Expand All @@ -31,13 +41,9 @@ function updateErrors() {
var errors = Zotero.getErrors(true);
var errorStr = errors.length ? errors.join('\n\n') + '\n\n' : '';

var scroll = atPageBottom();

document.getElementById('errors').textContent = errorStr + sysInfo;

// TODO: This doesn't seem to work for some reason -- when errors are logged, it doesn't stay
// at the bottom
if (scroll) {
if (autoscroll) {
scrollToPageBottom();
}
});
Expand All @@ -50,15 +56,12 @@ function addInitialOutput() {
}

function addLine(line) {
var scroll = atPageBottom()

var p = document.createElement('p');
p.textContent = line;
var output = document.getElementById('output');
output.appendChild(p);

// If scrolled to the bottom of the page, stay there
if (scroll) {
if (autoscroll) {
scrollToPageBottom();
}

Expand All @@ -71,6 +74,8 @@ function atPageBottom() {
}

function scrollToPageBottom() {
// Set a flag when auto-scrolling to differentiate from manual scrolls
scrolling = true;
window.scrollTo(0, document.body.scrollHeight);
}

Expand Down Expand Up @@ -180,6 +185,7 @@ function clearSubmitStatus() {
}

function clearOutput(button) {
document.getElementById('submit-button').setAttribute('disabled', '');
button.setAttribute('disabled', '');
document.getElementById('output').textContent = '';
clearSubmitStatus();
Expand Down
7 changes: 7 additions & 0 deletions chrome/content/zotero/xpcom/debug.js
Expand Up @@ -151,6 +151,13 @@ Zotero.Debug = new function () {
}
// Console window
if (_consoleViewer) {
// Remove ANSI color codes. We could replace this with HTML, but it's probably
// unnecessarily distracting/alarming to show the red in the viewer. Devs who care
// about times should just use a terminal.
if (slowPrefix) {
output = output.replace(slowPrefix, '').replace(slowSuffix, '');
}

// If there's a listener, pass line immediately
if (_consoleViewerListener) {
_consoleViewerListener(output);
Expand Down

0 comments on commit e3947e7

Please sign in to comment.