|
2 | 2 | <div> |
3 | 3 | <div class="text-xs font-mono"> |
4 | 4 | <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> |
6 | 7 | <div class="spinner spinner-xl mt-24"></div> |
7 | 8 | </div> |
8 | | - <div class="mb-2 text-grey-light" ref="terminal"></div> |
9 | 9 | </div> |
10 | 10 | <div class="rounded-b bg-grey-darkest text-white flex"> |
11 | 11 | <div class="flex-no-shrink p-2"> |
|
45 | 45 | */ |
46 | 46 | connected: function (state) { |
47 | 47 | 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 | + }); |
53 | 51 | } else { |
54 | | - this.terminal.dispose(); |
| 52 | + this.terminal.clear(); |
55 | 53 | } |
56 | 54 | }, |
57 | 55 | }, |
|
80 | 78 | */ |
81 | 79 | mounted: function () { |
82 | 80 | if (this.connected) { |
83 | | - this.$socket.emit('send server log'); |
| 81 | + this.mountTerminal(); |
84 | 82 | } |
85 | 83 | }, |
86 | 84 |
|
87 | 85 | data: function () { |
88 | 86 | 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(), |
118 | 88 | command: '', |
119 | 89 | commandHistory: [], |
120 | 90 | commandHistoryIndex: -1, |
121 | 91 | }; |
122 | 92 | }, |
123 | 93 |
|
124 | 94 | 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 | +
|
125 | 109 | /** |
126 | 110 | * Send a command to the server using the configured websocket. |
127 | 111 | */ |
|
152 | 136 |
|
153 | 137 | this.commandHistoryIndex += (e.key === 'ArrowUp') ? 1 : -1; |
154 | 138 | 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 | + }); |
155 | 176 | } |
156 | 177 | } |
157 | 178 | }; |
|
0 commit comments