Skip to content

Commit

Permalink
Second pass at support for HTM in Hyper.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Gauci committed May 13, 2018
1 parent a4669be commit f1c2386
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 30 deletions.
6 changes: 3 additions & 3 deletions app/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ const commands = {
},
'tab:new': focusedWindow => {
if (focusedWindow) {
focusedWindow.rpc.emit('termgroup add req');
focusedWindow.rpc.emit('termgroup add req', {});
} else {
setTimeout(app.createWindow, 0);
}
},
'pane:splitVertical': focusedWindow => {
focusedWindow && focusedWindow.rpc.emit('split request vertical');
focusedWindow && focusedWindow.rpc.emit('split request vertical', {});
},
'pane:splitHorizontal': focusedWindow => {
focusedWindow && focusedWindow.rpc.emit('split request horizontal');
focusedWindow && focusedWindow.rpc.emit('split request horizontal', {});
},
'pane:close': focusedWindow => {
focusedWindow && focusedWindow.rpc.emit('termgroup close req');
Expand Down
25 changes: 17 additions & 8 deletions app/ui/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {parse: parseUrl} = require('url');
const uuid = require('uuid');
const fileUriToPath = require('file-uri-to-path');
const isDev = require('electron-is-dev');

const updater = require('../updater');
const toElectronBackgroundColor = require('../utils/to-electron-background-color');
const {icon, cfgDir} = require('../config/paths');
Expand Down Expand Up @@ -66,7 +67,7 @@ module.exports = class Window {
// If no callback is passed to createWindow,
// a new session will be created by default.
if (!fn) {
fn = win => win.rpc.emit('termgroup add req');
fn = win => win.rpc.emit('termgroup add req', {});
}

// app.windowCallback is the createWindow callback
Expand Down Expand Up @@ -98,23 +99,23 @@ module.exports = class Window {
options
);

const initSession = (opts, fn_) => {
fn_(uuid.v4(), new Session(opts));
};

initSession(sessionOpts, (uid, session) => {
window.initSession(sessionOpts, (uid, session) => {
sessions.set(uid, session);
rpc.emit('session add', {
rows: sessionOpts.rows,
cols: sessionOpts.cols,
uid,
splitDirection: sessionOpts.splitDirection,
shell: session.shell,
pid: session.pty.pid
pid: typeof session.pty !== 'undefined' ? session.pty.pid : null,
termGroupUid: sessionOpts.termGroupUid,
activeUid: sessionOpts.activeUid
});

session.on('data', data => {
rpc.emit('session data', uid + data);
window.handleSessionData(uid, data, (innerUid, innerData) => {
rpc.emit('session data', {uid: innerUid, data: innerData});
});
});

session.on('exit', () => {
Expand Down Expand Up @@ -158,6 +159,14 @@ module.exports = class Window {
session.write(data);
}
});
window.initSession = (opts, fn_) => {
fn_(uuid.v4(), new Session(opts));
};

window.handleSessionData = (uid, data, handleSessionCallback) => {
// By default, just execute the callback. Plugins can override.
return handleSessionCallback(uid, data);
};
rpc.on('open external', ({url}) => {
shell.openExternal(url);
});
Expand Down
7 changes: 4 additions & 3 deletions lib/actions/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
SESSION_SET_XTERM_TITLE
} from '../constants/sessions';

export function addSession({uid, shell, pid, cols, rows, splitDirection}) {
export function addSession({uid, shell, pid, cols, rows, splitDirection, termGroupUid, activeUid}) {
return (dispatch, getState) => {
const {sessions} = getState();
const now = Date.now();
Expand All @@ -30,8 +30,9 @@ export function addSession({uid, shell, pid, cols, rows, splitDirection}) {
cols,
rows,
splitDirection,
activeUid: sessions.activeUid,
now
activeUid: activeUid ? activeUid : sessions.activeUid,
now,
termGroupUid
});
};
}
Expand Down
14 changes: 9 additions & 5 deletions lib/actions/term-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import getRootGroups from '../selectors';
import {setActiveSession, ptyExitSession, userExitSession} from './sessions';

function requestSplit(direction) {
return () => (dispatch, getState) => {
return (sessionUid, sourceUid) => (dispatch, getState) => {
dispatch({
type: SESSION_REQUEST,
effect: () => {
const {ui} = getState();
const {ui, sessions} = getState();
rpc.emit('new', {
splitDirection: direction,
cwd: ui.cwd
cwd: ui.cwd,
sessionUid,
activeUid: sourceUid ? sourceUid : sessions.activeUid
});
}
});
Expand All @@ -37,7 +39,7 @@ export function resizeTermGroup(uid, sizes) {
};
}

export function requestTermGroup() {
export function requestTermGroup(termGroupUid, sessionUid) {
return (dispatch, getState) => {
dispatch({
type: TERM_GROUP_REQUEST,
Expand All @@ -48,7 +50,9 @@ export function requestTermGroup() {
isNewGroup: true,
cols,
rows,
cwd
cwd,
termGroupUid,
sessionUid
});
}
});
Expand Down
17 changes: 7 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ rpc.on('session add', data => {
store_.dispatch(sessionActions.addSession(data));
});

rpc.on('session data', d => {
// the uid is a uuid v4 so it's 36 chars long
const uid = d.slice(0, 36);
const data = d.slice(36);
rpc.on('session data', ({uid, data}) => {
store_.dispatch(sessionActions.addSessionData(uid, data));
});

Expand Down Expand Up @@ -103,16 +100,16 @@ rpc.on('session break req', () => {
store_.dispatch(sessionActions.sendSessionData(null, '\x03'));
});

rpc.on('termgroup add req', () => {
store_.dispatch(termGroupActions.requestTermGroup());
rpc.on('termgroup add req', ({termGroupUid, sessionUid}) => {
store_.dispatch(termGroupActions.requestTermGroup(termGroupUid, sessionUid));
});

rpc.on('split request horizontal', () => {
store_.dispatch(termGroupActions.requestHorizontalSplit());
rpc.on('split request horizontal', ({sessionUid, sourceUid}) => {
store_.dispatch(termGroupActions.requestHorizontalSplit(sessionUid, sourceUid));
});

rpc.on('split request vertical', () => {
store_.dispatch(termGroupActions.requestVerticalSplit());
rpc.on('split request vertical', ({sessionUid, sourceUid}) => {
store_.dispatch(termGroupActions.requestVerticalSplit(sessionUid, sourceUid));
});

rpc.on('reset fontSize req', () => {
Expand Down
5 changes: 4 additions & 1 deletion lib/reducers/term-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ const reducer = (state = initialState, action) => {
return setActiveGroup(state, action);
}

const uid = uuid.v4();
let uid = uuid.v4();
if (action.termGroupUid) {
uid = action.termGroupUid;
}
const termGroup = TermGroup({
uid,
sessionUid: action.uid
Expand Down

0 comments on commit f1c2386

Please sign in to comment.