forked from rmoorman/react-jupyter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOutput.js
54 lines (45 loc) · 1.18 KB
/
Output.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
import React, { Component } from 'react'
import PropTypes from 'prop-types';
import ansi_up from 'ansi_up'
import DisplayData from './DisplayData'
import DisplayError from './DisplayError'
import Code from './Code'
const joinText = text => {
if (text.join) {
return text.map(joinText).join("")
} else {
return text
}
}
class Output extends Component {
static propTypes = {
number: PropTypes.number,
showCode: PropTypes.bool
}
render() {
const { raw, number, showCode } = this.props
let output;
if (['display_data', 'execute_result', 'pyout'].includes(raw.output_type)) {
output = <DisplayData raw={raw} number={number} />
}
if (['error', 'pyerr'].includes(raw.output_type)) {
output = <DisplayError raw={raw} number={number} />
}
if (raw.output_type === 'stream') {
const text = joinText(raw.text)
output = (
<Code
showCode={showCode}
className={(raw.stream || raw.name)}
string={ansi_up.ansi_to_html(text)}
/>
)
}
return (
<div className="output" data-prompt-number={number || null}>
{output}
</div>
)
}
}
export default Output