Skip to content

Commit

Permalink
0.1.1
Browse files Browse the repository at this point in the history
added command history
added shift+enter
  • Loading branch information
jneilliii committed May 22, 2020
1 parent 88c7b73 commit 05336a8
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Multi Line Terminal

This plugin simply replaces the single line gcode input into a multi-line text area. Once installed you will have to use the Send button instead of the Enter key to send the commands to your printer.
This plugin simply replaces the single line gcode input into a multi-line text area. Once installed you can use the Send button or shift+enter to send the gcode commands to your printer.

![screenshot](screenshot.png)

Expand Down
2 changes: 1 addition & 1 deletion octoprint_multilineterminal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_update_information(self):
current=self._plugin_version,

# update method: pip
pip="https://github.com/jneilliii/OctoPrint-MultiLineTerminal/archive/{target_version}.zip"
pip="https://github.com/jneilliii/OctoPrint-MultiLineTerminal/releases/download/{target_version}/{target_version}.zip"
)
)

Expand Down
31 changes: 28 additions & 3 deletions octoprint_multilineterminal/static/css/multilineterminal.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
textarea#terminal-command {
margin-bottom: 0px;
border-right: 0px;
-webkit-border-radius: 0px 0 0 0px;
-moz-border-radius: 0px 0 0 0px;
border-radius: 0px 0 0 0px;
resize: vertical;
}

a#terminal-send {
vertical-align: middle;
}

span#multilinehistorybuttons {
-webkit-border-radius: 4px 0 0 4px;
-moz-border-radius: 4px 0 0 4px;
border-radius: 4px 0 0 4px;
resize: vertical;
padding: 0px 0px;
vertical-align: middle;
}

a#terminal-send {
span#multilinehistorybuttons > a {
width: 100%;
display: block;
color: black;
text-decoration: none;
cursor: pointer;
vertical-align: middle;
}
}

span#multilinehistorybuttons > a:last-child {
padding-top: 10px;
}

span#multilinehistorybuttons > a:first-child {
padding-bottom: 10px;
}
32 changes: 30 additions & 2 deletions octoprint_multilineterminal/static/js/multilineterminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,39 @@ $(function() {
return;
}

OctoPrint.control.sendGcode(command.split("\n"));
OctoPrint.control.sendGcode(command.split("\n"))
.done(function() {
self.terminalViewModel.cmdHistory.push(command);
self.terminalViewModel.cmdHistory.slice(-300); // just to set a sane limit to how many manually entered commands will be saved...
self.terminalViewModel.cmdHistoryIdx = self.terminalViewModel.cmdHistory.length;
self.terminalViewModel.command("");
});
};

self.terminalViewModel.getHistoryMultiLine = function(direction) {
if (direction == 1 || direction == -1) {
if (direction == 1 && self.terminalViewModel.cmdHistory.length > 0 && self.terminalViewModel.cmdHistoryIdx > 0) {
self.terminalViewModel.cmdHistoryIdx--;
} else if (direction == -1 && self.terminalViewModel.cmdHistoryIdx < self.terminalViewModel.cmdHistory.length - 1) {
self.terminalViewModel.cmdHistoryIdx++;
}

if (self.terminalViewModel.cmdHistoryIdx >= 0 && self.terminalViewModel.cmdHistoryIdx < self.terminalViewModel.cmdHistory.length) {
self.terminalViewModel.command(self.terminalViewModel.cmdHistory[self.terminalViewModel.cmdHistoryIdx]);
}
}
}

self.terminalViewModel.handleKeyUpMultiLine = function(e){
if (event.shiftKey && event.keyCode === 13) {
$('#terminal-send').trigger('click');
}
// do not prevent default action
return true;
};

self.onStartup = function(){
$('#terminal-command').replaceWith('<textarea rows="4" class="input input-block-level" id="terminal-command" data-bind="value: command, event: { keyup: function(d,e) { return handleKeyUp(e); }, keydown: function(d,e) { return handleKeyDown(e); } }, enable: isOperational() && loginState.isUser()"/>');
$('#terminal-command').replaceWith('<span class="add-on" id="multilinehistorybuttons"><a class="icon icon-arrow-up" data-bind="click: function(){getHistoryMultiLine(1);}, enable: isOperational() && loginState.isUser()"></a><a class="icon icon-arrow-down" data-bind="click: function(){getHistoryMultiLine(-1);}, enable: isOperational() && loginState.isUser()"></a></span><textarea rows="4" class="input input-block-level" id="terminal-command" data-bind="textInput: command, event: { keyup: function(d,e) { return handleKeyUpMultiLine(e); } }, enable: isOperational() && loginState.isUser()"/>').parent('div').addClass('input prepend');
$('#terminal-send').attr('data-bind','click: sendCommandMultiLine, enable: isOperational() && loginState.isUser()');
}
}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "Multi Line Terminal"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "0.1.0"
plugin_version = "0.1.1"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit 05336a8

Please sign in to comment.