This repository was archived by the owner on Jun 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
87 lines (74 loc) · 2.21 KB
/
index.js
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
const throttle = require('lodash.throttle')
const BUSY_TIMEOUT = 700 // ms
const BUSY_THROTTLE = BUSY_TIMEOUT / 2
module.exports.decorateConfig = config => {
return Object.assign({}, config, {
termCSS: `
${config.termCSS || ''}
.cursor-node[focus=true]:not([hyper-blink-moving]) {
animation: blink 1s ease infinite;
}
@keyframes blink {
10%, 50% { opacity: 0 }
60%, 100% { opacity: 1 }
}
`
})
}
module.exports.decorateTerm = (Term, {React, notify}) => {
return class extends React.Component {
constructor (props, context) {
super(props, context)
this._onTerminal = this._onTerminal.bind(this)
this._onCursorChange = this._onCursorChange.bind(this)
this._updateCursorStatus = this._updateCursorStatus.bind(this)
this._markBusyThrottled = throttle(this._markBusy.bind(this), BUSY_THROTTLE)
this._markIdle = this._markIdle.bind(this)
}
_onTerminal (term) {
/* eslint-disable prop-types */
if (this.props.onTerminal) {
this.props.onTerminal(term)
}
this._cursor = term.cursorNode_
/* global MutationObserver */
this._observer = new MutationObserver(this._onCursorChange)
this._observer.observe(this._cursor, {
attributes: true,
childList: false,
characterData: false
})
}
_onCursorChange (mutations) {
const cursorMoved = mutations.some(m => m.attributeName === 'title')
if (cursorMoved) {
this._updateCursorStatus()
}
}
_updateCursorStatus () {
this._markBusyThrottled()
clearTimeout(this._markingTimer)
this._markingTimer = setTimeout(() => {
this._markIdle()
}, BUSY_TIMEOUT)
}
_markBusy () {
// console.log('!!! Cursor Moving !!!')
this._cursor.setAttribute('hyper-blink-moving', true)
}
_markIdle () {
// console.log('...idle...')
this._cursor.removeAttribute('hyper-blink-moving')
}
render () {
return React.createElement(Term, Object.assign({}, this.props, {
onTerminal: this._onTerminal
}))
}
componentWillUnmount () {
if (this._observer) {
this._observer.disconnect()
}
}
}
}