export interface CodeSnippetDataProps {
lines: string[];
- lineTransformer?: (line: string) => string;
+ lineFormatter?: (lines: string[], index: number) => string;
className?: string;
apiResponse?: boolean;
linked?: boolean;
});
export const VirtualCodeSnippet = withStyles(styles)(connect(mapStateToProps)(
- ({ classes, lines, linked, className, apiResponse, dispatch, auth }: CodeSnippetProps & CodeSnippetAuthProps & DispatchProp) => {
- const RenderRow = ({index, style}) => (
- <span style={style}>{linked ? renderLinks(auth, dispatch)(lines[index]) : lines[index]}</span>
- );
+ ({ classes, lines, lineFormatter, linked, className, apiResponse, dispatch, auth }: CodeSnippetProps & CodeSnippetAuthProps & DispatchProp) => {
+ const RenderRow = ({index, style}) => {
+ const lineContents = lineFormatter ? lineFormatter(lines, index) : lines[index];
+ return <span style={style}>{linked ? renderLinks(auth, dispatch)(lineContents) : lineContents}</span>
+ };
return <Typography
component="div"
classes,
doHidePanel,
}: ProcessCmdCardProps) => {
- const command = process.containerRequest.command.map((v) =>
- shellescape([v]) // Escape each arg separately
- );
- let formattedCommand = [...command];
- formattedCommand.forEach((item, i, arr) => {
+ const formatLine = (lines: string[], index: number): string => {
+ // Escape each arg separately
+ let line = shellescape([lines[index]])
// Indent lines after the first
- const indent = i > 0 ? ' ' : '';
- // Escape newlines on every non-last arg when there are multiple lines
- const lineBreak = arr.length > 1 && i < arr.length - 1 ? ' \\' : '';
- arr[i] = `${indent}${item}${lineBreak}`;
- });
+ const indent = index > 0 ? ' ' : '';
+ // Add backslash "escaped linebreak"
+ const lineBreak = lines.length > 1 && index < lines.length - 1 ? ' \\' : '';
+
+ return `${indent}${line}${lineBreak}`;
+ };
return (
<Card className={classes.card}>
<Tooltip title="Copy link to clipboard" disableFocusListener>
<IconButton>
<CopyToClipboard
- text={command.join(" ")}
+ text={" "}
onCopy={() => onCopy("Command copied to clipboard")}
>
<CopyIcon />
}
/>
<CardContent className={classes.content}>
- <DefaultVirtualCodeSnippet lines={formattedCommand} linked />
+ <DefaultVirtualCodeSnippet
+ lines={process.containerRequest.command}
+ lineFormatter={formatLine}
+ linked
+ />
</CardContent>
</Card>
);