feat: Display welcome message.
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
/*** defines ***/
|
/*** defines ***/
|
||||||
|
|
||||||
#define CTRL_KEY(k) ((k) & 0x1f)
|
#define CTRL_KEY(k) ((k) & 0x1f)
|
||||||
|
#define KILO_VERSION "0.0.1"
|
||||||
|
|
||||||
/*** data ***/
|
/*** data ***/
|
||||||
|
|
||||||
@@ -146,8 +147,30 @@ void abFree(struct abuf *ab) {
|
|||||||
|
|
||||||
void editorDrawRows(struct abuf *ab) {
|
void editorDrawRows(struct abuf *ab) {
|
||||||
for (int y = 0; y < E.screenrows; y++) {
|
for (int y = 0; y < E.screenrows; y++) {
|
||||||
abAppend(ab, "~", 1);
|
if (y == E.screenrows / 3) {
|
||||||
|
char welcome[80];
|
||||||
|
int welcomelen = snprintf(
|
||||||
|
welcome,
|
||||||
|
sizeof(welcome),
|
||||||
|
"Kil editor -- version %s",
|
||||||
|
KILO_VERSION
|
||||||
|
);
|
||||||
|
if (welcomelen > E.screencols)
|
||||||
|
welcomelen = E.screencols;
|
||||||
|
int padding = (E.screencols - welcomelen) / 2;
|
||||||
|
if (padding) {
|
||||||
|
abAppend(ab, "~", 1);
|
||||||
|
padding--;
|
||||||
|
}
|
||||||
|
while (padding--)
|
||||||
|
abAppend(ab, " ", 1);
|
||||||
|
abAppend(ab, welcome, welcomelen);
|
||||||
|
} else {
|
||||||
|
abAppend(ab, "~", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erase the line content to the right of the cursor.
|
||||||
|
abAppend(ab, "\x1b[K", 3);
|
||||||
// No new line on the last line, the terminal scrolls past the
|
// No new line on the last line, the terminal scrolls past the
|
||||||
// first line otherwise.
|
// first line otherwise.
|
||||||
if (y < E.screenrows - 1) {
|
if (y < E.screenrows - 1) {
|
||||||
@@ -158,8 +181,8 @@ void editorDrawRows(struct abuf *ab) {
|
|||||||
|
|
||||||
void editorRefreshScreen() {
|
void editorRefreshScreen() {
|
||||||
struct abuf ab = ABUF_INIT;
|
struct abuf ab = ABUF_INIT;
|
||||||
// Clear the whole screen.
|
// Hide cursor.
|
||||||
abAppend(&ab, "\x1b[2J", 4);
|
abAppend(&ab, "\x1b[?25l", 6);
|
||||||
// Move cursor to top left.
|
// Move cursor to top left.
|
||||||
abAppend(&ab, "\x1b[H", 3);
|
abAppend(&ab, "\x1b[H", 3);
|
||||||
|
|
||||||
@@ -167,6 +190,8 @@ void editorRefreshScreen() {
|
|||||||
|
|
||||||
// Return cursor to top left after drawing.
|
// Return cursor to top left after drawing.
|
||||||
abAppend(&ab, "\x1b[H", 3);
|
abAppend(&ab, "\x1b[H", 3);
|
||||||
|
// Show cursor again.
|
||||||
|
abAppend(&ab, "\x1b[?25h", 6);
|
||||||
|
|
||||||
write(STDOUT_FILENO, ab.b, ab.len);
|
write(STDOUT_FILENO, ab.b, ab.len);
|
||||||
abFree(&ab);
|
abFree(&ab);
|
||||||
|
|||||||
Reference in New Issue
Block a user