Skip to content

Commit 00a3d7d

Browse files
committed
Properly handle the console when the socket disconnects/reconnects
1 parent f20d404 commit 00a3d7d

File tree

1 file changed

+59
-38
lines changed
  • resources/assets/scripts/components/server/subpages

1 file changed

+59
-38
lines changed

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

Lines changed: 59 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<div>
33
<div class="text-xs font-mono">
44
<div class="rounded-t p-2 bg-black overflow-scroll w-full" style="min-height: 16rem;max-height:64rem;">
5-
<div v-if="!connected">
5+
<div class="mb-2 text-grey-light" ref="terminal" v-if="connected"></div>
6+
<div v-else>
67
<div class="spinner spinner-xl mt-24"></div>
78
</div>
8-
<div class="mb-2 text-grey-light" ref="terminal"></div>
99
</div>
1010
<div class="rounded-b bg-grey-darkest text-white flex">
1111
<div class="flex-no-shrink p-2">
@@ -45,13 +45,11 @@
4545
*/
4646
connected: function (state) {
4747
if (state) {
48-
this.terminal.open(this.$refs.terminal);
49-
this.terminal.fit();
50-
this.terminal.clear();
51-
52-
this.$socket.emit('send server log');
48+
this.$nextTick(() => {
49+
this.mountTerminal();
50+
});
5351
} else {
54-
this.terminal.dispose();
52+
this.terminal.clear();
5553
}
5654
},
5755
},
@@ -80,48 +78,34 @@
8078
*/
8179
mounted: function () {
8280
if (this.connected) {
83-
this.$socket.emit('send server log');
81+
this.mountTerminal();
8482
}
8583
},
8684
8785
data: function () {
8886
return {
89-
terminal: new Terminal({
90-
disableStdin: true,
91-
cursorStyle: 'underline',
92-
allowTransparency: true,
93-
fontSize: 12,
94-
fontFamily: 'Menlo,Monaco,Consolas,monospace',
95-
rows: 30,
96-
theme: {
97-
background: 'transparent',
98-
cursor: 'transparent',
99-
black: '#000000',
100-
red: '#E54B4B',
101-
green: '#9ECE58',
102-
yellow: '#FAED70',
103-
blue: '#396FE2',
104-
magenta: '#BB80B3',
105-
cyan: '#2DDAFD',
106-
white: '#d0d0d0',
107-
brightBlack: 'rgba(255, 255, 255, 0.2)',
108-
brightRed: '#FF5370',
109-
brightGreen: '#C3E88D',
110-
brightYellow: '#FFCB6B',
111-
brightBlue: '#82AAFF',
112-
brightMagenta: '#C792EA',
113-
brightCyan: '#89DDFF',
114-
brightWhite: '#ffffff',
115-
},
116-
117-
}),
87+
terminal: this._terminalInstance(),
11888
command: '',
11989
commandHistory: [],
12090
commandHistoryIndex: -1,
12191
};
12292
},
12393
12494
methods: {
95+
/**
96+
* Mount the terminal and grab the most recent server logs.
97+
*/
98+
mountTerminal: function () {
99+
// Get a new instance of the terminal setup.
100+
this.terminal = this._terminalInstance();
101+
102+
this.terminal.open(this.$refs.terminal);
103+
this.terminal.fit();
104+
this.terminal.clear();
105+
106+
this.$socket.emit('send server log');
107+
},
108+
125109
/**
126110
* Send a command to the server using the configured websocket.
127111
*/
@@ -152,6 +136,43 @@
152136
153137
this.commandHistoryIndex += (e.key === 'ArrowUp') ? 1 : -1;
154138
this.command = this.commandHistoryIndex < 0 ? '' : this.commandHistory[this.commandHistoryIndex];
139+
},
140+
141+
/**
142+
* Returns a new instance of the terminal to be used.
143+
*
144+
* @return {module:xterm.Terminal}
145+
* @private
146+
*/
147+
_terminalInstance() {
148+
return new Terminal({
149+
disableStdin: true,
150+
cursorStyle: 'underline',
151+
allowTransparency: true,
152+
fontSize: 12,
153+
fontFamily: 'Menlo, Monaco, Consolas, monospace',
154+
rows: 30,
155+
theme: {
156+
background: 'transparent',
157+
cursor: 'transparent',
158+
black: '#000000',
159+
red: '#E54B4B',
160+
green: '#9ECE58',
161+
yellow: '#FAED70',
162+
blue: '#396FE2',
163+
magenta: '#BB80B3',
164+
cyan: '#2DDAFD',
165+
white: '#d0d0d0',
166+
brightBlack: 'rgba(255, 255, 255, 0.2)',
167+
brightRed: '#FF5370',
168+
brightGreen: '#C3E88D',
169+
brightYellow: '#FFCB6B',
170+
brightBlue: '#82AAFF',
171+
brightMagenta: '#C792EA',
172+
brightCyan: '#89DDFF',
173+
brightWhite: '#ffffff',
174+
},
175+
});
155176
}
156177
}
157178
};

0 commit comments

Comments
 (0)