Browse Source

horrible hacks

master
eta 1 year ago
parent
commit
4cc31f95c5
  1. 1
      html/package.json
  2. 9
      html/src/components/app.tsx
  3. 36
      html/src/components/terminal/index.tsx
  4. 20264
      src/html.h

1
html/package.json

@ -54,6 +54,7 @@ @@ -54,6 +54,7 @@
"xterm-addon-fit": "^0.5.0",
"xterm-addon-web-links": "^0.4.0",
"xterm-addon-webgl": "^0.11.3",
"xterm-addon-unicode11": "^0.3.0",
"zmodem.js": "^0.1.10"
}
}

9
html/src/components/app.tsx

@ -56,4 +56,13 @@ export class App extends Component { @@ -56,4 +56,13 @@ export class App extends Component {
/>
);
}
componentDidMount() {
console.log("notification permissions: " + Notification.permission);
if (Notification.permission === "default") {
console.log("requesting permissions");
Notification.requestPermission(function (permission) {
console.log("permission request result: " + permission);
});
}
}
}

36
html/src/components/terminal/index.tsx

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
import { bind } from 'decko';
import { Component, h } from 'preact';
import { ITerminalOptions, Terminal } from 'xterm';
import { Unicode11Addon } from 'xterm-addon-unicode11';
import { FitAddon } from 'xterm-addon-fit';
import { WebglAddon } from 'xterm-addon-webgl';
import { WebLinksAddon } from 'xterm-addon-web-links';
@ -85,6 +86,25 @@ export class Xterm extends Component<Props> { @@ -85,6 +86,25 @@ export class Xterm extends Component<Props> {
window.addEventListener('resize', this.onWindowResize);
window.addEventListener('beforeunload', this.onWindowUnload);
console.log("adding listener?");
this.terminal.element.addEventListener('paste', () => {
console.log("fired?");
/*
var items = event.clipboardData.items;
console.log(JSON.stringify(items)); // might give you mime types
for (var index in items) {
var item = items[index];
if (item.kind === 'file') {
var blob = item.getAsFile();
var reader = new FileReader();
reader.onload = function (event) {
console.log(event.target.result); // data url!
};
reader.readAsDataURL(blob);
}
}
*/
});
}
componentWillUnmount() {
@ -176,6 +196,9 @@ export class Xterm extends Component<Props> { @@ -176,6 +196,9 @@ export class Xterm extends Component<Props> {
terminal.loadAddon(overlayAddon);
terminal.loadAddon(new WebLinksAddon());
terminal.loadAddon(this.zmodemAddon);
terminal.loadAddon(new Unicode11Addon());
terminal.unicode.activeVersion = '11';
terminal.onTitleChange(data => {
if (data && data !== '' && !this.titleFixed) {
@ -184,6 +207,19 @@ export class Xterm extends Component<Props> { @@ -184,6 +207,19 @@ export class Xterm extends Component<Props> {
});
terminal.onData(this.onTerminalData);
terminal.onResize(this.onTerminalResize);
terminal.parser.registerDcsHandler({prefix: "?", final: "a"}, (data, _) => {
let text = atob(data);
console.log("[ttyd] got notification escape sequence: " + text);
try {
let parsed = JSON.parse(text);
new Notification(parsed.title, parsed);
return true;
}
catch (e) {
console.error("[ttyd] parse failed: " + e);
return false;
}
});
if (document.queryCommandSupported && document.queryCommandSupported('copy')) {
terminal.onSelectionChange(() => {
if (terminal.getSelection() === '') return;

20264
src/html.h generated

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save