From a7a78c11d4ab16a8bd6601350b94529aca01da0e Mon Sep 17 00:00:00 2001 From: Shawn Bruce Date: Thu, 8 Feb 2018 11:44:55 -0500 Subject: [PATCH] Terminal: Autoscroll Enhancements * Disable autoscroll when scrolling up. * Scroll to bottom when autoscroll is toggled to enable. --- .../static/js/app/viewmodels/terminal.js | 15 +++++++++++++++ src/octoprint/templates/tabs/terminal.jinja2 | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/octoprint/static/js/app/viewmodels/terminal.js b/src/octoprint/static/js/app/viewmodels/terminal.js index 09a9188ca..6ee6586ce 100644 --- a/src/octoprint/static/js/app/viewmodels/terminal.js +++ b/src/octoprint/static/js/app/viewmodels/terminal.js @@ -277,6 +277,17 @@ $(function() { } }; + self.terminalScrollEvent = _.throttle(function () { + if (self.autoscrollEnabled()) { + var container = self.fancyFunctionality() ? $("#terminal-output") : $("#terminal-output-lowfi"); + var maxScroll = container[0].scrollHeight - container[0].offsetHeight; + + if (container.scrollTop() <= maxScroll ) { + self.autoscrollEnabled(false); + } + } + }, 250); + self.gotoTerminalCommand = function() { // skip if user highlights text. var sel = getSelection().toString(); @@ -289,6 +300,10 @@ $(function() { self.toggleAutoscroll = function() { self.autoscrollEnabled(!self.autoscrollEnabled()); + + if (self.autoscrollEnabled()) { + self.updateOutput(); + } }; self.selectAll = function() { diff --git a/src/octoprint/templates/tabs/terminal.jinja2 b/src/octoprint/templates/tabs/terminal.jinja2 index df5762601..ba6c20482 100644 --- a/src/octoprint/templates/tabs/terminal.jinja2 +++ b/src/octoprint/templates/tabs/terminal.jinja2 @@ -1,5 +1,5 @@
-
+