/// import { Writable } from 'stream'; /** * InsertionLog is a class that helps with printing to the console. The thing it * adds over console.log is that it is capable of inserting lines between and * replacing already printed lines. * * InsertionLog will only work if it gets exclusive access to its output stream. * If someone else writes to it, it will cause InsertionLog to do the wrong * thing. It is ok for someone else to take over after InsertionLog, but then * it can't be used anymore. */ export default class InsertionLog { #private; private readonly _stream; constructor(_stream: Writable); private cursorUp; private deleteLineAndGoToBeginning; private getLastMessages; private rewindMessages; private printMessages; private indexOfMessage; private logAt; /** * Append a message to the end of the log. * * @param message String. The message to write (should not contain a newline * char). * @param messageId String. Optional (defaults to null). Id of the message to * write. If you want to be able to overwrite it or insert messages before * or after this message you need to assign an id to it. */ log(message: string, messageId?: string): void; /** * Insert a new message after a given log message. * * @param afterMessageId The id of the message to write after. If there are * duplicates, the last message with the given id will be chosen. * @param message String. The message to insert (should not contain a newline * char). * @param messageId String. Optional (defaults to null). Id of the message to * write. If you want to be able to overwrite it or insert messages before * or after this message you need to assign an id to it. */ logAfter(afterMessageId: string, message: string, messageId?: string): void; /** * Insert a new message before a given log message. * * @param beforeMessageId The id of the message to write before. If there are * duplicates, the last message with the given id will be chosen. * @param message String. The message to insert (should not contain a newline * char). * @param messageId String. Optional (defaults to null). Id of the message to * write. If you want to be able to overwrite it or insert messages before * or after this message you need to assign an id to it. */ logBefore(beforeMessageId: string, message: string, messageId?: string): void; /** * Replace an already written log message. * * @warning It is not allowed to replace a message with one that has a different * number of newlines. * * @param replacedMessageId The id of the message to replace. If there are * duplicates, the last message with the given id will be chosen. * @param message String. The message to insert (should not contain a newline * char) */ replace(replacedMessageId: string, message: string): void; }