Skip to content

Commit fdf9dea

Browse files
committed
Fixing --follow output - need to re-apply colours
1 parent ae43434 commit fdf9dea

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

src/components/JobFollow.tsx

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Job, JobLogEntry, LogLevel} from '@cli/types/api.js'
22
import {useJobWatching} from '@cli/utils/index.js'
3+
import { useStderr, useStdout } from 'ink'
34

45
interface JobFollowProps {
56
jobId: string
@@ -9,18 +10,40 @@ interface JobFollowProps {
910
}
1011

1112
// Outputs job logs to stdout/stderr as they come in
12-
export const JobFollow = ({jobId, onComplete, onFailure, projectId}: JobFollowProps) => {
13+
export const JobFollow = ({
14+
jobId,
15+
onComplete,
16+
onFailure,
17+
projectId,
18+
}: JobFollowProps) => {
19+
const {stdout, write: writeOut} = useStdout();
20+
const {stderr, write: writeErr} = useStderr();
21+
22+
// Only emit ANSI when we're actually writing to a TTY.
23+
const useAnsi = Boolean((stderr as any).isTTY ?? (stdout as any).isTTY);
24+
25+
const yellow = useAnsi ? '\x1b[33m' : '';
26+
const red = useAnsi ? '\x1b[31m' : '';
27+
const reset = useAnsi ? '\x1b[0m' : '';
28+
1329
useJobWatching({
1430
isWatching: true,
1531
jobId,
1632
onComplete,
1733
onFailure,
1834
onNewLogEntry(logEntry: JobLogEntry) {
19-
if (logEntry.level === LogLevel.ERROR) console.error(logEntry.message)
20-
else console.log(logEntry.message)
35+
const msg = logEntry.message + '\n';
36+
37+
if (logEntry.level === LogLevel.ERROR) {
38+
writeErr(`${red}${msg}${reset}`);
39+
} else if (logEntry.level === LogLevel.WARN) {
40+
writeErr(`${yellow}${msg}${reset}`);
41+
} else {
42+
writeOut(msg);
43+
}
2144
},
2245
projectId,
23-
})
46+
});
2447

25-
return null
26-
}
48+
return null;
49+
};

0 commit comments

Comments
 (0)