mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
performance improvements
This commit is contained in:
parent
2f2268906a
commit
5ba9f27c5d
7 changed files with 64 additions and 44 deletions
|
|
@ -19,7 +19,7 @@ import {
|
|||
SESSION_SET_PROCESS_TITLE
|
||||
} from '../constants/sessions';
|
||||
|
||||
export function addSession (uid) {
|
||||
export function addSession (uid, shell) {
|
||||
return (dispatch, getState) => {
|
||||
const { sessions } = getState();
|
||||
|
||||
|
|
@ -31,7 +31,8 @@ export function addSession (uid) {
|
|||
|
||||
dispatch({
|
||||
type: SESSION_ADD,
|
||||
uid
|
||||
uid,
|
||||
shell
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
@ -51,13 +52,14 @@ export function requestSession (uid) {
|
|||
}
|
||||
|
||||
export function addSessionData (uid, data) {
|
||||
return (dispatch, getState) => {
|
||||
return function (dispatch, getState) {
|
||||
dispatch({
|
||||
type: SESSION_ADD_DATA,
|
||||
data,
|
||||
effect () {
|
||||
const url = getURL(data);
|
||||
if (null != url) {
|
||||
const { shell } = getState().sessions.sessions[uid];
|
||||
const url = getURL(shell, data);
|
||||
if (null !== url) {
|
||||
dispatch({
|
||||
type: SESSION_URL_SET,
|
||||
uid,
|
||||
|
|
@ -101,10 +103,13 @@ export function userExitSession (uid) {
|
|||
type: SESSION_USER_EXIT,
|
||||
uid,
|
||||
effect () {
|
||||
rpc.emit('exit', { uid });
|
||||
const sessions = keys(getState().sessions.sessions);
|
||||
if (!sessions.length) {
|
||||
window.close();
|
||||
const { sessions } = getState().sessions;
|
||||
if (sessions[uid]) {
|
||||
rpc.emit('exit', { uid });
|
||||
const sessions = keys(getState().sessions.sessions);
|
||||
if (!sessions.length) {
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* global Blob,URL */
|
||||
/* global Blob,URL,requestAnimationFrame */
|
||||
import React from 'react';
|
||||
import hterm from '../hterm';
|
||||
import Component from '../component';
|
||||
|
|
@ -73,7 +73,9 @@ export default class Term extends Component {
|
|||
}
|
||||
|
||||
write (data) {
|
||||
this.term.io.print(data);
|
||||
requestAnimationFrame(() => {
|
||||
this.term.io.print(data);
|
||||
});
|
||||
}
|
||||
|
||||
focus () {
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ rpc.on('ready', () => {
|
|||
store_.dispatch(init());
|
||||
});
|
||||
|
||||
rpc.on('session add', ({ uid }) => {
|
||||
store_.dispatch(sessionActions.addSession(uid));
|
||||
rpc.on('session add', ({ uid, shell }) => {
|
||||
store_.dispatch(sessionActions.addSession(uid, shell));
|
||||
});
|
||||
|
||||
rpc.on('session data', ({ uid, data }) => {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ function Session (obj) {
|
|||
title: '',
|
||||
write: null,
|
||||
url: null,
|
||||
cleared: false
|
||||
cleared: false,
|
||||
shell: ''
|
||||
}).merge(obj);
|
||||
}
|
||||
|
||||
|
|
@ -37,14 +38,12 @@ function Write (obj) {
|
|||
}
|
||||
|
||||
const reducer = (state = initialState, action) => {
|
||||
// prune the last write to the terminal
|
||||
if (state.write) {
|
||||
state = state.set('write', null);
|
||||
}
|
||||
|
||||
switch (action.type) {
|
||||
case SESSION_ADD:
|
||||
return state.setIn(['sessions', action.uid], Session({ uid: action.uid }));
|
||||
return state.setIn(['sessions', action.uid], Session({
|
||||
uid: action.uid,
|
||||
shell: action.shell.split('/').pop()
|
||||
}));
|
||||
|
||||
case SESSION_URL_SET:
|
||||
return state.setIn(['sessions', action.uid, 'url'], action.url);
|
||||
|
|
@ -65,8 +64,9 @@ const reducer = (state = initialState, action) => {
|
|||
}, { deep: true });
|
||||
|
||||
case SESSION_PTY_DATA:
|
||||
return state.merge({
|
||||
write: Write(action),
|
||||
return state
|
||||
.set('write', Write(action))
|
||||
.merge({
|
||||
sessions: {
|
||||
[action.uid]: {
|
||||
cleared: false
|
||||
|
|
|
|||
|
|
@ -1,30 +1,40 @@
|
|||
import * as regex from './url-regex';
|
||||
|
||||
export default function isUrlCommand (data) {
|
||||
let match = data.match(regex.bash);
|
||||
let url;
|
||||
export const domainRegex = /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/;
|
||||
|
||||
export default function isUrlCommand (shell, data) {
|
||||
const matcher = regex[shell];
|
||||
if (undefined === matcher) return null;
|
||||
let url, i;
|
||||
|
||||
switch (matcher) {
|
||||
case regex.bash:
|
||||
i = 5;
|
||||
break;
|
||||
|
||||
case regex.zsh:
|
||||
i = 7;
|
||||
break;
|
||||
|
||||
case regex.fish:
|
||||
i = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
let match = data.match(matcher);
|
||||
|
||||
if (match) {
|
||||
url = match[5];
|
||||
} else {
|
||||
match = data.match(regex.zsh);
|
||||
if (match) {
|
||||
url = match[7];
|
||||
} else {
|
||||
match = data.match(regex.fish);
|
||||
if (match) {
|
||||
url = match[4];
|
||||
url = match[i];
|
||||
if (url) {
|
||||
// extract the domain portion from the url
|
||||
const domain = url.split('/')[0];
|
||||
if (domainRegex.test(domain)) {
|
||||
return toURL(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (url) {
|
||||
// extract the domain portion from the url
|
||||
const domain = url.split('/')[0];
|
||||
if (regex.domain.test(domain)) {
|
||||
return toURL(url);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function toURL (domain) {
|
||||
|
|
|
|||
|
|
@ -1,4 +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 sh = /(ba)?sh: ((https?:\/\/)|(\/\/))?(.*): ((command not found)|(No such file or directory))/;
|
||||
export const bash = sh;
|
||||
export const zsh = /zsh: ((command not found)|(no such file or directory)): ((https?:\/\/)|(\/\/))?([^\n]+)/;
|
||||
export const fish = /fish: Unknown command '((https?:\/\/)|(\/\/))?([^']+)'/;
|
||||
|
|
|
|||
5
index.js
5
index.js
|
|
@ -78,7 +78,10 @@ app.on('ready', () => {
|
|||
rpc.on('new', ({ rows = 40, cols = 100 }) => {
|
||||
initSession({ rows, cols }, (uid, session) => {
|
||||
sessions.set(uid, session);
|
||||
rpc.emit('session add', { uid });
|
||||
rpc.emit('session add', {
|
||||
uid,
|
||||
shell: session.shell
|
||||
});
|
||||
|
||||
session.on('data', (data) => {
|
||||
rpc.emit('session data', { uid, data });
|
||||
|
|
|
|||
Loading…
Reference in a new issue