summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c43
1 files changed, 37 insertions, 6 deletions
diff --git a/main.c b/main.c
index a94c446..c803a95 100644
--- a/main.c
+++ b/main.c
@@ -73,6 +73,7 @@
X(CPAIR_DEFAULT , COLOR_FG , COLOR_BG, A_NORMAL , "default")\
X(CPAIR_TEXT , COLOR_FG , COLOR_BG, A_NORMAL , "text")\
X(CPAIR_MENTION , COLOR_FG , COLOR_BG, A_REVERSE, "mention")\
+ X(CPAIR_HELP , COLOR_FG , COLOR_BG, A_REVERSE, "help")\
X(CPAIR_USER , COLOR_YELLOW , COLOR_BG, A_NORMAL , "user")\
X(CPAIR_PRONOUNS , COLOR_CYAN , COLOR_BG, A_NORMAL , "pronouns")\
X(CPAIR_DATE , COLOR_BLUE , COLOR_BG, A_NORMAL , "date")\
@@ -680,12 +681,48 @@ void gfx_draw_post(GfxPost *post, int y, int x, int width, Arena *scratch) {
}
}
+void gfx_draw_msg(void) {
+ switch (msg_status) {
+ case MSG_OK: use_color(CPAIR_MSG_OK); break;
+ case MSG_WARN: use_color(CPAIR_MSG_WARN); break;
+ case MSG_ERR: use_color(CPAIR_MSG_ERR); break;
+ }
+ mvaddstr(getmaxy(stdscr) - 1, getmaxx(stdscr) - strlen(msg), msg);
+}
+
+void gfx_draw_help(Arena *scratch) {
+ use_color(CPAIR_HELP);
+ //const char *help_src = "[c]reate [r]efresh [q]uit [?]help | scrolling: arrows, j/k, (ctrl-)d/u, space, page up/down";
+ /*const char *help_src = "[c]reate [r]efresh [q]uit [?]help"
+ " [up/k]prev [down/j]next"
+ " [space]pagedown [b]pageup"
+ " [u]halfup [d]halfdown"
+ ;*/
+ const char *help_src = "[c]reate [e]dit [r]efresh [q]uit"
+ " | scrolling: arrows, j/k, b/space, page up/down, (ctrl-)d/u";
+ Str wrapped = { 0 };
+ str_cat_wrap(&wrapped, str_from_cstr(help_src), getmaxx(stdscr), scratch);
+ int line_count = 0;
+ for (Str src = wrapped, line = { 0 }; next_line(&src, &line);) line_count++;
+ int y = getmaxy(stdscr) - line_count;
+ for (Str src = wrapped, line = { 0 }; next_line(&src, &line);) {
+ mvaddnstr(y++, 0, line.s, line.n);
+ for (int i = getmaxx(stdscr); i > line.n; i--) {
+ addch(' ');
+ }
+ }
+}
+
void gfx_draw(Gfx *gfx, int cur, Arena *scratch) {
erase();
for (int i = cur, y = opt.margin.top; i < gfx->len && y < getmaxy(stdscr) - opt.margin.bottom; i++) {
gfx_draw_post(&gfx->posts[i], y, post_left_margin(gfx->posts[i].src), gfx_post_width(gfx->posts[i].src), scratch);
y += gfx_post_height(&gfx->posts[i]) + GFX_POST_SPACING;
}
+ if (opt.cbink.help) {
+ gfx_draw_help(scratch);
+ }
+ gfx_draw_msg();
}
/* maybe should write an ui layer to not have to deal with all the manual layout stuff */
@@ -1178,12 +1215,6 @@ int main(void) {
arena_reset(&temp_arena);
gfx_draw(&gfx, cur, &temp_arena);
- switch (msg_status) {
- case MSG_OK: use_color(CPAIR_MSG_OK); break;
- case MSG_WARN: use_color(CPAIR_MSG_WARN); break;
- case MSG_ERR: use_color(CPAIR_MSG_ERR); break;
- }
- mvaddstr(getmaxy(stdscr) - 1, getmaxx(stdscr) - strlen(msg), msg);
msg[0] = '\0';
int ch = getch();