From 3b4936b6f2b870f9f2444ebb6ce1ca2de3f49d9f Mon Sep 17 00:00:00 2001
From: Daniel Baumann <daniel.baumann@progress-linux.org>
Date: Fri, 19 Apr 2024 04:54:31 +0200
Subject: Adding upstream version 1.7.4.

Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
---
 html/src/components/terminal/index.tsx | 59 ++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 html/src/components/terminal/index.tsx

(limited to 'html/src/components/terminal/index.tsx')

diff --git a/html/src/components/terminal/index.tsx b/html/src/components/terminal/index.tsx
new file mode 100644
index 0000000..a7349fd
--- /dev/null
+++ b/html/src/components/terminal/index.tsx
@@ -0,0 +1,59 @@
+import { bind } from 'decko';
+import { Component, h } from 'preact';
+import { Xterm, XtermOptions } from './xterm';
+
+import 'xterm/css/xterm.css';
+import { Modal } from '../modal';
+
+interface Props extends XtermOptions {
+    id: string;
+}
+
+interface State {
+    modal: boolean;
+}
+
+export class Terminal extends Component<Props, State> {
+    private container: HTMLElement;
+    private xterm: Xterm;
+
+    constructor(props: Props) {
+        super();
+        this.xterm = new Xterm(props, this.showModal);
+    }
+
+    async componentDidMount() {
+        await this.xterm.refreshToken();
+        this.xterm.open(this.container);
+        this.xterm.connect();
+    }
+
+    componentWillUnmount() {
+        this.xterm.dispose();
+    }
+
+    render({ id }: Props, { modal }: State) {
+        return (
+            <div id={id} ref={c => (this.container = c as HTMLElement)}>
+                <Modal show={modal}>
+                    <label class="file-label">
+                        <input onChange={this.sendFile} class="file-input" type="file" multiple />
+                        <span class="file-cta">Choose files…</span>
+                    </label>
+                </Modal>
+            </div>
+        );
+    }
+
+    @bind
+    showModal() {
+        this.setState({ modal: true });
+    }
+
+    @bind
+    sendFile(event: Event) {
+        this.setState({ modal: false });
+        const files = (event.target as HTMLInputElement).files;
+        if (files) this.xterm.sendFile(files);
+    }
+}
-- 
cgit v1.2.3

