2016-07-13 12:44:24 -08:00
|
|
|
import React from 'react';
|
2016-10-03 18:00:50 -08:00
|
|
|
import {decorate, getTermGroupProps} from '../utils/plugins';
|
2017-11-02 18:51:18 -08:00
|
|
|
import {registerCommandHandlers} from '../command-registry';
|
2016-10-03 18:00:50 -08:00
|
|
|
import TermGroup_ from './term-group';
|
2017-06-11 02:42:39 -08:00
|
|
|
import StyleSheet_ from './style-sheet';
|
2016-07-13 12:44:24 -08:00
|
|
|
|
2016-10-03 18:00:50 -08:00
|
|
|
const TermGroup = decorate(TermGroup_, 'TermGroup');
|
2017-06-11 02:42:39 -08:00
|
|
|
const StyleSheet = decorate(StyleSheet_, 'StyleSheet');
|
|
|
|
|
|
2016-11-11 08:18:04 -09:00
|
|
|
const isMac = /Mac/.test(navigator.userAgent);
|
2016-07-13 12:44:24 -08:00
|
|
|
|
2018-03-17 04:51:36 -08:00
|
|
|
export default class Terms extends React.Component {
|
2016-09-21 06:27:11 -08:00
|
|
|
constructor(props, context) {
|
2016-07-13 12:44:24 -08:00
|
|
|
super(props, context);
|
|
|
|
|
this.terms = {};
|
|
|
|
|
this.bound = new WeakMap();
|
|
|
|
|
this.onRef = this.onRef.bind(this);
|
2017-11-02 18:51:18 -08:00
|
|
|
this.registerCommands = registerCommandHandlers;
|
2016-07-13 12:44:24 -08:00
|
|
|
props.ref_(this);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
shouldComponentUpdate(nextProps) {
|
2016-07-14 07:45:59 -08:00
|
|
|
for (const i in nextProps) {
|
2016-09-21 06:27:11 -08:00
|
|
|
if (i === 'write') {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-07-14 07:45:59 -08:00
|
|
|
if (this.props[i] !== nextProps[i]) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (const i in this.props) {
|
2016-09-21 06:27:11 -08:00
|
|
|
if (i === 'write') {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-07-14 07:45:59 -08:00
|
|
|
if (this.props[i] !== nextProps[i]) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
2016-07-14 07:45:59 -08:00
|
|
|
return false;
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
onRef(uid, term) {
|
2016-07-13 12:44:24 -08:00
|
|
|
if (term) {
|
|
|
|
|
this.terms[uid] = term;
|
2016-10-03 18:00:50 -08:00
|
|
|
} else if (!this.props.sessions[uid]) {
|
2016-07-13 12:44:24 -08:00
|
|
|
delete this.terms[uid];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
getTermByUid(uid) {
|
2016-07-13 12:44:24 -08:00
|
|
|
return this.terms[uid];
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
getActiveTerm() {
|
2016-07-13 12:44:24 -08:00
|
|
|
return this.getTermByUid(this.props.activeSession);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
getLastTermIndex() {
|
2016-07-22 11:38:15 -08:00
|
|
|
return this.props.sessions.length - 1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
onTerminal(uid, term) {
|
2016-07-13 12:44:24 -08:00
|
|
|
this.terms[uid] = term;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-03 12:24:41 -08:00
|
|
|
componentDidMount() {
|
|
|
|
|
window.addEventListener('contextmenu', () => {
|
|
|
|
|
const selection = window.getSelection().toString();
|
|
|
|
|
const {props: {uid}} = this.getActiveTerm();
|
|
|
|
|
this.props.onContextMenu(uid, selection);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
componentWillUnmount() {
|
2016-07-13 12:44:24 -08:00
|
|
|
this.props.ref_(null);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-17 04:51:36 -08:00
|
|
|
render() {
|
2016-11-11 08:18:04 -09:00
|
|
|
const shift = !isMac && this.props.termGroups.length > 1;
|
2017-09-10 05:35:10 -08:00
|
|
|
return (
|
2018-03-17 04:51:36 -08:00
|
|
|
<div className={`terms_terms ${shift ? 'terms_termsShifted' : ''}`}>
|
2017-09-10 05:35:10 -08:00
|
|
|
{this.props.customChildrenBefore}
|
|
|
|
|
{this.props.termGroups.map(termGroup => {
|
2016-10-03 18:00:50 -08:00
|
|
|
const {uid} = termGroup;
|
|
|
|
|
const isActive = uid === this.props.activeRootGroup;
|
|
|
|
|
const props = getTermGroupProps(uid, this.props, {
|
|
|
|
|
termGroup,
|
|
|
|
|
terms: this.terms,
|
2016-11-19 11:05:48 -09:00
|
|
|
activeSession: this.props.activeSession,
|
2016-10-03 18:00:50 -08:00
|
|
|
sessions: this.props.sessions,
|
2017-12-04 12:28:40 -09:00
|
|
|
backgroundColor: this.props.backgroundColor,
|
2018-01-09 07:33:24 -09:00
|
|
|
foregroundColor: this.props.foregroundColor,
|
2016-10-03 18:00:50 -08:00
|
|
|
borderColor: this.props.borderColor,
|
2018-01-09 07:33:24 -09:00
|
|
|
selectionColor: this.props.selectionColor,
|
|
|
|
|
colors: this.props.colors,
|
2016-07-21 15:15:23 -08:00
|
|
|
cursorShape: this.props.cursorShape,
|
2017-02-17 15:11:23 -09:00
|
|
|
cursorBlink: this.props.cursorBlink,
|
2018-01-09 07:33:24 -09:00
|
|
|
cursorColor: this.props.cursorColor,
|
2017-08-02 11:05:47 -08:00
|
|
|
fontSize: this.props.fontSize,
|
|
|
|
|
fontFamily: this.props.fontFamily,
|
2017-02-17 18:15:55 -09:00
|
|
|
uiFontFamily: this.props.uiFontFamily,
|
2018-02-14 04:09:02 -09:00
|
|
|
fontWeight: this.props.fontWeight,
|
|
|
|
|
fontWeightBold: this.props.fontWeightBold,
|
2016-10-03 18:00:50 -08:00
|
|
|
padding: this.props.padding,
|
2016-08-05 14:30:40 -08:00
|
|
|
bell: this.props.bell,
|
2016-08-13 13:03:44 -08:00
|
|
|
bellSoundURL: this.props.bellSoundURL,
|
2016-09-30 04:30:11 -08:00
|
|
|
copyOnSelect: this.props.copyOnSelect,
|
2016-10-03 18:00:50 -08:00
|
|
|
modifierKeys: this.props.modifierKeys,
|
|
|
|
|
onActive: this.props.onActive,
|
|
|
|
|
onResize: this.props.onResize,
|
|
|
|
|
onTitle: this.props.onTitle,
|
|
|
|
|
onData: this.props.onData,
|
2017-02-15 11:22:09 -09:00
|
|
|
onURLAbort: this.props.onURLAbort,
|
2017-11-03 12:24:41 -08:00
|
|
|
onContextMenu: this.props.onContextMenu,
|
2017-03-27 11:40:42 -08:00
|
|
|
quickEdit: this.props.quickEdit,
|
|
|
|
|
parentProps: this.props
|
2016-07-13 12:44:24 -08:00
|
|
|
});
|
2016-10-03 18:00:50 -08:00
|
|
|
|
|
|
|
|
return (
|
2018-03-17 04:51:36 -08:00
|
|
|
<div key={`d${uid}`} className={`terms_termGroup ${isActive ? 'terms_termGroupActive' : ''}`}>
|
2017-09-10 05:35:10 -08:00
|
|
|
<TermGroup key={uid} ref_={this.onRef} {...props} />
|
2016-10-03 18:00:50 -08:00
|
|
|
</div>
|
|
|
|
|
);
|
2017-09-10 05:35:10 -08:00
|
|
|
})}
|
|
|
|
|
{this.props.customChildren}
|
|
|
|
|
<StyleSheet
|
2017-12-04 12:28:40 -09:00
|
|
|
backgroundColor={this.props.backgroundColor}
|
2017-09-10 05:35:10 -08:00
|
|
|
customCSS={this.props.customCSS}
|
|
|
|
|
fontFamily={this.props.fontFamily}
|
|
|
|
|
foregroundColor={this.props.foregroundColor}
|
|
|
|
|
borderColor={this.props.borderColor}
|
|
|
|
|
/>
|
2018-03-17 04:51:36 -08:00
|
|
|
|
|
|
|
|
<style jsx>{`
|
|
|
|
|
.terms_terms {
|
|
|
|
|
position: absolute;
|
|
|
|
|
margin-top: 34px;
|
|
|
|
|
top: 0;
|
|
|
|
|
right: 0;
|
|
|
|
|
left: 0;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
color: #fff;
|
|
|
|
|
transition: ${isMac ? 'none' : 'margin-top 0.3s ease'};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.terms_termsShifted {
|
|
|
|
|
margin-top: 68px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.terms_termGroup {
|
|
|
|
|
display: block;
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 0;
|
|
|
|
|
left: -9999em; /* Offscreen to pause xterm rendering, thanks to IntersectionObserver */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.terms_termGroupActive {
|
|
|
|
|
left: 0;
|
|
|
|
|
}
|
|
|
|
|
`}</style>
|
2017-09-10 05:35:10 -08:00
|
|
|
</div>
|
|
|
|
|
);
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
}
|