tImplement status bar spacing in a simpler way, add char array for filename - ve - a minimal text editor (work in progress)
(HTM) git clone git://src.adamsgaard.dk/ve
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 47a9339b4ca25ac94128be6af5f98881381353ca
(DIR) parent 514b81a4a6a9b5496e7ebfb9836557c64efa37de
(HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Tue, 6 Aug 2019 14:21:18 +0200
Implement status bar spacing in a simpler way, add char array for filename
Diffstat:
M byote.h | 2 +-
M input.c | 4 ++--
M io.c | 3 +++
M output.c | 15 ++++++---------
M terminal.c | 3 +++
5 files changed, 15 insertions(+), 12 deletions(-)
---
(DIR) diff --git a/byote.h b/byote.h
t@@ -22,8 +22,8 @@ struct editor_config {
int num_rows;
eRow *row;
int row_offset, column_offset;
+ char *filename;
struct termios orig_termios;
- int status_height;
int mode; /* 0: normal, 1: insert, 2: visual */
};
(DIR) diff --git a/input.c b/input.c
t@@ -75,12 +75,12 @@ editor_process_keypress()
break;
case CTRL_KEY('f'):
- i = E.screen_rows - E.status_height;
+ i = E.screen_rows;
while (i--)
editor_move_cursor('j');
break;
case CTRL_KEY('b'):
- i = E.screen_rows - E.status_height;
+ i = E.screen_rows;
while (i--)
editor_move_cursor('k');
break;
(DIR) diff --git a/io.c b/io.c
t@@ -64,6 +64,9 @@ editor_append_row(char *s, size_t len)
void
file_open(char *filename)
{
+ free(E.filename);
+ E.filename = strdup(filename);
+
FILE *fp;
char *line;
size_t linecap;
(DIR) diff --git a/output.c b/output.c
t@@ -29,9 +29,8 @@ ab_free(struct abuf *ab) {
* if the screen is narrower than both parts, just show the left status,
* truncated, if necessary. */
void
-draw_status(struct abuf *ab)
+editor_draw_status(struct abuf *ab)
{
- E.status_height = 1;
char left_status[512], right_status[512];
int left_status_len, right_status_len, padding;
t@@ -93,8 +92,8 @@ editor_scroll()
if (E.cursor_y < E.row_offset)
E.row_offset = E.cursor_y;
- else if (E.cursor_y >= E.row_offset + E.screen_rows - E.status_height)
- E.row_offset = E.cursor_y - E.screen_rows + E.status_height + 1;
+ else if (E.cursor_y >= E.row_offset + E.screen_rows)
+ E.row_offset = E.cursor_y - E.screen_rows + 1;
if (E.cursor_rx < E.column_offset)
E.column_offset = E.cursor_rx;
t@@ -110,9 +109,7 @@ editor_draw_rows(struct abuf *ab)
int y, len, file_row;
for (y = 0; y < E.screen_rows; ++y) {
file_row = y + E.row_offset;
- if (y == E.screen_rows-1) {
- draw_status(ab);
- } else if (file_row < E.num_rows) {
+ if (file_row < E.num_rows) {
len = E.row[file_row].rsize - E.column_offset;
if (len < 0)
len = 0;
t@@ -124,8 +121,7 @@ editor_draw_rows(struct abuf *ab)
}
ab_append(ab, "\x1b[K", 3); /* erase to end of line */
- if (y < E.screen_rows - 1)
- ab_append(ab, "\r\n", 2);
+ ab_append(ab, "\r\n", 2);
}
}
t@@ -145,6 +141,7 @@ editor_refresh_screen()
ab_append(&ab, "\x1b[H", 3); /* cursor to home */
editor_draw_rows(&ab);
+ editor_draw_status(&ab);
char buf[32];
snprintf(buf, sizeof(buf), "\x1b[%d;%dH",
(DIR) diff --git a/terminal.c b/terminal.c
t@@ -106,6 +106,7 @@ get_window_size(int *rows, int *cols)
}
}
+/* set editor state variables, make room for status */
void
init_editor() {
E.cursor_x = 0;
t@@ -116,6 +117,8 @@ init_editor() {
E.row = NULL;
E.row_offset = 0;
E.column_offset = 0;
+ E.filename = NULL;
if (get_window_size(&E.screen_rows, &E.screen_columns) == -1)
die("get_window_size");
+ E.screen_rows -= 1;
}