hyper/lib/containers/hyper.js

135 lines
3 KiB
JavaScript
Raw Normal View History

/* eslint-disable react/no-danger */
2016-07-13 12:44:24 -08:00
import React from 'react';
import Component from '../component';
import {connect} from '../utils/plugins';
import * as uiActions from '../actions/ui';
2016-07-13 12:44:24 -08:00
import HeaderContainer from './header';
import TermsContainer from './terms';
import NotificationsContainer from './notifications';
const isMac = /Mac/.test(navigator.userAgent);
class Hyper extends Component {
constructor(props) {
2016-07-13 12:44:24 -08:00
super(props);
this.handleFocusActive = this.handleFocusActive.bind(this);
2016-07-13 12:44:24 -08:00
this.onTermsRef = this.onTermsRef.bind(this);
}
componentWillReceiveProps(next) {
2016-07-13 12:44:24 -08:00
if (this.props.backgroundColor !== next.backgroundColor) {
// this can be removed when `setBackgroundColor` in electron
// starts working again
2016-07-13 12:44:24 -08:00
document.body.style.backgroundColor = next.backgroundColor;
}
}
handleFocusActive() {
2016-07-13 12:44:24 -08:00
const term = this.terms.getActiveTerm();
if (term) {
term.focus();
}
2016-07-13 12:44:24 -08:00
}
attachKeyListeners() {
2017-08-02 11:05:47 -08:00
// eslint-disable-next-line no-console
console.error('removed key listeners')
2016-07-13 12:44:24 -08:00
}
onTermsRef(terms) {
2016-07-13 12:44:24 -08:00
this.terms = terms;
}
componentDidUpdate(prev) {
2016-07-13 12:44:24 -08:00
if (prev.activeSession !== this.props.activeSession) {
if (this.keys) {
this.keys.reset();
}
this.handleFocusActive();
2016-07-13 12:44:24 -08:00
this.attachKeyListeners();
}
}
componentWillUnmount() {
if (this.keys) {
this.keys.reset();
}
2016-07-13 12:44:24 -08:00
document.body.style.backgroundColor = 'inherit';
}
template(css) {
2017-08-02 11:05:47 -08:00
const {isMac: isMac_, customCSS, uiFontFamily, borderColor, maximized} = this.props;
const borderWidth = isMac_ ? '' :
`${maximized ? '0' : '1'}px`;
Split Panes (#693) * npm: add .npmrc with save-exact=true * split panes: create initial implementation This allows users to split their Hyperterm terms into multiple nested splits, both vertical and horizontal. Fixes #56 * split panes: suport closing tabs and individual panes * split panes: ensure new splits are placed at the correct index New split panes should be placed after the currently active pane, not at the end like they were previously. * split panes: add explicit dependency to uuid * split panes: implement split pane cycling This adds menu buttons for moving back and forward between open split panes in the currect terminal tab. Doesn't add a hotkey yet, needs some bikeshedding. * split panes: move activeSessionUid to its own object It made little sense to have so many objects with `activeSessionUid` set to `null` when it only mattered on the top level. Now it's an object mapping term-group `uid` to `sessionUid` instead. * split panes: make sure closing the last split pane exits the app * split panes: fix a crash after closing specific panes Sometimes the terminal would crash when a specific split pane was closed, because the `activeSessions` mapping wasn't updated correctly. * split panes: fix a bug that caused initial session sizing to be wrong * fix all our focus / blur issues in one fell swoop :O (famous last words) * get rid of react warning * hterm: make sure not to lose focus when VT listens on clicks * term: restore onactive callback * add missing `return` to override (just in case) * split pane: new split pane implementation * goodbye react-split-pane * added term group resizing action and reducer * terms: supply border color so that we can use it for splits * term-group: add resizing hook * term-groups: add resizing constant * remove split pane css side-effect * split panes: pass existing hterm instances to Term * split panes: add keybindings for split pane cycling * split panes: remove unused action * split panes: remove unused styling * split-pane: remove `console.log` * split-pane: remove `console.log` * split panes: rebalance sizes on insert/removal * split panes: pass existing hterm instances to Term * split panes: add keybindings for split pane cycling * split panes: remove unused action * split panes: remove unused styling * split panes: rebalance sizes on insert/removal * split panes: set a minimum size for resizing * split-pane: fix vertical splits * css :| * package: bump electron * split panes: attach onFocus listener to webviews * 1.4.1 and 1.4.2 are broken. they have the following regression: - open google.com on the main window - open a new tab - come back to previous tab. webview is gone :| * split panes: handle PTY exits * split panes: add linux friendly keybindings
2016-10-03 18:00:50 -08:00
return (<div>
2016-07-13 12:44:24 -08:00
<div
style={{fontFamily: uiFontFamily, borderColor, borderWidth}}
2017-08-02 11:05:47 -08:00
className={css('main', isMac_ && 'mainRounded')}
>
<HeaderContainer/>
<TermsContainer ref_={this.onTermsRef}/>
2017-03-18 15:10:31 -08:00
{ this.props.customInnerChildren }
2016-07-13 12:44:24 -08:00
</div>
<NotificationsContainer/>
<style dangerouslySetInnerHTML={{__html: customCSS}}/>
2016-07-13 12:44:24 -08:00
{ this.props.customChildren }
</div>);
2016-07-13 12:44:24 -08:00
}
styles() {
2016-07-13 12:44:24 -08:00
return {
main: {
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
// can be overridden by inline style above
border: '1px solid #333'
},
mainRounded: {
borderRadius: '5px'
}
};
}
}
const HyperContainer = connect(
state => {
2016-07-13 12:44:24 -08:00
return {
isMac,
customCSS: state.ui.css,
uiFontFamily: state.ui.uiFontFamily,
2016-07-13 12:44:24 -08:00
borderColor: state.ui.borderColor,
activeSession: state.sessions.activeUid,
backgroundColor: state.ui.backgroundColor,
maximized: state.ui.maximized
2016-07-13 12:44:24 -08:00
};
},
dispatch => {
2016-07-13 12:44:24 -08:00
return {
moveTo: i => {
dispatch(uiActions.moveTo(i));
2016-07-13 12:44:24 -08:00
},
moveLeft: () => {
dispatch(uiActions.moveLeft());
2016-07-13 12:44:24 -08:00
},
moveRight: () => {
dispatch(uiActions.moveRight());
2016-07-13 12:44:24 -08:00
}
};
},
null,
{withRef: true}
)(Hyper, 'Hyper');
2016-07-13 12:44:24 -08:00
export default HyperContainer;