Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobicloudvision committed Apr 22, 2024
1 parent d9e474e commit ccbc10a
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 25 deletions.
2 changes: 1 addition & 1 deletion web/resources/js/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import './bootstrap';

import { Terminal } from '@xterm/xterm';

63 changes: 63 additions & 0 deletions web/resources/js/web-terminal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import '@xterm/xterm/css/xterm.css';
import { Terminal } from '@xterm/xterm';
import { WebglAddon } from '@xterm/addon-webgl';
import { CanvasAddon } from '@xterm/addon-canvas';
import { FitAddon } from '@xterm/addon-fit';

let terminalElement = document.getElementById('js-web-terminal');
if (terminalElement !== null) {

const terminal = new Terminal({
allowTransparency: true,
theme: {
background: '#09090b',
foreground: '#cccccc',
selectionBackground: '#399ef440',
black: '#666666',
blue: '#399ef4',
brightBlack: '#666666',
brightBlue: '#399ef4',
brightCyan: '#21c5c7',
brightGreen: '#4eb071',
brightMagenta: '#b168df',
brightRed: '#da6771',
brightWhite: '#efefef',
brightYellow: '#fff099',
cyan: '#21c5c7',
green: '#4eb071',
magenta: '#b168df',
red: '#da6771',
white: '#efefef',
yellow: '#fff099'
}
});

if (typeof WebGL2RenderingContext !== 'undefined') {
terminal.loadAddon(new WebglAddon());
} else {
terminal.loadAddon(new CanvasAddon());
}

const fitAddon = new FitAddon();
terminal.loadAddon(fitAddon);

terminal.open(terminalElement);

fitAddon.fit();

const socket = new WebSocket(`ws://49.13.166.115:3311`);
socket.addEventListener('open', (_) => {
terminal.onData((data) => socket.send(data));
socket.addEventListener('message', (evt) => terminal.write(evt.data));
});
socket.addEventListener('error', (_) => {
terminal.reset();
terminal.writeln('Connection error.');
});
socket.addEventListener('close', (evt) => {
if (evt.wasClean) {
terminal.reset();
terminal.writeln(evt.reason ?? 'Connection closed.');
}
});
}
25 changes: 2 additions & 23 deletions web/resources/views/filament/pages/terminal.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,9 @@

<div>

<div id="js-web-terminal"></div>

<script>
@vite('resources/js/web-terminal.js')

const terminal = new Terminal();
terminal.open(document.getElementById('js-web-terminal'));
//terminal.resize(160, 30);
const socket = new WebSocket(`ws://49.13.166.115:3311`);
socket.addEventListener('open', (_) => {
terminal.onData((data) => socket.send(data));
socket.addEventListener('message', (evt) => terminal.write(evt.data));
});
socket.addEventListener('error', (_) => {
terminal.reset();
terminal.writeln('Connection error.');
});
socket.addEventListener('close', (evt) => {
if (evt.wasClean) {
terminal.reset();
terminal.writeln(evt.reason ?? 'Connection closed.');
}
});
</script>
<div id="js-web-terminal"></div>

</div>

Expand Down
6 changes: 5 additions & 1 deletion web/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import laravel, { refreshPaths } from 'laravel-vite-plugin'
export default defineConfig({
plugins: [
laravel({
input: ['resources/css/app.css', 'resources/js/app.js'],
input: [
'resources/css/app.css',
'resources/js/app.js',
'resources/js/web-terminal.js',
],
refresh: [
...refreshPaths,
'app/Livewire/**',
Expand Down

0 comments on commit ccbc10a

Please sign in to comment.