From c5e7d6e209ba6360ef570f8cb8c75f5babc0d9e1 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Thu, 9 Nov 2023 13:08:00 -0500 Subject: [PATCH] Get the padding on the welcome message just right --- src/common/editor/editor.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/common/editor/editor.ts b/src/common/editor/editor.ts index 0eabf8d..9299fd6 100644 --- a/src/common/editor/editor.ts +++ b/src/common/editor/editor.ts @@ -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('~'); }