forked from bomanimc/gitrocket
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitRocketTerminal.jsx
More file actions
140 lines (121 loc) · 3.65 KB
/
GitRocketTerminal.jsx
File metadata and controls
140 lines (121 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* eslint no-underscore-dangle: 0 */
/* eslint react/no-multi-comp: 0 */
import PropTypes from 'prop-types';
import { Rocket, RocketSpan, FinTop, FinBottom, Fire, Wastes } from './styledElements';
// This function performs regex matching on expected shell output for git push result being input
// at the command line. Currently it supports output from bash, zsh, fish, cmd and powershell.
function detectPushCommand(data) {
const patterns = ['To(.+)\.git'];
const antiPatterns = ['error:'];
return new RegExp(`(${patterns.join(')|(')})`).test(data) && !new RegExp(`(${antiPatterns.join(')|(')})`).test(data);
}
exports.middleware = store => next => (action) => {
if (action.type === 'SESSION_ADD_DATA') {
const { data } = action;
// The data length check verifies it is a push, not a duplicate output of the console
if (detectPushCommand(data) && data.length < 1000) {
store.dispatch({
type: 'PUSH_MODE_TOGGLE',
});
}
next(action);
} else {
next(action);
}
};
exports.reduceUI = (state, action) => {
switch (action.type) {
case 'PUSH_MODE_TOGGLE':
return state.set('rocketState', (state.rocketState + 1) || 1);
default:
return state;
}
};
const passProps = (uid, parentProps, props) => Object.assign(props, {
rocketState: parentProps.rocketState,
});
exports.mapTermsState = (state, map) => Object.assign(map, {
rocketState: state.ui.rocketState,
});
exports.getTermGroupProps = passProps;
exports.getTermProps = passProps;
exports.decorateTerm = (Term, { React }) => {
class GitRocket extends React.Component {
constructor() {
super();
this.state = {
display: false,
};
}
componentDidMount() {
const rocket = document.getElementById('rocket');
rocket.addEventListener('animationend', () => {
this.setState({
display: false,
});
});
}
componentWillReceiveProps(nextProps) {
if ((nextProps.rocketState > this.props.rocketState) ||
(nextProps.rocketState !== undefined &&
this.props.rocketState === undefined)) {
this.setState({
display: true,
});
}
return nextProps;
}
render() {
return (
// Markup and styling for this section is adapted from Kevin Boudot's
// Pen at https://codepen.io/kevinboudot/pen/EaQeNL
<Rocket id="rocket" display={this.state.display}>
<RocketSpan>
<FinTop />
<FinBottom />
<Fire />
<Wastes>
<i />
<i />
<i />
<i />
<i />
</Wastes>
</RocketSpan>
</Rocket>
);
}
}
// Define and return our higher order component.
class HOCTerm extends React.Component {
constructor(props, context) {
super(props, context);
this._onTerminal = this._onTerminal.bind(this);
this._div = null;
this._observer = null;
}
_onTerminal(term) {
if (this.props.onTerminal) this.props.onTerminal(term);
this._div = term.div_;
this._window = term.document_.defaultView;
}
render() {
return (
<div style={{ width: '100%', height: '100%', position: 'relative' }}>
{React.createElement(Term, Object.assign({}, this.props, {
onTerminal: this._onTerminal,
}))}
<GitRocket rocketState={this.props.rocketState} />
</div>
);
}
}
GitRocket.propTypes = {
rocketState: PropTypes.number.isRequired,
};
HOCTerm.propTypes = {
onTerminal: PropTypes.func.isRequired,
rocketState: PropTypes.number.isRequired,
};
return HOCTerm;
};