mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
Provide hooks to open a new tab to the same directory (#174)
* provide a cwd for #4 * expose a pid for #4
This commit is contained in:
parent
ba84c12788
commit
04c0b1acff
5 changed files with 17 additions and 14 deletions
|
|
@ -19,7 +19,7 @@ import {
|
|||
SESSION_SET_PROCESS_TITLE
|
||||
} from '../constants/sessions';
|
||||
|
||||
export function addSession (uid, shell) {
|
||||
export function addSession (uid, shell, pid) {
|
||||
return (dispatch, getState) => {
|
||||
const { sessions } = getState();
|
||||
|
||||
|
|
@ -32,7 +32,8 @@ export function addSession (uid, shell) {
|
|||
dispatch({
|
||||
type: SESSION_ADD,
|
||||
uid,
|
||||
shell
|
||||
shell,
|
||||
pid
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
@ -40,12 +41,11 @@ export function addSession (uid, shell) {
|
|||
export function requestSession (uid) {
|
||||
return (dispatch, getState) => {
|
||||
const { ui } = getState();
|
||||
const cols = ui.cols;
|
||||
const rows = ui.rows;
|
||||
const { cols, rows, cwd } = ui;
|
||||
dispatch({
|
||||
type: SESSION_REQUEST,
|
||||
effect: () => {
|
||||
rpc.emit('new', { cols, rows });
|
||||
rpc.emit('new', { cols, rows, cwd });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ rpc.on('ready', () => {
|
|||
store_.dispatch(init());
|
||||
});
|
||||
|
||||
rpc.on('session add', ({ uid, shell }) => {
|
||||
store_.dispatch(sessionActions.addSession(uid, shell));
|
||||
rpc.on('session add', ({ uid, shell, pid }) => {
|
||||
store_.dispatch(sessionActions.addSession(uid, shell, pid));
|
||||
});
|
||||
|
||||
rpc.on('session data', ({ uid, data }) => {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ function Session (obj) {
|
|||
write: null,
|
||||
url: null,
|
||||
cleared: false,
|
||||
shell: ''
|
||||
shell: '',
|
||||
pid: null
|
||||
}).merge(obj);
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +43,8 @@ const reducer = (state = initialState, action) => {
|
|||
case SESSION_ADD:
|
||||
return state.setIn(['sessions', action.uid], Session({
|
||||
uid: action.uid,
|
||||
shell: action.shell.split('/').pop()
|
||||
shell: action.shell.split('/').pop(),
|
||||
pid: action.pid
|
||||
}));
|
||||
|
||||
case SESSION_URL_SET:
|
||||
|
|
|
|||
7
index.js
7
index.js
|
|
@ -80,12 +80,13 @@ app.on('ready', () => {
|
|||
}
|
||||
});
|
||||
|
||||
rpc.on('new', ({ rows = 40, cols = 100 }) => {
|
||||
initSession({ rows, cols }, (uid, session) => {
|
||||
rpc.on('new', ({ rows = 40, cols = 100, cwd = process.env.HOME }) => {
|
||||
initSession({ rows, cols, cwd }, (uid, session) => {
|
||||
sessions.set(uid, session);
|
||||
rpc.emit('session add', {
|
||||
uid,
|
||||
shell: session.shell
|
||||
shell: session.shell,
|
||||
pid: session.pty.pid
|
||||
});
|
||||
|
||||
session.on('data', (data) => {
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@ const TITLE_POLL_INTERVAL = 500;
|
|||
|
||||
module.exports = class Session extends EventEmitter {
|
||||
|
||||
constructor ({ rows, cols: columns }) {
|
||||
constructor ({ rows, cols: columns, cwd }) {
|
||||
super();
|
||||
this.pty = spawn(defaultShell, ['--login'], {
|
||||
columns,
|
||||
rows,
|
||||
cwd: process.env.HOME,
|
||||
cwd,
|
||||
env: Object.assign({}, process.env, {
|
||||
TERM: 'xterm-256color'
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue