Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making nteract outputs more configurable for ansi outputs #100

Merged
merged 1 commit into from
Mar 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion packages/outputs/__tests__/output.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mount, shallow } from "enzyme";
import * as React from "react";

import Ansi from "ansi-to-react";
import { createImmutableOutput, ImmutableOutput } from "@nteract/commutable";

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

describe("Output ansi options", () => {
it("stream data", () => {
const output = createImmutableOutput({
output_type: "stream",
name: "stdout",
text: "hey"
});

const component = mount(
<Output output={output}>
<StreamText linkify={false} useClasses={true} />
</Output>
);

expect(component.find("StreamText")).not.toBeNull();
expect(component.find(Ansi).prop("linkify")).toBe(false);
expect(component.find(Ansi).prop("useClasses")).toBe(true);
});

it("error data", () => {
const output = createImmutableOutput({
output_type: "error",
traceback: ["Yikes, Will is in the upsidedown again!"],
ename: "NameError",
evalue: "Yikes!"
});

const component = mount(
<Output output={output}>
<KernelOutputError linkify={true} useClasses={true} />
</Output>
);

expect(component.find("KernelOutputError")).not.toBeNull();
expect(component.find(Ansi).prop("linkify")).toBe(true);
expect(component.find(Ansi).prop("useClasses")).toBe(true);
});
});


describe("Full Outputs usage", () => {
const testOutput = createImmutableOutput({
output_type: "display_data",
@@ -219,4 +259,5 @@ describe("Output with an array of output_types", () => {
expect(wrapperExecuteResult.find(Media.HTML).exists()).toEqual(true);
expect(wrapperOtherOutput.html()).toEqual("");
});

});
4 changes: 3 additions & 1 deletion packages/outputs/src/components/kernel-output-error.tsx
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@ interface Props {
className?: string;
output: ImmutableErrorOutput;
output_type: "error";
linkify?: boolean;
useClasses?: boolean;
}

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

return (
<Ansi className={props.className} linkify={false}>
<Ansi className={props.className} linkify={props.linkify ?? false} useClasses={props.useClasses ?? false }>
{kernelOutputError.join("\n")}
</Ansi>
);
8 changes: 5 additions & 3 deletions packages/outputs/src/components/stream-text.tsx
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@ import * as React from "react";
interface Props {
output_type: "stream";
output: ImmutableStreamOutput;
linkify?: boolean;
useClasses?: boolean;
}

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

render() {
const { output } = this.props;
const { output, linkify, useClasses } = this.props;
if (!output) {
return null;
}
const { text, name } = output;

return (
<Ansi linkify className={`nteract-display-area-${name}`}>
<Ansi linkify={linkify ?? true} className={`nteract-display-area-${name}`} useClasses={useClasses}>
{text}
</Ansi>
);
}
}

export default StreamText;
export default StreamText;