mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-13 04:28:41 -09:00
Improve tabs title (#892)
* Set tab title when asked by the contained shell process via ANSI code * Commented out process polling code * Removed unused module and constant * Remove getTitle method * Removed props binding * Removed polling clearTimeout * Removed session focus & blur * Remove listening for session `title` event * Removed SESSION_SET_PROCESS_TITLE action * Removed remainig blur
This commit is contained in:
parent
3f772311db
commit
97432df7a4
7 changed files with 6 additions and 105 deletions
29
app/index.js
29
app/index.js
|
|
@ -194,11 +194,6 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
|
|||
rpc.emit('session data', {uid, data});
|
||||
});
|
||||
|
||||
session.on('title', title => {
|
||||
win.setTitle(title);
|
||||
rpc.emit('session title', {uid, title});
|
||||
});
|
||||
|
||||
session.on('exit', () => {
|
||||
rpc.emit('session exit', {uid});
|
||||
sessions.delete(uid);
|
||||
|
|
@ -206,30 +201,6 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
|
|||
});
|
||||
});
|
||||
|
||||
// TODO: this goes away when we are able to poll
|
||||
// for the title ourselves, instead of relying
|
||||
// on Session and focus/blur to subscribe
|
||||
rpc.on('focus', ({uid}) => {
|
||||
const session = sessions.get(uid);
|
||||
if (typeof session !== 'undefined' && typeof session.lastTitle !== 'undefined') {
|
||||
win.setTitle(session.lastTitle);
|
||||
}
|
||||
if (session) {
|
||||
session.focus();
|
||||
} else {
|
||||
console.log('session not found by', uid);
|
||||
}
|
||||
});
|
||||
rpc.on('blur', ({uid}) => {
|
||||
const session = sessions.get(uid);
|
||||
|
||||
if (session) {
|
||||
session.blur();
|
||||
} else {
|
||||
console.log('session not found by', uid);
|
||||
}
|
||||
});
|
||||
|
||||
rpc.on('exit', ({uid}) => {
|
||||
const session = sessions.get(uid);
|
||||
if (session) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
const {exec} = require('child_process');
|
||||
const {EventEmitter} = require('events');
|
||||
const {StringDecoder} = require('string_decoder');
|
||||
|
||||
|
|
@ -21,8 +20,6 @@ try {
|
|||
);
|
||||
}
|
||||
|
||||
const TITLE_POLL_INTERVAL = 500;
|
||||
|
||||
const envFromConfig = config.getConfig().env || {};
|
||||
|
||||
module.exports = class Session extends EventEmitter {
|
||||
|
|
@ -62,60 +59,6 @@ module.exports = class Session extends EventEmitter {
|
|||
});
|
||||
|
||||
this.shell = shell || defaultShell;
|
||||
this.getTitle();
|
||||
}
|
||||
|
||||
focus() {
|
||||
this.subscribed = true;
|
||||
this.getTitle();
|
||||
}
|
||||
|
||||
blur() {
|
||||
this.subscribed = false;
|
||||
clearTimeout(this.titlePoll);
|
||||
}
|
||||
|
||||
getTitle() {
|
||||
if (process.platform === 'win32') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.fetching) {
|
||||
return;
|
||||
}
|
||||
this.fetching = true;
|
||||
|
||||
let tty = this.pty.stdout.ttyname;
|
||||
tty = tty.replace(/^\/dev\/tty/, '');
|
||||
|
||||
// try to exclude grep from the results
|
||||
// by grepping for `[s]001` instead of `s001`
|
||||
tty = `[${tty[0]}]${tty.substr(1)}`;
|
||||
|
||||
// TODO: limit the concurrency of how many processes we run?
|
||||
// TODO: only tested on mac
|
||||
exec(`ps uxac | grep ${tty} | head -n 1`, (err, out) => {
|
||||
this.fetching = false;
|
||||
if (this.ended) {
|
||||
return;
|
||||
}
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
let title = out.split(' ').pop();
|
||||
if (title) {
|
||||
title = title.replace(/^\(/, '');
|
||||
title = title.replace(/\)?\n$/, '');
|
||||
if (title !== this.lastTitle) {
|
||||
this.emit('title', title);
|
||||
this.lastTitle = title;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.subscribed) {
|
||||
this.titlePoll = setTimeout(() => this.getTitle(), TITLE_POLL_INTERVAL);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
exit() {
|
||||
|
|
@ -142,7 +85,6 @@ module.exports = class Session extends EventEmitter {
|
|||
}
|
||||
this.emit('exit');
|
||||
this.ended = true;
|
||||
this.blur();
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -15,8 +15,7 @@ import {
|
|||
SESSION_USER_DATA,
|
||||
SESSION_URL_SET,
|
||||
SESSION_URL_UNSET,
|
||||
SESSION_SET_XTERM_TITLE,
|
||||
SESSION_SET_PROCESS_TITLE
|
||||
SESSION_SET_XTERM_TITLE
|
||||
} from '../constants/sessions';
|
||||
|
||||
export function addSession({uid, shell, pid, cols, rows, splitDirection}) {
|
||||
|
|
@ -127,14 +126,6 @@ export function clearActiveSession() {
|
|||
};
|
||||
}
|
||||
|
||||
export function setSessionProcessTitle(uid, title) {
|
||||
return {
|
||||
type: SESSION_SET_PROCESS_TITLE,
|
||||
uid,
|
||||
title
|
||||
};
|
||||
}
|
||||
|
||||
export function setSessionXtermTitle(uid, title) {
|
||||
return {
|
||||
type: SESSION_SET_XTERM_TITLE,
|
||||
|
|
|
|||
|
|
@ -69,6 +69,10 @@ export default class Term extends Component {
|
|||
this.term.modifierKeys = props.modifierKeys;
|
||||
// this.term.CursorNode_ is available at this point.
|
||||
this.term.setCursorShape(props.cursorShape);
|
||||
|
||||
// emit onTitle event when hterm instance
|
||||
// wants to set the title of its tab
|
||||
this.term.setWindowTitle = props.onTitle;
|
||||
};
|
||||
this.term.decorate(this.termRef);
|
||||
this.term.installKeyboard();
|
||||
|
|
|
|||
|
|
@ -11,5 +11,4 @@ export const SESSION_USER_DATA = 'SESSION_USER_DATA';
|
|||
export const SESSION_URL_SET = 'SESSION_URL_SET';
|
||||
export const SESSION_URL_UNSET = 'SESSION_URL_UNSET';
|
||||
export const SESSION_SET_XTERM_TITLE = 'SESSION_SET_XTERM_TITLE';
|
||||
export const SESSION_SET_PROCESS_TITLE = 'SESSION_SET_PROCESS_TITLE';
|
||||
export const SESSION_SET_CWD = 'SESSION_SET_CWD';
|
||||
|
|
|
|||
|
|
@ -52,10 +52,6 @@ rpc.on('session data send', ({uid, data}) => {
|
|||
store_.dispatch(sessionActions.sendSessionData(uid, data));
|
||||
});
|
||||
|
||||
rpc.on('session title', ({uid, title}) => {
|
||||
store_.dispatch(sessionActions.setSessionProcessTitle(uid, title));
|
||||
});
|
||||
|
||||
rpc.on('session exit', ({uid}) => {
|
||||
store_.dispatch(termGroupActions.ptyExitTermGroup(uid));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ import {
|
|||
SESSION_URL_SET,
|
||||
SESSION_URL_UNSET,
|
||||
SESSION_RESIZE,
|
||||
SESSION_SET_XTERM_TITLE,
|
||||
SESSION_SET_PROCESS_TITLE
|
||||
SESSION_SET_XTERM_TITLE
|
||||
} from '../constants/sessions';
|
||||
|
||||
const initialState = Immutable({
|
||||
|
|
@ -94,7 +93,6 @@ const reducer = (state = initialState, action) => {
|
|||
return deleteSession(state, action.uid);
|
||||
|
||||
case SESSION_SET_XTERM_TITLE:
|
||||
case SESSION_SET_PROCESS_TITLE:
|
||||
return state.setIn(['sessions', action.uid, 'title'], action.title);
|
||||
|
||||
case SESSION_RESIZE:
|
||||
|
|
|
|||
Loading…
Reference in a new issue