Files
Kmake/kmake/src/Block.ts
2026-05-26 23:36:42 -07:00

42 lines
752 B
TypeScript

import * as fs from 'fs';
export class Block {
out: number;
indentation: number;
constructor(out: number, indentation: number) {
this.out = out;
this.indentation = indentation;
}
indent() {
++this.indentation;
}
unindent() {
--this.indentation;
}
tag(name: string, value: string) {
this.p('<' + name + '>' + value + '</' + name + '>');
}
tagStart(name: string) {
this.p('<' + name + '>');
this.indent();
}
tagEnd(name: string) {
this.unindent();
this.p('</' + name + '>');
}
p(line: string) {
if (line === undefined) line = '';
let tabs = '';
for (let i = 0; i < this.indentation; ++i) tabs += '\t';
let data = Buffer.from(tabs + line + '\n');
fs.writeSync(this.out, data, 0, data.length, null);
}
}