symfony-style-console
Version:
Use the style and utilities of the Symfony Console in Node.js
38 lines (37 loc) • 781 B
JavaScript
import { EOL } from '../env';
import Output from './Output';
/**
* An [[OutputInterface]] that buffers its written messages.
*
* @author Jean-François Simon <contact@jfsimon.fr>
*
* Original PHP class
*
* @author Florian Reuschel <florian@loilo.de>
*
* Port to TypeScript
*/
export default class BufferedOutput extends Output {
constructor() {
super(...arguments);
this.buffer = '';
}
/**
* Empties buffer and returns its content.
*
* @return string
*/
fetch() {
const content = this.buffer;
this.buffer = '';
return content;
}
/**
* {@inheritdoc}
*/
doWrite(message, newline) {
this.buffer += message;
if (newline)
this.buffer += EOL;
}
}