Skip to content

Commit 3a97a89

Browse files
committed
Add command history
1 parent 38d50c8 commit 3a97a89

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

resources/assets/scripts/components/server/subpages/ConsolePage.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
ref="command"
1414
v-model="command"
1515
v-on:keyup.enter="sendCommand"
16+
v-on:keydown="handleArrowKey"
1617
>
1718
</div>
1819
</div>
@@ -53,13 +54,38 @@
5354
}
5455
}),
5556
command: '',
57+
commandHistory: [],
58+
commandHistoryIndex: -1,
5659
};
5760
},
5861
5962
methods: {
6063
sendCommand: function () {
64+
this.commandHistory.unshift(this.command);
6165
this.$parent.$emit('send-command', this.command);
6266
this.command = '';
67+
},
68+
69+
/**
70+
* Handle a user pressing up/down arrows when in the command field to scroll through thier
71+
* command history for this server.
72+
*
73+
* @param {KeyboardEvent} e
74+
*/
75+
handleArrowKey: function (e) {
76+
if (['ArrowUp', 'ArrowDown'].indexOf(e.key) < 0 || e.key === 'ArrowDown' && this.commandHistoryIndex < 0) {
77+
return;
78+
}
79+
80+
e.preventDefault();
81+
e.stopPropagation();
82+
83+
if (e.key === 'ArrowUp' && (this.commandHistoryIndex + 1 > (this.commandHistory.length - 1))) {
84+
return;
85+
}
86+
87+
this.commandHistoryIndex += (e.key === 'ArrowUp') ? 1 : -1;
88+
this.command = this.commandHistoryIndex < 0 ? '' : this.commandHistory[this.commandHistoryIndex];
6389
}
6490
}
6591
};

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const productionPlugins = [
6868

6969
module.exports = {
7070
mode: process.env.NODE_ENV,
71-
devtool: process.env.NODE_ENV === 'production' ? false : 'eval-source-map',
71+
devtool: process.env.NODE_ENV === 'production' ? false : 'inline-source-map',
7272
performance: {
7373
hints: false,
7474
},

0 commit comments

Comments
 (0)