diff --git a/src/app/panels/terminal.js b/src/app/panels/terminal.js
index c5215a0362..b3a2f9329a 100644
--- a/src/app/panels/terminal.js
+++ b/src/app/panels/terminal.js
@@ -189,6 +189,7 @@ class Terminal {
self._view.input = yo`
`
+ self._view.input.innerText = '\n'
self._view.cli = yo`
${'>'}
@@ -397,19 +398,44 @@ class Terminal {
self.event.trigger('resize', [self._api.getPosition(event)])
}
+ self._cmdHistory = []
+ self._cmdTemp = ''
+
return self._view.el
function change (event) {
+ if (self._view.input.innerText.length === 0) self._view.input.innerText += '\n'
if (event.which === 13) {
if (event.ctrlKey) { //
- self._view.input.appendChild(document.createElement('br'))
- self.scroll2bottom()
+ self._view.input.innerText += '\n'
putCursor2End(self._view.input)
+ self.scroll2bottom()
} else { //
event.preventDefault()
- self.commands.script(self._view.input.innerText)
- self._view.input.innerHTML = ''
+ var script = self._view.input.innerText.trim()
+ self._view.input.innerText = '\n'
+ if (script.length) {
+ self._cmdHistory.push('\n' + script)
+ self.commands.script(script)
+ }
}
+ } else if (event.which === 38) { //
+ var len = self._cmdHistory.length
+ if (len === 0) return event.preventDefault()
+ if (self._cmdIndex === undefined) {
+ self._cmdIndex = len - 1
+ self._cmdTemp = self._view.input.innerText
+ } else if (self._cmdIndex === 0) return
+ else self._cmdIndex -= 1
+ self._view.input.innerText = self._cmdHistory[self._cmdIndex]
+ self.scroll2bottom()
+ } else if (event.which === 40) { //
+ if (self._cmdIndex === undefined) return
+ else if (self._cmdIndex === self._cmdHistory.length - 1) self._cmdIndex = undefined
+ else self._cmdIndex += 1
+ self._view.input.innerText = self._cmdHistory[self._cmdIndex] || self._cmdTemp
+ putCursor2End(self._view.input)
+ self.scroll2bottom()
}
}
function putCursor2End (editable) {