Skip to content

Commit a94c6d8

Browse files
committed
Add xterm for console support (holy shit this is speedy)
1 parent c2ebf1c commit a94c6d8

File tree

5 files changed

+576
-32
lines changed

5 files changed

+576
-32
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "pterodactyl-panel",
33
"dependencies": {
4+
"cssnano": "^4.0.3",
45
"date-fns": "^1.29.0",
56
"socket.io-client": "^2.1.1",
67
"vee-validate": "^2.1.0-beta.2",
@@ -9,7 +10,8 @@
910
"vue-router": "^3.0.1",
1011
"vuex": "^3.0.1",
1112
"vuex-i18n": "^1.10.5",
12-
"vuex-router-sync": "^5.0.0"
13+
"vuex-router-sync": "^5.0.0",
14+
"xterm": "^3.5.1"
1315
},
1416
"devDependencies": {
1517
"@babel/core": "^7.0.0-beta.49",

resources/assets/scripts/components/server/Server.vue

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
</router-link>
5656
</div>
5757
</div>
58-
<div class="bg-white p-6 rounded border border-grey-light h-full">
58+
<div class="bg-white p-6 rounded border border-grey-light h-full w-full">
5959
<router-view></router-view>
6060
</div>
6161
</div>
@@ -83,6 +83,10 @@
8383
8484
mounted: function () {
8585
this.loadServer();
86+
87+
this.$on('send-command', data => {
88+
this.socket.emit('send command', data);
89+
});
8690
},
8791
8892
data: function () {
@@ -109,7 +113,6 @@
109113
},
110114
111115
initalizeWebsocket: function () {
112-
this.$store.commit('server/CONSOLE_DATA', 'Connecting to ' + this.credentials.node + '...');
113116
this.socket = io(this.credentials.node + '/v1/ws/' + this.server.uuid, {
114117
query: 'token=' + this.credentials.key,
115118
});
@@ -123,34 +126,29 @@
123126
},
124127
125128
_socket_error: function (err) {
126-
this.$store.commit('server/CONSOLE_DATA', 'There was a socket error: ' + err);
127129
console.error('there was a socket error:', err);
128130
},
129131
130132
_socket_connect: function () {
131-
this.$store.commit('server/CONSOLE_DATA', 'Connected to socket.');
132133
this.socket.emit('send server log');
133-
console.log('connected');
134134
},
135135
136136
_socket_status: function (data) {
137-
this.$store.commit('server/CONSOLE_DATA', 'Server state has changed.');
138-
console.warn(data);
139137
},
140138
141139
_socket_serverLog: function (data) {
142140
data.split(/\n/g).forEach(item => {
143-
this.$store.commit('server/CONSOLE_DATA', item);
141+
this.$emit('console', item);
144142
});
145143
},
146144
147145
_socket_consoleLine: function (data) {
148146
if(data.line) {
149-
data.line.split(/\n/g).forEach((item) => {
150-
this.$store.commit('server/CONSOLE_DATA', item);
147+
data.line.split(/\n/g).forEach(item => {
148+
this.$emit('console', item);
151149
});
152150
}
153-
}
151+
},
154152
},
155153
}
156154
</script>
Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,68 @@
11
<template>
22
<div>
33
<div class="text-xs font-mono">
4-
<div class="rounded-t p-2 bg-black overflow-scroll w-full" style="min-height: 16rem;max-height:32rem;">
5-
<div class="mb-2">
6-
<span class="block text-grey-light" v-for="line in console" v-text="line"></span>
7-
</div>
4+
<div class="rounded-t p-2 bg-black overflow-scroll w-full" style="min-height: 16rem;max-height:64rem;">
5+
<div class="mb-2 text-grey-light" ref="terminal"></div>
86
</div>
97
<div class="rounded-b bg-grey-darkest text-white flex">
108
<div class="flex-no-shrink p-2">
119
<span class="font-bold">$</span>
1210
</div>
1311
<div class="w-full">
14-
<input type="text" aria-label="Send console command" class="bg-transparent text-white p-2 pl-0 w-full" placeholder="enter command and press enter to send">
12+
<input type="text" aria-label="Send console command" class="bg-transparent text-white p-2 pl-0 w-full" placeholder="enter command and press enter to send"
13+
ref="command"
14+
v-model="command"
15+
v-on:keyup.enter="sendCommand"
16+
>
1517
</div>
1618
</div>
1719
</div>
1820
</div>
1921
</template>
2022

2123
<script>
22-
import {mapState} from 'vuex';
24+
import { Terminal } from 'xterm';
25+
import * as TerminalFit from 'xterm/lib/addons/fit/fit';
26+
27+
Terminal.applyAddon(TerminalFit);
2328
2429
export default {
2530
name: 'console-page',
2631
27-
computed: {
28-
...mapState('server', ['console']),
32+
mounted: function () {
33+
this.terminal.open(this.$refs.terminal);
34+
this.terminal.fit();
35+
36+
this.$parent.$on('console', data => {
37+
this.terminal.writeln(data);
38+
});
2939
},
40+
41+
data: function () {
42+
return {
43+
terminal: new Terminal({
44+
disableStdin: true,
45+
allowTransparency: true,
46+
fontSize: 12,
47+
fontFamily: 'Menlo,Monaco,Consolas,monospace',
48+
rows: 30,
49+
theme: {
50+
background: 'transparent',
51+
}
52+
}),
53+
command: '',
54+
};
55+
},
56+
57+
methods: {
58+
sendCommand: function () {
59+
this.$parent.$emit('send-command', this.command);
60+
this.command = '';
61+
}
62+
}
3063
};
3164
</script>
65+
66+
<style lang="postcss">
67+
@import "~xterm/src/xterm.css";
68+
</style>

tailwind.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,4 +916,8 @@ module.exports = {
916916
separator: ':',
917917
},
918918

919+
experiments: {
920+
shadowLookup: true,
921+
},
922+
919923
};

0 commit comments

Comments
 (0)