scroll/src/common/buffer.ts
Timothy J. Warren 1951425508
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good
Refactor runtimes
2024-07-12 10:58:23 -04:00

37 lines
626 B
JavaScript

import { strlen, truncate } from './fns.ts';
import { getRuntime } from './runtime/mod.ts';
class Buffer {
#b = '';
constructor() {
}
public append(s: string, maxLen?: number): void {
this.#b += (maxLen === undefined) ? s : truncate(s, maxLen);
}
public appendLine(s = ''): void {
this.#b += s + '\r\n';
}
public clear(): void {
this.#b = '';
}
/**
* Output the contents of the buffer into stdout
*/
public async flush() {
const { term } = await getRuntime();
await term.writeStdout(this.#b);
this.clear();
}
public strlen(): number {
return strlen(this.#b);
}
}
export default Buffer;