tDraw status with left and right components and handle truncation - ve - a mini… | |
git clone git://src.adamsgaard.dk/ve | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit b8e623a52f0e936fd1a85796f6ab7af8d030fac7 | |
parent 87aab360fcdd4649b2d1f3349f589f51bc69976b | |
Author: Anders Damsgaard <[email protected]> | |
Date: Tue, 6 Aug 2019 10:27:40 +0200 | |
Draw status with left and right components and handle truncation | |
Diffstat: | |
M output.c | 38 +++++++++++++++++++++++------… | |
1 file changed, 29 insertions(+), 9 deletions(-) | |
--- | |
diff --git a/output.c b/output.c | |
t@@ -25,16 +25,36 @@ ab_free(struct abuf *ab) { | |
free(ab->b); | |
} | |
+/* draw status line consisting of left and right components. | |
+ * if the screen is narrower than both parts, just show the left status, | |
+ * truncated, if necessary. */ | |
void | |
-draw_status_string(struct abuf *ab) | |
+draw_status(struct abuf *ab) | |
{ | |
- char status[80]; | |
- int statuslen; | |
- statuslen = snprintf(status, sizeof(status), | |
- "%s editor -- version %s", PROGNAME, VERSION); | |
- if (statuslen > E.screencols) | |
- statuslen = E.screencols; | |
- ab_append(ab, status, statuslen); | |
+ char left_status[80], right_status[80]; | |
+ int left_status_len, right_status_len, padding; | |
+ left_status_len = snprintf(left_status, sizeof(left_status), | |
+ "%s editor -- version %s", | |
+ PROGNAME, VERSION); | |
+ right_status_len = snprintf(right_status, sizeof(right_status), | |
+ "%s editor -- version %s", | |
+ PROGNAME, VERSION); | |
+ | |
+ if (left_status_len > E.screencols) | |
+ left_status_len = E.screencols; | |
+ | |
+ padding = E.screencols - left_status_len - right_status_len; | |
+ if (padding < 0) { | |
+ if (left_status_len < E.screencols) | |
+ ab_append(ab, left_status, left_status_len); | |
+ else | |
+ ab_append(ab, left_status, E.screencols); | |
+ } else { | |
+ ab_append(ab, left_status, left_status_len); | |
+ while (padding--) | |
+ ab_append(ab, " ", 1); | |
+ ab_append(ab, right_status, right_status_len); | |
+ } | |
} | |
/* draw editor screen. | |
t@@ -46,7 +66,7 @@ editor_draw_rows(struct abuf *ab) | |
for (y = -1; y < E.screenrows; ++y) { | |
if (y == E.screenrows-1) | |
- draw_status_string(ab); | |
+ draw_status(ab); | |
else | |
ab_append(ab, "~", 1); | |