Store the console output in a buffer for easier display
This commit is contained in:
parent
f9b8ddc917
commit
e99ac7abe8
|
@ -42,7 +42,7 @@
|
||||||
name: 'ServerConsole',
|
name: 'ServerConsole',
|
||||||
mixins: [Socketio],
|
mixins: [Socketio],
|
||||||
computed: {
|
computed: {
|
||||||
...mapState('socket', ['connected']),
|
...mapState('socket', ['connected', 'outputBuffer']),
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
*/
|
*/
|
||||||
sockets: {
|
sockets: {
|
||||||
'console output': function (line: string) {
|
'console output': function (line: string) {
|
||||||
this.terminal && this.terminal.writeln(line.replace(/(?:\r\n|\r|\n)$/im, '') + '\u001b[0m');
|
this.writeLineToConsole(line);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -101,6 +101,8 @@
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.terminal.fit();
|
this.terminal.fit();
|
||||||
this.terminal.clear();
|
this.terminal.clear();
|
||||||
|
|
||||||
|
this.outputBuffer.forEach(this.writeLineToConsole);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,6 +115,10 @@
|
||||||
this.command = '';
|
this.command = '';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
writeLineToConsole: function (line: string) {
|
||||||
|
this.terminal && this.terminal.writeln(line.replace(/(?:\r\n|\r|\n)$/im, '') + '\u001b[0m');
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle a user pressing up/down arrows when in the command field to scroll through thier
|
* Handle a user pressing up/down arrows when in the command field to scroll through thier
|
||||||
* command history for this server.
|
* command history for this server.
|
||||||
|
|
|
@ -7,6 +7,7 @@ export default {
|
||||||
connected: false,
|
connected: false,
|
||||||
connectionError: false,
|
connectionError: false,
|
||||||
status: Status.STATUS_OFF,
|
status: Status.STATUS_OFF,
|
||||||
|
outputBuffer: [],
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
SOCKET_CONNECT: (state: SocketState) => {
|
SOCKET_CONNECT: (state: SocketState) => {
|
||||||
|
@ -25,6 +26,22 @@ export default {
|
||||||
|
|
||||||
SOCKET_STATUS: (state: SocketState, data: string) => {
|
SOCKET_STATUS: (state: SocketState, data: string) => {
|
||||||
state.status = data;
|
state.status = data;
|
||||||
}
|
},
|
||||||
|
|
||||||
|
'SOCKET_CONSOLE OUTPUT': (state: SocketState, data: string) => {
|
||||||
|
const { outputBuffer } = state;
|
||||||
|
|
||||||
|
if (outputBuffer.length >= 500) {
|
||||||
|
// Pop all of the output buffer items off the front until we only have 499
|
||||||
|
// items in the array.
|
||||||
|
for (let i = 0; i <= (outputBuffer.length - 500); i++) {
|
||||||
|
outputBuffer.shift();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
outputBuffer.push(data);
|
||||||
|
state.outputBuffer = outputBuffer;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,6 +12,7 @@ export type SocketState = {
|
||||||
connected: boolean,
|
connected: boolean,
|
||||||
connectionError: boolean | Error,
|
connectionError: boolean | Error,
|
||||||
status: string,
|
status: string,
|
||||||
|
outputBuffer: string[],
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ServerApplicationCredentials = {
|
export type ServerApplicationCredentials = {
|
||||||
|
|
Loading…
Reference in New Issue