From 67a1fc4dbb5c1d5d848419841bfd813663a7a0b9 Mon Sep 17 00:00:00 2001 From: ivanwonder Date: Fri, 2 Aug 2019 10:12:46 +0800 Subject: [PATCH] support config 'useConpty' --- app/session.js | 20 ++++++++++++++------ app/ui/window.js | 5 +++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/session.js b/app/session.js index 1f84fd42..f1a0a6d4 100644 --- a/app/session.js +++ b/app/session.js @@ -20,6 +20,7 @@ try { } const envFromConfig = config.getConfig().env || {}; +const useConpty = config.getConfig().useConpty; // Max duration to batch session data before sending it to the renderer process. const BATCH_DURATION_MS = 16; @@ -107,13 +108,20 @@ module.exports = class Session extends EventEmitter { const defaultShellArgs = ['--login']; + const options = { + cols: columns, + rows, + cwd, + env: getDecoratedEnv(baseEnv) + }; + + // if config do not set the useConpty, it will be judged by the node-pty + if (typeof useConpty === 'boolean') { + options.experimentalUseConpty = useConpty; + } + try { - this.pty = spawn(shell || defaultShell, shellArgs || defaultShellArgs, { - cols: columns, - rows, - cwd, - env: getDecoratedEnv(baseEnv) - }); + this.pty = spawn(shell || defaultShell, shellArgs || defaultShellArgs, options); } catch (err) { if (/is not a function/.test(err.message)) { throw createNodePtyError(); diff --git a/app/ui/window.js b/app/ui/window.js index b903479a..7ad57903 100644 --- a/app/ui/window.js +++ b/app/ui/window.js @@ -123,12 +123,13 @@ module.exports = class Window { // Optimistically create the initial session so that when the window sends // the first "new" IPC message, there's a session already warmed up. + let initialSession = null; function createInitialSession() { let {session, options} = createSession(); const initialEvents = []; const handleData = data => initialEvents.push(['session data', data]); const handleExit = () => { - // the warmed up session exits when open hyper by cli. + // the warmed up session should be cleaned if exit before add a new session. session.removeListener('data', handleData); session.removeListener('exit', handleExit); initialSession = null; @@ -145,7 +146,7 @@ module.exports = class Window { } return {session, options, flushEvents}; } - let initialSession = createInitialSession(); + initialSession = createInitialSession(); rpc.on('new', extraOptions => { const {session, options} = initialSession || createSession(extraOptions);