Skip to content

Commit

Permalink
chore: add the ability to wrap the terminal commands
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Oct 21, 2020
1 parent ee8c5ea commit ce4618b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/@newrelic/gatsby-theme-newrelic/components/CodeBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ const CustomCodeBlock = ({
children,
animate,
copyable,
wrap,
...props
}) => {
return isShellLanguage(language) ? (
<Terminal animate={animate} copyable={copyable}>
<Terminal animate={animate} copyable={copyable} wrap={wrap}>
{children}
</Terminal>
) : (
Expand Down
18 changes: 13 additions & 5 deletions src/components/Terminal/CommandLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const CommandLine = ({
prompt,
typingDelay,
onFinishedTyping,
wrap,
}) => {
const element = animate ? (
<Typist
Expand All @@ -44,19 +45,24 @@ const CommandLine = ({
return (
<div
css={css`
display: grid;
grid-template-columns: 1ch auto;
grid-gap: 1ch;
display: flex;
flex-wrap: ${wrap ? 'wrap' : null};
gap: 1ch;
justify-content: start;
align-items: baseline;
align-items: flex-start;
@supports not (gap: 1ch) {
margin-right: 1ch;
}
`}
>
<Prompt character={prompt} />
<div
css={css`
flex: 1;
position: relative;
color: #fafafa;
white-space: pre;
white-space: ${wrap ? 'pre-wrap' : 'pre'};
&:empty {
height: 100%;
Expand Down Expand Up @@ -91,12 +97,14 @@ CommandLine.propTypes = {
prompt: PropTypes.oneOf(['$', '>']),
typingDelay: PropTypes.number,
onFinishedTyping: PropTypes.func,
wrap: PropTypes.bool,
};

CommandLine.defaultProps = {
animate: false,
avgTypingDelay: 40,
typingDelay: 0,
wrap: false,
};

export default CommandLine;
7 changes: 5 additions & 2 deletions src/components/Terminal/Shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import MenuBar from './MenuBar';
import { useIntersection } from 'react-use';
import { useClipboard } from '@newrelic/gatsby-theme-newrelic';

const Shell = ({ animate, copyable, highlight, code }) => {
const Shell = ({ animate, copyable, highlight, code, wrap }) => {
const { tokens, getTokenProps } = highlight;
const lines = translateLines(tokens, code);

Expand Down Expand Up @@ -103,7 +103,7 @@ const Shell = ({ animate, copyable, highlight, code }) => {
const previousLine = renderedLines[idx - 1];

return type === 'OUTPUT' ? (
<ShellOutput key={idx} line={line} />
<ShellOutput key={idx} line={line} wrap={wrap} />
) : (
<CommandLine
key={idx}
Expand All @@ -117,13 +117,15 @@ const Shell = ({ animate, copyable, highlight, code }) => {
}
typingDelay={getTypingDelay(line, previousLine)}
onFinishedTyping={() => send('PRESS_ENTER')}
wrap={wrap}
>
{line.map((token, key) => (
// eslint-disable-next-line react/jsx-key
<span
css={css`
display: inline-block;
vertical-align: baseline;
word-break: break-all;
`}
{...getTokenProps({ token, key })}
/>
Expand Down Expand Up @@ -181,6 +183,7 @@ Shell.propTypes = {
tokens: PropTypes.array.isRequired,
getTokenProps: PropTypes.func.isRequired,
}),
wrap: PropTypes.bool,
};

export default Shell;

0 comments on commit ce4618b

Please sign in to comment.