-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respect ANSI color codes in check output (#392)
Signed-off-by: James Phillips <jamesdphillips@gmail.com>
- Loading branch information
1 parent
20a7ad0
commit 5fcc5ff
Showing
8 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* eslint-disable react/prop-types */ | ||
|
||
import React from "/vendor/react"; | ||
import Skeleton from "./Skeleton"; | ||
import { ANSIColorLazyProps } from "./ANSIColorLazy"; | ||
|
||
export type ANSIColorProps = ANSIColorLazyProps; | ||
|
||
const Component = React.lazy(() => import("./ANSIColorLazy")); | ||
|
||
const ANSIColor: React.FC<ANSIColorProps> = ({ ref, ...props }) => { | ||
return ( | ||
<React.Suspense fallback={<Skeleton variant="text">loading</Skeleton>}> | ||
<Component {...props} /> | ||
</React.Suspense> | ||
); | ||
}; | ||
|
||
export default ANSIColor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Convert from "ansi-to-html"; | ||
import { encodeXML } from "entities"; | ||
|
||
onmessage = message => { | ||
const [data] = message.data.msg; | ||
const convert = new Convert(); | ||
postMessage([message.data.key, convert.toHtml(encodeXML(data))]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from "react"; | ||
|
||
export interface ANSIColorLazyProps | ||
extends Omit<React.HTMLProps<HTMLSpanElement>, "children"> { | ||
children?: string; | ||
} | ||
|
||
declare const ANSIColorLazy: React.FC<ANSIColorLazyProps>; | ||
export default ANSIColorLazy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* eslint-disable react/prop-types */ | ||
|
||
import React from "/vendor/react"; | ||
import Worker from "./ANSIColor.worker"; | ||
|
||
const worker = new Worker(); | ||
const pending = {}; | ||
|
||
worker.onmessage = event => { | ||
const [key, data] = event.data; | ||
pending[key].call(this, data); | ||
}; | ||
|
||
let idx = 0; | ||
function postMessage(msg, callback) { | ||
const key = idx; | ||
pending[idx] = data => { | ||
callback(data); | ||
delete pending[idx]; | ||
}; | ||
worker.postMessage({ key, msg }); | ||
idx += 1; | ||
} | ||
|
||
const ANSIColor = ({ children, ...other }) => { | ||
const [result, setResult] = React.useState({ value: "", processed: false }); | ||
React.useEffect(() => { | ||
postMessage([children], result => { | ||
setResult({ value: result, processed: true }); | ||
}); | ||
}, [children, setResult]); | ||
|
||
return <code dangerouslySetInnerHTML={{ __html: result.value }} {...other} />; | ||
}; | ||
|
||
export default ANSIColor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters