Skip to content

Commit

Permalink
Merge branch 'master' of ssh://github.com/zeit/hyper into feature/mor…
Browse files Browse the repository at this point in the history
…eShells
  • Loading branch information
AlmirKadric committed May 21, 2017
2 parents 8c09a31 + e09a7f7 commit dcc5409
Show file tree
Hide file tree
Showing 55 changed files with 3,755 additions and 1,669 deletions.
3 changes: 2 additions & 1 deletion .github/issue_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
If not, please try and fulfil these first.
-->

<!-- Checked checkbox should look like this: [x] -->
- [ ] I am on the [latest](https://github.com/zeit/hyper/releases/latest) Hyper.app version
- [ ] I have searched the [issues](https://github.com/zeit/hyper/issues) of this repo and believe that this is not a duplicate

Expand All @@ -17,7 +18,7 @@
- **OS version and name**: <!-- Replace with version + name -->
- **Hyper.app version**: <!-- Replace with version -->
- **Link of a [Gist](https://gist.github.com/) with the contents of your .hyper.js**: <!-- Gist Link Here -->
- **Relevent information from devtools** _(CMD+SHIFT+I on Mac OS, CTRL+SHIFT+I elsewhere)_: <!-- Replace with info if applicable, or N/A -->
- **Relevant information from devtools** _(CMD+ALT+I on Mac OS, CTRL+SHIFT+I elsewhere)_: <!-- Replace with info if applicable, or N/A -->
- **The issue is reproducible in vanilla Hyper.app**: <!-- Replace with info if applicable, or `Is Vanilla`. (Vanilla means Hyper.app without any add-ons or extras. Straight out of the box.) -->

## Issue
Expand Down
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@ addons:
- xz-utils
- rpm
- bsdtar
- snapd

before_install:
- mkdir -p /tmp/git-lfs && curl -L https://github.com/github/git-lfs/releases/download/v1.2.1/git-lfs-$([ "$TRAVIS_OS_NAME" == "linux" ] && echo "linux" || echo "darwin")-amd64-1.2.1.tar.gz | tar -xz -C /tmp/git-lfs --strip-components 1 && /tmp/git-lfs/git-lfs pull
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export DISPLAY=:99.0; sh -e /etc/init.d/xvfb start; sleep 3; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install yarn; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo add-apt-repository ppa:snappy-dev/tools-proposed -y && sudo apt update && sudo apt install snapcraft; fi

install:
- npm install

before_script:
- npm prune
- yarn

after_success:
- npm run dist
- yarn run dist

branches:
except:
Expand Down
24 changes: 21 additions & 3 deletions app/config-default.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.

module.exports = {
config: {
// default font size in pixels for all tabs
Expand All @@ -12,6 +16,9 @@ module.exports = {
// `BEAM` for |, `UNDERLINE` for _, `BLOCK` for █
cursorShape: 'BLOCK',

// set to true for blinking cursor
cursorBlink: false,

// color of the text
foregroundColor: '#fff',

Expand Down Expand Up @@ -63,9 +70,16 @@ module.exports = {

// the shell to run when spawning a new session (i.e. /usr/local/bin/fish)
// if left empty, your system's login shell will be used by default
// make sure to use a full path if the binary name doesn't work
// (e.g `C:\\Windows\\System32\\bash.exe` instad of just `bash.exe`)
// if you're using powershell, make sure to remove the `--login` below
//
// Windows
// - Make sure to use a full path if the binary name doesn't work
// - Remove `--login` in shellArgs
//
// Bash on Windows
// - Example: `C:\\Windows\\System32\\bash.exe`
//
// Powershell on Windows
// - Example: `C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`
shell: '',

// for setting shell arguments (i.e. for using interactive shellArgs: ['-i'])
Expand All @@ -81,6 +95,10 @@ module.exports = {
// if true, selected text will automatically be copied to the clipboard
copyOnSelect: false

// if true, on right click selected text will be copied or pasted if no
// selection is present (true by default on Windows)
// quickEdit: true

// URL to custom bell
// bellSoundURL: 'http://example.com/bell.mp3',

Expand Down
18 changes: 15 additions & 3 deletions app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ const watchers = [];
let cfg = {};

function watch() {
gaze(path, function (err) {
// watch for changes on config every 2s
// windows interval: https://github.com/zeit/hyper/pull/1772
gaze(path, process.platform === 'win32' ? {interval: 2000} : {}, function (err) {
if (err) {
throw err;
}
Expand Down Expand Up @@ -84,6 +86,13 @@ function exec(str) {
return true;
}

// This method will take text formatted as Unix line endings and transform it
// to text formatted with DOS line endings. We do this because the default
// text editor on Windows (notepad) doesn't Deal with LF files. Still. In 2017.
function crlfify(str) {
return str.replace(/\r?\n/g, '\r\n');
}

exports.subscribe = function (fn) {
watchers.push(fn);
return () => {
Expand All @@ -110,9 +119,12 @@ exports.init = function () {
try {
console.log('attempting to write default config to', path);
exec(defaultConfig);
writeFileSync(path, defaultConfig);

writeFileSync(
path,
process.platform === 'win32' ? crlfify(defaultConfig.toString()) : defaultConfig);
} catch (err) {
throw new Error(`Failed to write config to ${path}`);
throw new Error(`Failed to write config to ${path}: ${err.message}`);
}
}
watch();
Expand Down
1 change: 1 addition & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<style>
body {
color: #fff;
-webkit-backface-visibility: hidden;
}

* {
Expand Down
23 changes: 19 additions & 4 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
// Print diagnostic information for a few arguments instead of running Hyper.
if (['--help', '-v', '--version'].includes(process.argv[1])) {
const {version} = require('./package');
const configLocation = process.platform === 'win32' ? process.env.userprofile + '\\.hyper.js' : '~/.hyper.js';
console.log(`Hyper version ${version}`);
console.log('Hyper does not accept any command line arguments. Please modify the config file instead.');
console.log(`Hyper configuration file located at: ${configLocation}`);
// eslint-disable-next-line unicorn/no-process-exit
process.exit();
}

// handle startup squirrel events
if (process.platform === 'win32') {
// eslint-disable-next-line import/order
Expand Down Expand Up @@ -42,7 +53,7 @@ const createRPC = require('./rpc');
const notify = require('./notify');
const fetchNotifications = require('./notifications');

app.commandLine.appendSwitch('js-flags', '--harmony');
app.commandLine.appendSwitch('js-flags', '--harmony-async-await');

// set up config
const config = require('./config');
Expand Down Expand Up @@ -166,7 +177,8 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
win.webContents.send('config change');

// notify user that shell changes require new sessions
if (cfg_.shell !== cfg.shell || cfg_.shellArgs !== cfg.shellArgs) {
if (cfg_.shell !== cfg.shell ||
JSON.stringify(cfg_.shellArgs) !== JSON.stringify(cfg.shellArgs)) {
notify(
'Shell configuration changed!',
'Open a new tab or window to start using the new shell'
Expand Down Expand Up @@ -222,7 +234,7 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
});

session.on('data', data => {
rpc.emit('session data', {uid, data});
rpc.emit('session data', uid + data);
});

session.on('exit', () => {
Expand Down Expand Up @@ -267,7 +279,7 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
});

rpc.on('open hamburger menu', ({x, y}) => {
Menu.getApplicationMenu().popup(x, y);
Menu.getApplicationMenu().popup(Math.ceil(x), Math.ceil(y));
});

rpc.on('minimize', () => {
Expand Down Expand Up @@ -303,6 +315,9 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
event.preventDefault();
const path = fileUriToPath(url).replace(/ /g, '\\ ');
rpc.emit('session data send', {data: path});
} else if (protocol === 'http:' || protocol === 'https:') {
event.preventDefault();
rpc.emit('session data send', {data: url});
}
});

Expand Down
29 changes: 14 additions & 15 deletions app/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const path = require('path');
const {app, shell, dialog} = require('electron');

const {accelerators} = require('./accelerators');
const config = require('./config');
const {getConfig,getConfigDir} = require('./config');

const isMac = process.platform === 'darwin';
const appName = app.getName();
const shells = config.getConfig().shells || {};
const shells = getConfig().shells || {};
const shellKeys = Object.keys(shells);

// based on and inspired by
Expand All @@ -30,12 +30,9 @@ module.exports = ({createWindow, updatePlugins}) => {
{
label: 'Preferences...',
accelerator: accelerators.preferences,
click(item, focusedWindow) {
if (focusedWindow) {
focusedWindow.rpc.emit('preferences');
} else {
createWindow(win => win.rpc.emit('preferences'));
}
click() {
const configFile = path.resolve(getConfigDir(), '.hyper.js');
shell.openItem(configFile);
}
},
{
Expand Down Expand Up @@ -234,12 +231,9 @@ module.exports = ({createWindow, updatePlugins}) => {
{
label: 'Preferences...',
accelerator: accelerators.preferences,
click(item, focusedWindow) {
if (focusedWindow) {
focusedWindow.rpc.emit('preferences');
} else {
createWindow(win => win.rpc.emit('preferences'));
}
click() {
const configFile = path.resolve(getConfigDir(), '.hyper.js');
shell.openItem(configFile);
}
}
);
Expand Down Expand Up @@ -271,7 +265,12 @@ module.exports = ({createWindow, updatePlugins}) => {
accelerator: accelerators.toggleDevTools,
click(item, focusedWindow) {
if (focusedWindow) {
focusedWindow.webContents.toggleDevTools();
const webContents = focusedWindow.webContents;
if (webContents.isDevToolsOpened()) {
webContents.closeDevTools();
} else {
webContents.openDevTools({mode: 'detach'});
}
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hyper",
"productName": "Hyper",
"description": "A terminal built on web technologies",
"version": "1.1.0",
"version": "1.3.3",
"license": "MIT",
"author": {
"name": "Zeit, Inc.",
Expand All @@ -23,7 +23,7 @@
"mkdirp": "0.5.1",
"ms": "0.7.1",
"node-fetch": "1.6.3",
"node-pty": "0.4.1",
"node-pty": "0.6.4",
"semver": "5.3.0",
"shell-env": "0.2.0",
"uuid": "3.0.0",
Expand Down
28 changes: 22 additions & 6 deletions app/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ const availableExtensions = new Set([
'reduceUI', 'reduceSessions', 'reduceTermGroups',
'decorateMenu', 'decorateTerm', 'decorateHyper',
'decorateHyperTerm', // for backwards compatibility with hyperterm
'decorateTab',
'decorateHeader', 'decorateTerms', 'decorateTab',
'decorateNotification', 'decorateNotifications',
'decorateTabs', 'decorateConfig', 'decorateEnv',
'decorateTermGroup', 'getTermProps',
'decorateTermGroup', 'decorateSplitPane', 'getTermProps',
'getTabProps', 'getTabsProps', 'getTermGroupProps',
'mapHyperTermState', 'mapTermsState',
'mapHeaderState', 'mapNotificationsState',
Expand Down Expand Up @@ -235,11 +235,27 @@ function install(fn) {
env.npm_config_target = process.versions.electron;
env.npm_config_disturl = 'https://atom.io/download/atom-shell';
/* eslint-enable camelcase */
exec('npm prune && npm install --production', {
// Shell-specific installation commands
const installCommands = {
fish: 'npm prune; and npm install --production',
posix: 'npm prune && npm install --production'
};
// determine the shell we're running in
const whichShell = (typeof cfgShell === 'string' && cfgShell.match(/fish/)) ? 'fish' : 'posix';
const execOptions = {
cwd: path,
env,
shell
}, err => {
env
};

// https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback
// node.js requires command line parsing should be compatible with cmd.exe on Windows, should able to accept `/d /s /c`
// but most custom shell doesn't. Instead, falls back to default shell
if (process.platform !== 'win32') {
execOptions.shell = shell;
}

// Use the install command that is appropriate for our shell
exec(installCommands[whichShell], execOptions, err => {
if (err) {
return fn(err);
}
Expand Down
15 changes: 11 additions & 4 deletions app/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {getDecoratedEnv} = require('./plugins');
const {productName, version} = require('./package');
const config = require('./config');

const createNodePtyError = () => new Error('`node-pty` failed to load. Typically this means that it was built incorrectly. Please check the `README.me` to more info.');
const createNodePtyError = () => new Error('`node-pty` failed to load. Typically this means that it was built incorrectly. Please check the `readme.md` to more info.');

let spawn;
try {
Expand All @@ -30,6 +30,13 @@ module.exports = class Session extends EventEmitter {
TERM_PROGRAM_VERSION: version
}, envFromConfig);

// Electron has a default value for process.env.GOOGLE_API_KEY
// We don't want to leak this to the shell
// See https://github.com/zeit/hyper/issues/696
if (baseEnv.GOOGLE_API_KEY && process.env.GOOGLE_API_KEY === baseEnv.GOOGLE_API_KEY) {
delete baseEnv.GOOGLE_API_KEY;
}

const decoder = new StringDecoder('utf8');

const defaultShellArgs = ['--login'];
Expand All @@ -49,7 +56,7 @@ module.exports = class Session extends EventEmitter {
}
}

this.pty.stdout.on('data', data => {
this.pty.on('data', data => {
if (this.ended) {
return;
}
Expand All @@ -71,12 +78,12 @@ module.exports = class Session extends EventEmitter {
}

write(data) {
this.pty.stdin.write(data);
this.pty.write(data);
}

resize({cols, rows}) {
try {
this.pty.stdout.resize(cols, rows);
this.pty.resize(cols, rows);
} catch (err) {
console.error(err.stack);
}
Expand Down
Loading

0 comments on commit dcc5409

Please sign in to comment.