scroll/src/common/document.ts

50 lines
752 B
JavaScript
Raw Normal View History

2023-11-13 15:33:56 -05:00
import { chars } from './utils.ts';
2023-11-13 14:46:04 -05:00
export class Row {
chars: string[] = [];
constructor(s: string = '') {
this.chars = chars(s);
}
public toString(): string {
return this.chars.join('');
}
}
export class Document {
#rows: Row[];
private constructor() {
this.#rows = [];
}
get numrows(): number {
return this.#rows.length;
}
public static empty(): Document {
return new Document();
}
2023-11-13 15:33:56 -05:00
public static open(_filename: string): Document {
2023-11-13 14:46:04 -05:00
const doc = new Document();
const line = 'Hello, World!';
const row = new Row(line);
doc.#rows.push(row);
return doc;
}
public getRow(i: number): Row | null {
if (this.#rows[i] !== undefined) {
return this.#rows[i];
}
return null;
}
}
export default Document;