Skip to content

Commit 09b1eee

Browse files
authored
Merge pull request #100 from brism17/brism/ansioutputoptions
Making nteract outputs more configurable for ansi outputs
2 parents d848959 + f616866 commit 09b1eee

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

Diff for: packages/outputs/__tests__/output.spec.tsx

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { mount, shallow } from "enzyme";
22
import * as React from "react";
3-
3+
import Ansi from "ansi-to-react";
44
import { createImmutableOutput, ImmutableOutput } from "@nteract/commutable";
55

66
import {
@@ -113,6 +113,46 @@ describe("Output", () => {
113113
});
114114
});
115115

116+
describe("Output ansi options", () => {
117+
it("stream data", () => {
118+
const output = createImmutableOutput({
119+
output_type: "stream",
120+
name: "stdout",
121+
text: "hey"
122+
});
123+
124+
const component = mount(
125+
<Output output={output}>
126+
<StreamText linkify={false} useClasses={true} />
127+
</Output>
128+
);
129+
130+
expect(component.find("StreamText")).not.toBeNull();
131+
expect(component.find(Ansi).prop("linkify")).toBe(false);
132+
expect(component.find(Ansi).prop("useClasses")).toBe(true);
133+
});
134+
135+
it("error data", () => {
136+
const output = createImmutableOutput({
137+
output_type: "error",
138+
traceback: ["Yikes, Will is in the upsidedown again!"],
139+
ename: "NameError",
140+
evalue: "Yikes!"
141+
});
142+
143+
const component = mount(
144+
<Output output={output}>
145+
<KernelOutputError linkify={true} useClasses={true} />
146+
</Output>
147+
);
148+
149+
expect(component.find("KernelOutputError")).not.toBeNull();
150+
expect(component.find(Ansi).prop("linkify")).toBe(true);
151+
expect(component.find(Ansi).prop("useClasses")).toBe(true);
152+
});
153+
});
154+
155+
116156
describe("Full Outputs usage", () => {
117157
const testOutput = createImmutableOutput({
118158
output_type: "display_data",
@@ -219,4 +259,5 @@ describe("Output with an array of output_types", () => {
219259
expect(wrapperExecuteResult.find(Media.HTML).exists()).toEqual(true);
220260
expect(wrapperOtherOutput.html()).toEqual("");
221261
});
262+
222263
});

Diff for: packages/outputs/src/components/kernel-output-error.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ interface Props {
88
className?: string;
99
output: ImmutableErrorOutput;
1010
output_type: "error";
11+
linkify?: boolean;
12+
useClasses?: boolean;
1113
}
1214

1315
const PlainKernelOutputError = (props: Partial<Props>) => {
@@ -33,7 +35,7 @@ const PlainKernelOutputError = (props: Partial<Props>) => {
3335
}
3436

3537
return (
36-
<Ansi className={props.className} linkify={false}>
38+
<Ansi className={props.className} linkify={props.linkify ?? false} useClasses={props.useClasses ?? false }>
3739
{kernelOutputError.join("\n")}
3840
</Ansi>
3941
);

Diff for: packages/outputs/src/components/stream-text.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as React from "react";
55
interface Props {
66
output_type: "stream";
77
output: ImmutableStreamOutput;
8+
linkify?: boolean;
9+
useClasses?: boolean;
810
}
911

1012
export class StreamText extends React.PureComponent<Props> {
@@ -14,18 +16,18 @@ export class StreamText extends React.PureComponent<Props> {
1416
};
1517

1618
render() {
17-
const { output } = this.props;
19+
const { output, linkify, useClasses } = this.props;
1820
if (!output) {
1921
return null;
2022
}
2123
const { text, name } = output;
2224

2325
return (
24-
<Ansi linkify className={`nteract-display-area-${name}`}>
26+
<Ansi linkify={linkify ?? true} className={`nteract-display-area-${name}`} useClasses={useClasses}>
2527
{text}
2628
</Ansi>
2729
);
2830
}
2931
}
3032

31-
export default StreamText;
33+
export default StreamText;

0 commit comments

Comments
 (0)