-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathAddons.js
75 lines (69 loc) · 1.85 KB
/
Addons.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
import React from 'react'
import '../App.css'
import {XTerm} from 'xterm-for-react'
import { SearchAddon } from 'xterm-addon-search';
import SyntaxHighlighter from 'react-syntax-highlighter';
import { dark } from 'react-syntax-highlighter/dist/esm/styles/hljs';
class Addons extends React.Component {
constructor(props) {
super(props)
// Create a ref
this.xtermRef = React.createRef()
this.searchAddon = new SearchAddon();
}
componentDidMount() {
this.xtermRef.current.terminal.writeln(
"Hit enter we will highlight 'THIS' text."
);
}
render() {
return (
<>
{/* Create a new terminal and set it's ref. */}
<XTerm
ref={this.xtermRef}
addons={[this.searchAddon]}
onData={(data) => {
const code = data.charCodeAt(0);
if (code === 13) {
this.searchAddon.findNext("'THIS'")
}
}}
/>
<SyntaxHighlighter language="javascript" style={ dark }>
{`
class Addons extends React.Component {
constructor(props) {
super(props)
// Create a ref
this.xtermRef = React.createRef()
this.searchAddon = new SearchAddon();
}
componentDidMount() {
this.xtermRef.current.terminal.writeln(
"Hit enter we will highlight 'THIS' text."
);
}
render() {
return (
{/* Create a new terminal and set it's ref. */}
<XTerm
ref={this.xtermRef}
addons={[this.searchAddon]}
onData={(data) => {
const code = data.charCodeAt(0);
if (code === 13) {
this.searchAddon.findNext("'THIS'")
}
}}
/>
)
}
}
`}
</SyntaxHighlighter>
</>
)
}
}
export default Addons