Skip to content

Commit

Permalink
feat(cli): handle non-tty streams
Browse files Browse the repository at this point in the history
- git-bash on windows does not support raw mode
- render `<Messages />` without `<MessageScrollBox />`
  • Loading branch information
AriPerkkio committed Nov 6, 2020
1 parent b79ae5d commit b08c2e6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ module.exports = {
'no-process-exit': 'off',
'prettier/prettier': 'error',
'node/no-unsupported-features/es-syntax': 'off',
'react/prop-types': ['error', { ignore: ['children'] }], // Already covered by React.FC
},
overrides: [
{
files: ['*.tsx'],
rules: {
'react/prop-types': ['off'], // Covered by React.FC
},
},
{
files: ['*config*', 'test/**/*.ts'],
rules: {
Expand Down
20 changes: 17 additions & 3 deletions lib/ui/components/AppCLI.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { Newline, Text } from 'ink';

import Status from './Status';
import Tasks from './Tasks';
Expand All @@ -11,7 +12,7 @@ import useOnHorizontalResize from '../hooks/useOnHorizontalResize';
/**
* Application for CLIs
*/
export default function AppCLI(): JSX.Element {
const AppCLI: React.FC<{ isTTY: boolean }> = ({ isTTY }) => {
const done = useOnExit();

// Clear screen completely on horizontal resize
Expand All @@ -22,11 +23,24 @@ export default function AppCLI(): JSX.Element {
return <FinalLog />;
}

// Scrollbox can only be rendered in TTY
const wrapper = isTTY ? MessagesScrollBox : undefined;

return (
<>
{!isTTY && (
<Text color='red'>
Terminal is not detected as TTY. Scrollbox is disabled.
<Newline />
</Text>
)}

<Status />
<Tasks />
<Messages wrapper={MessagesScrollBox} />
{!isTTY && <Text>{/* Spacer */}</Text>}
<Messages wrapper={wrapper} />
</>
);
}
};

export default AppCLI;
7 changes: 5 additions & 2 deletions lib/ui/render-application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import AppCI from './components/AppCI';
import AppCLI from './components/AppCLI';

export default function renderApplication(): void {
render(config.CI ? <AppCI /> : <AppCLI />, {
// Both stdout and stdin need to be TTY in order to get scrollbox working
const isTTY = !!(process.stdout.isTTY && process.stdin.isTTY);

render(config.CI ? <AppCI /> : <AppCLI isTTY={isTTY} />, {
// CLIs will exit by useScroll hook, CIs by default
exitOnCtrlC: config.CI,
exitOnCtrlC: config.CI || !isTTY,
});
}

0 comments on commit b08c2e6

Please sign in to comment.