mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
clean up and refactor
This commit is contained in:
parent
09cb3a4e45
commit
1265528b13
4 changed files with 63 additions and 53 deletions
47
app/hterm.js
Normal file
47
app/hterm.js
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
import { hterm, lib } from 'hterm-umdjs';
|
||||||
|
|
||||||
|
hterm.defaultStorage = new lib.Storage.Memory();
|
||||||
|
|
||||||
|
// override double click behavior to copy
|
||||||
|
const oldMouse = hterm.Terminal.prototype.onMouse_;
|
||||||
|
hterm.Terminal.prototype.onMouse_ = function (e) {
|
||||||
|
if ('dblclick' === e.type) {
|
||||||
|
console.log('[hyperterm+hterm] ignore double click');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return oldMouse.call(this, e);
|
||||||
|
};
|
||||||
|
|
||||||
|
// there's no option to turn off the size overlay
|
||||||
|
hterm.Terminal.prototype.overlaySize = function () {};
|
||||||
|
|
||||||
|
// fixing a bug in hterm where a double click triggers
|
||||||
|
// a non-collapsed selection whose text is '', and results
|
||||||
|
// in an infinite copy loop
|
||||||
|
hterm.Terminal.prototype.copySelectionToClipboard = function () {
|
||||||
|
var text = this.getSelectionText();
|
||||||
|
if (text != null && text !== '') {
|
||||||
|
this.copyStringToClipboard(text);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// passthrough all the commands that are meant to control
|
||||||
|
// hyperterm and not the terminal itself
|
||||||
|
const oldKeyDown = hterm.Keyboard.prototype.onKeyDown_;
|
||||||
|
hterm.Keyboard.prototype.onKeyDown_ = function (e) {
|
||||||
|
if (e.metaKey) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return oldKeyDown.call(this, e);
|
||||||
|
};
|
||||||
|
|
||||||
|
const oldKeyPress = hterm.Keyboard.prototype.onKeyPress_;
|
||||||
|
hterm.Keyboard.prototype.onKeyPress_ = function (e) {
|
||||||
|
if (e.metaKey) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return oldKeyPress.call(this, e);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { hterm };
|
||||||
|
export { lib };
|
||||||
5
app/notify.js
Normal file
5
app/notify.js
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
/* global Notification */
|
||||||
|
/* eslint no-new:0 */
|
||||||
|
export default function notify (title, body) {
|
||||||
|
new Notification(title, { body });
|
||||||
|
}
|
||||||
4
app/regex.js
Normal file
4
app/regex.js
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
export const domain = /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/;
|
||||||
|
export const bash = /(ba)?sh: ((https?:\/\/)|(\/\/))?(.*): ((command not found)|(No such file or directory))/;
|
||||||
|
export const zsh = /zsh: ((command not found)|(no such file or directory)): ((https?:\/\/)|(\/\/))?([^\n]+)/;
|
||||||
|
export const fish = /fish: Unknown command '((https?:\/\/)|(\/\/))?([^']+)'/;
|
||||||
60
app/term.js
60
app/term.js
|
|
@ -1,54 +1,7 @@
|
||||||
/*global URL:false,Blob:false*/
|
/*global URL:false,Blob:false*/
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { hterm, lib as htermLib } from 'hterm-umdjs';
|
import { hterm, lib as htermLib } from './hterm';
|
||||||
|
import * as regex from './regex';
|
||||||
hterm.defaultStorage = new htermLib.Storage.Memory();
|
|
||||||
|
|
||||||
// override double click behavior to copy
|
|
||||||
const oldMouse = hterm.Terminal.prototype.onMouse_;
|
|
||||||
hterm.Terminal.prototype.onMouse_ = function (e) {
|
|
||||||
if ('dblclick' === e.type) {
|
|
||||||
console.log('[hyperterm+hterm] ignore double click');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return oldMouse.call(this, e);
|
|
||||||
};
|
|
||||||
|
|
||||||
// there's no option to turn off the size overlay
|
|
||||||
hterm.Terminal.prototype.overlaySize = function () {};
|
|
||||||
|
|
||||||
// fixing a bug in hterm where a double click triggers
|
|
||||||
// a non-collapsed selection whose text is '', and results
|
|
||||||
// in an infinite copy loop
|
|
||||||
hterm.Terminal.prototype.copySelectionToClipboard = function () {
|
|
||||||
var text = this.getSelectionText();
|
|
||||||
if (text != null && text !== '') {
|
|
||||||
this.copyStringToClipboard(text);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// passthrough all the commands that are meant to control
|
|
||||||
// hyperterm and not the terminal itself
|
|
||||||
const oldKeyDown = hterm.Keyboard.prototype.onKeyDown_;
|
|
||||||
hterm.Keyboard.prototype.onKeyDown_ = function (e) {
|
|
||||||
if (e.metaKey) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return oldKeyDown.call(this, e);
|
|
||||||
};
|
|
||||||
|
|
||||||
const oldKeyPress = hterm.Keyboard.prototype.onKeyPress_;
|
|
||||||
hterm.Keyboard.prototype.onKeyPress_ = function (e) {
|
|
||||||
if (e.metaKey) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return oldKeyPress.call(this, e);
|
|
||||||
};
|
|
||||||
|
|
||||||
const domainRegex = /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/;
|
|
||||||
const bashRegex = /(ba)?sh: ((https?:\/\/)|(\/\/))?(.*): ((command not found)|(No such file or directory))/;
|
|
||||||
const zshRegex = /zsh: ((command not found)|(no such file or directory)): ((https?:\/\/)|(\/\/))?([^\n]+)/;
|
|
||||||
const fishRegex = /fish: Unknown command '((https?:\/\/)|(\/\/))?([^']+)'/;
|
|
||||||
|
|
||||||
export default class Term extends Component {
|
export default class Term extends Component {
|
||||||
|
|
||||||
|
|
@ -73,6 +26,7 @@ export default class Term extends Component {
|
||||||
.cursor-node[focus="false"] {
|
.cursor-node[focus="false"] {
|
||||||
border-width: 1px !important;
|
border-width: 1px !important;
|
||||||
}
|
}
|
||||||
|
${Array.from(props.customCSS || '').join('\n')}
|
||||||
`]), { type: 'text/css' }));
|
`]), { type: 'text/css' }));
|
||||||
|
|
||||||
this.term.onTerminalReady = () => {
|
this.term.onTerminalReady = () => {
|
||||||
|
|
@ -137,17 +91,17 @@ export default class Term extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
write (data) {
|
write (data) {
|
||||||
let match = data.match(bashRegex);
|
let match = data.match(regex.bash);
|
||||||
let url;
|
let url;
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
url = match[5];
|
url = match[5];
|
||||||
} else {
|
} else {
|
||||||
match = data.match(zshRegex);
|
match = data.match(regex.zsh);
|
||||||
if (match) {
|
if (match) {
|
||||||
url = match[7];
|
url = match[7];
|
||||||
} else {
|
} else {
|
||||||
match = data.match(fishRegex);
|
match = data.match(regex.fish);
|
||||||
if (match) {
|
if (match) {
|
||||||
url = match[4];
|
url = match[4];
|
||||||
}
|
}
|
||||||
|
|
@ -157,7 +111,7 @@ export default class Term extends Component {
|
||||||
if (url) {
|
if (url) {
|
||||||
// extract the domain portion from the url
|
// extract the domain portion from the url
|
||||||
const domain = url.split('/')[0];
|
const domain = url.split('/')[0];
|
||||||
if (domainRegex.test(domain)) {
|
if (regex.domain.test(domain)) {
|
||||||
this.props.onURL(toURL(url));
|
this.props.onURL(toURL(url));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue