(opts: TaskLogOptions)
| 45 | * Renders a log which clears on success and remains on failure |
| 46 | */ |
| 47 | export const taskLog = (opts: TaskLogOptions) => { |
| 48 | const output: Writable = opts.output ?? process.stdout; |
| 49 | const columns = getColumns(output); |
| 50 | const secondarySymbol = styleText('gray', S_BAR); |
| 51 | const spacing = opts.spacing ?? 1; |
| 52 | const barSize = 3; |
| 53 | const retainLog = opts.retainLog === true; |
| 54 | const isTTY = !isCIFn() && isTTYFn(output); |
| 55 | |
| 56 | output.write(`${secondarySymbol}\n`); |
| 57 | output.write(`${styleText('green', S_STEP_SUBMIT)} ${opts.title}\n`); |
| 58 | for (let i = 0; i < spacing; i++) { |
| 59 | output.write(`${secondarySymbol}\n`); |
| 60 | } |
| 61 | |
| 62 | const buffers: BufferEntry[] = [ |
| 63 | { |
| 64 | value: '', |
| 65 | full: '', |
| 66 | }, |
| 67 | ]; |
| 68 | let lastMessageWasRaw = false; |
| 69 | |
| 70 | const clear = (clearTitle: boolean): void => { |
| 71 | if (buffers.length === 0) { |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | let lines = 0; |
| 76 | |
| 77 | if (clearTitle) { |
| 78 | lines += spacing + 2; |
| 79 | } |
| 80 | |
| 81 | for (const buffer of buffers) { |
| 82 | const { value, result } = buffer; |
| 83 | let text = result?.message ?? value; |
| 84 | |
| 85 | if (text.length === 0) { |
| 86 | continue; |
| 87 | } |
| 88 | |
| 89 | if (result === undefined && buffer.header !== undefined && buffer.header !== '') { |
| 90 | text += `\n${buffer.header}`; |
| 91 | } |
| 92 | |
| 93 | const bufferHeight = text.split('\n').reduce((count, line) => { |
| 94 | if (line === '') { |
| 95 | return count + 1; |
| 96 | } |
| 97 | return count + Math.ceil((line.length + barSize) / columns); |
| 98 | }, 0); |
| 99 | |
| 100 | lines += bufferHeight; |
| 101 | } |
| 102 | |
| 103 | if (lines > 0) { |
| 104 | lines += 1; |
nothing calls this directly
no test coverage detected