Get the padding on the welcome message just right

This commit is contained in:
Timothy Warren 2023-11-09 13:08:00 -05:00
parent 88ba42df0d
commit c5e7d6e209

View File

@ -57,10 +57,23 @@ export class Editor {
}
private drawRows(): void {
this.drawPlaceholderRows();
}
private drawPlaceholderRows(): void {
for (let y = 0; y < this.#screenRows; y++) {
if (y === this.#screenRows / 3) {
if (y === Math.trunc(this.#screenRows / 2)) {
const message = `Kilo editor -- version ${VERSION}`;
this.#buffer.append(truncate(message, this.#screenCols));
const messageLen = (message.length > this.#screenCols) ? this.#screenCols : message.length;
let padding = Math.trunc((this.#screenCols - messageLen) / 2);
if (padding > 0) {
this.#buffer.append('~');
padding -= 1;
this.#buffer.append(' '.repeat(padding));
}
this.#buffer.append(truncate(message, messageLen));
} else {
this.#buffer.append('~');
}