-
Notifications
You must be signed in to change notification settings - Fork 9
/
terminal.jsx
67 lines (54 loc) · 1.52 KB
/
terminal.jsx
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
/* global ResizeObserver */
import React from 'react'
import {Disposable} from 'event-kit'
import debouncer from 'debounce-fn'
import Component from '../utils/component.jsx'
export default class Terminal extends Component {
render() {
return <archipelago-terminal ref={this.setRef} />
}
setRef(container) {
this.container = container
}
fit() {
if (this.props.tabId === this.props.currentTabId) {
debouncer(this.props.session.fit, {wait: 150})()
}
}
componentDidMount() {
const {session} = this.props
session.attach(this.container)
this.resizeObserver.observe(this.container)
}
initialize() {
this.resizeObserver = new ResizeObserver(this.fit)
}
bindListeners() {
this.addSubscription(
new Disposable(() => this.resizeObserver.unobserve(this.container))
)
this.addSubscription(
this.props.session.onFocus(() => {
this.props.selectSession(this.props.session.id)
this.props.changeTitle(this.props.tabId, this.props.session.title)
})
)
this.addSubscription(
this.props.session.onTitle(title => {
this.props.changeTitle(this.props.tabId, title)
})
)
this.addSubscription(
this.props.session.onExit(() => {
this.props.removeSession(this.props.tabId, this.props.session.id)
})
)
this.addSubscription(
this.props.session.onData(() => {
if (this.props.currentTabId !== this.props.tabId) {
this.props.markUnread(this.props.tabId)
}
})
)
}
}