hyper/lib/components/terms.js
Matheus Fernandes 9c90e19760 Add Windows support and first-class Linux support (#946)
* `child_pty` => `pty.js`

* Create a frameless window on Windows and Linux

* Add a brand new UI for Linux and Windows 💅

* [Windows] Fix plugin installation

* [Windows] Fix the `build` script

* [Windows] Add a bigger `icon.ico`

* [Mac] Add `WebKitAppRegion: drag` when running on macOS

* Fix code style 🤔

* Add `appveyor.yml`

* Fix code style (again)

* [Windows] Fix AppVeyor's `install` script

* [Windows] Try a new AppVeyor config

* [Windows] Set the binary path so Spectron can run the tests

* [Windows] Try to build on x64

* Try again to build on x64

* Try one more time 😩

* Throw an error to indicate that `pty.js` was built incorrectly

* [Win/Linux] Add `display: hidden` to <Tabs /> if tabs.length === 1

* [Win/Linux] Reorganize SVGs – via @CodeTheory

* [Win/Linux] Fix the hamburger menu height

* Make the SVGs look better with `shape-rendering: crispEdges;`

* [Win/Linux] Add config options for the window controls and the 🍔 menu

* Add `electron-squirrel-startup` dependency

* [Win] Handle Squirrel commands

* [Win/Linux] Fix default color for the 🍔 and window controls – via @CodeTheory

* [Win/Linux] Add some padding - via @CodeTheory

* [Win/Linux] Add hover states – via @CodeTheory

* [Win] Fix empty window/tab titles

* [Win] Fix opening Preferences (#978)

* [Win] Fix opening Preferences

* Update ui.js

* Update ui.js

* Enhance messages and default editor

* [Win] Add dependency instructions to the README.md [skip ci]

* Fix code style

* [Win/Linux] Check the number of open windows before quitting the app
2016-11-11 15:18:04 -02:00

156 lines
3.8 KiB
JavaScript

import React from 'react';
import Component from '../component';
import {decorate, getTermGroupProps} from '../utils/plugins';
import TermGroup_ from './term-group';
const TermGroup = decorate(TermGroup_, 'TermGroup');
const isMac = /Mac/.test(navigator.userAgent);
export default class Terms extends Component {
constructor(props, context) {
super(props, context);
this.terms = {};
this.bound = new WeakMap();
this.onRef = this.onRef.bind(this);
props.ref_(this);
}
componentWillReceiveProps(next) {
const {write} = next;
if (write && this.props.write !== write) {
this.getTermByUid(write.uid).write(write.data);
}
}
shouldComponentUpdate(nextProps) {
for (const i in nextProps) {
if (i === 'write') {
continue;
}
if (this.props[i] !== nextProps[i]) {
return true;
}
}
for (const i in this.props) {
if (i === 'write') {
continue;
}
if (this.props[i] !== nextProps[i]) {
return true;
}
}
return false;
}
onRef(uid, term) {
if (term) {
this.terms[uid] = term;
} else if (!this.props.sessions[uid]) {
delete this.terms[uid];
}
}
getTermByUid(uid) {
return this.terms[uid];
}
getActiveTerm() {
return this.getTermByUid(this.props.activeSession);
}
getLastTermIndex() {
return this.props.sessions.length - 1;
}
onTerminal(uid, term) {
this.terms[uid] = term;
}
componentWillUnmount() {
this.props.ref_(null);
}
template(css) {
const shift = !isMac && this.props.termGroups.length > 1;
return (<div
className={css('terms', shift && 'termsShifted')}
>
{ this.props.customChildrenBefore }
{
this.props.termGroups.map(termGroup => {
const {uid} = termGroup;
const isActive = uid === this.props.activeRootGroup;
const props = getTermGroupProps(uid, this.props, {
termGroup,
terms: this.terms,
sessions: this.props.sessions,
customCSS: this.props.customCSS,
fontSize: this.props.fontSize,
borderColor: this.props.borderColor,
cursorColor: this.props.cursorColor,
cursorShape: this.props.cursorShape,
fontFamily: this.props.fontFamily,
fontSmoothing: this.props.fontSmoothing,
foregroundColor: this.props.foregroundColor,
backgroundColor: this.props.backgroundColor,
padding: this.props.padding,
colors: this.props.colors,
bell: this.props.bell,
bellSoundURL: this.props.bellSoundURL,
copyOnSelect: this.props.copyOnSelect,
modifierKeys: this.props.modifierKeys,
onActive: this.props.onActive,
onResize: this.props.onResize,
onTitle: this.props.onTitle,
onData: this.props.onData,
onURLAbort: this.props.onURLAbort
});
return (
<div
key={`d${uid}`}
className={css('termGroup', isActive && 'termGroupActive')}
>
<TermGroup
key={uid}
ref_={this.onRef}
{...props}
/>
</div>
);
})
}
{ this.props.customChildren }
</div>);
}
styles() {
return {
terms: {
position: 'absolute',
marginTop: '34px',
top: 0,
right: 0,
left: 0,
bottom: 0,
color: '#fff',
transition: isMac ? '' : 'margin-top 0.3s ease'
},
termsShifted: {
marginTop: '68px'
},
termGroup: {
display: 'none',
width: '100%',
height: '100%'
},
termGroupActive: {
display: 'block'
}
};
}
}