Skip to content

Commit e99ac7a

Browse files
committed
Store the console output in a buffer for easier display
1 parent f9b8ddc commit e99ac7a

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
name: 'ServerConsole',
4343
mixins: [Socketio],
4444
computed: {
45-
...mapState('socket', ['connected']),
45+
...mapState('socket', ['connected', 'outputBuffer']),
4646
},
4747
4848
watch: {
@@ -65,7 +65,7 @@
6565
*/
6666
sockets: {
6767
'console output': function (line: string) {
68-
this.terminal && this.terminal.writeln(line.replace(/(?:\r\n|\r|\n)$/im, '') + '\u001b[0m');
68+
this.writeLineToConsole(line);
6969
},
7070
},
7171
@@ -101,6 +101,8 @@
101101
// @ts-ignore
102102
this.terminal.fit();
103103
this.terminal.clear();
104+
105+
this.outputBuffer.forEach(this.writeLineToConsole);
104106
},
105107
106108
/**
@@ -113,6 +115,10 @@
113115
this.command = '';
114116
},
115117
118+
writeLineToConsole: function (line: string) {
119+
this.terminal && this.terminal.writeln(line.replace(/(?:\r\n|\r|\n)$/im, '') + '\u001b[0m');
120+
},
121+
116122
/**
117123
* Handle a user pressing up/down arrows when in the command field to scroll through thier
118124
* command history for this server.

resources/assets/scripts/store/modules/socket.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default {
77
connected: false,
88
connectionError: false,
99
status: Status.STATUS_OFF,
10+
outputBuffer: [],
1011
},
1112
mutations: {
1213
SOCKET_CONNECT: (state: SocketState) => {
@@ -25,6 +26,22 @@ export default {
2526

2627
SOCKET_STATUS: (state: SocketState, data: string) => {
2728
state.status = data;
28-
}
29+
},
30+
31+
'SOCKET_CONSOLE OUTPUT': (state: SocketState, data: string) => {
32+
const { outputBuffer } = state;
33+
34+
if (outputBuffer.length >= 500) {
35+
// Pop all of the output buffer items off the front until we only have 499
36+
// items in the array.
37+
for (let i = 0; i <= (outputBuffer.length - 500); i++) {
38+
outputBuffer.shift();
39+
i++;
40+
}
41+
}
42+
43+
outputBuffer.push(data);
44+
state.outputBuffer = outputBuffer;
45+
},
2946
},
3047
};

resources/assets/scripts/store/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type SocketState = {
1212
connected: boolean,
1313
connectionError: boolean | Error,
1414
status: string,
15+
outputBuffer: string[],
1516
}
1617

1718
export type ServerApplicationCredentials = {

0 commit comments

Comments
 (0)