From db65ac01a21d097183ae811e0847155f99bae25d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Thu, 22 Oct 2015 19:17:54 +0200 Subject: vis: improve :help text, add separate status mode names --- config.def.h | 19 +++++++++++++++---- editor.h | 2 ++ ui-curses.c | 2 +- vis.c | 25 ++++++++++++++++++++----- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/config.def.h b/config.def.h index b4630ad..ed395bc 100644 --- a/config.def.h +++ b/config.def.h @@ -1452,12 +1452,16 @@ static Mode vis_modes[] = { }, [VIS_MODE_NORMAL] = { .name = "NORMAL", + .status = "", + .help = "", .isuser = true, .parent = &vis_modes[VIS_MODE_OPERATOR], .default_bindings = vis_mode_normal, }, [VIS_MODE_VISUAL] = { - .name = "--VISUAL--", + .name = "VISUAL", + .status = "--VISUAL--", + .help = "", .isuser = true, .parent = &vis_modes[VIS_MODE_OPERATOR], .default_bindings = vis_mode_visual, @@ -1466,7 +1470,9 @@ static Mode vis_modes[] = { .visual = true, }, [VIS_MODE_VISUAL_LINE] = { - .name = "--VISUAL LINE--", + .name = "VISUAL LINE", + .status = "--VISUAL LINE--", + .help = "", .isuser = true, .parent = &vis_modes[VIS_MODE_VISUAL], .default_bindings = vis_mode_visual_line, @@ -1481,6 +1487,7 @@ static Mode vis_modes[] = { }, [VIS_MODE_PROMPT] = { .name = "PROMPT", + .help = "", .isuser = true, .parent = &vis_modes[VIS_MODE_READLINE], .default_bindings = vis_mode_prompt, @@ -1489,7 +1496,9 @@ static Mode vis_modes[] = { .leave = vis_mode_prompt_leave, }, [VIS_MODE_INSERT] = { - .name = "--INSERT--", + .name = "INSERT", + .status = "--INSERT--", + .help = "", .isuser = true, .parent = &vis_modes[VIS_MODE_READLINE], .default_bindings = vis_mode_insert, @@ -1499,7 +1508,9 @@ static Mode vis_modes[] = { .idle_timeout = 3, }, [VIS_MODE_REPLACE] = { - .name = "--REPLACE--", + .name = "REPLACE", + .status = "--REPLACE--", + .help = "", .isuser = true, .parent = &vis_modes[VIS_MODE_INSERT], .default_bindings = vis_mode_replace, diff --git a/editor.h b/editor.h index e7b5f0a..3454bd4 100644 --- a/editor.h +++ b/editor.h @@ -49,6 +49,8 @@ struct Mode { Map *bindings; KeyBinding *default_bindings; const char *name; /* descriptive, user facing name of the mode */ + const char *status; /* name displayed in the window status bar */ + const char *help; /* short description used by :help */ bool isuser; /* whether this is a user or internal mode */ void (*enter)(Mode *old); /* called right before the mode becomes active */ void (*leave)(Mode *new); /* called right before the mode becomes inactive */ diff --git a/ui-curses.c b/ui-curses.c index b42ee48..8c35756 100644 --- a/ui-curses.c +++ b/ui-curses.c @@ -613,7 +613,7 @@ static void ui_window_draw_status(UiWin *w) { wattrset(win->winstatus, focused ? A_REVERSE|A_BOLD : A_REVERSE); mvwhline(win->winstatus, 0, 0, ' ', win->width); mvwprintw(win->winstatus, 0, 0, "%s %s %s %s", - vis->mode->name && vis->mode->name[0] == '-' ? vis->mode->name : "", + focused && vis->mode->status ? vis->mode->status : "", filename ? filename : "[No Name]", text_modified(win->file->text) ? "[+]" : "", vis->recording ? "recording": ""); diff --git a/vis.c b/vis.c index 26b9fb4..9b9ba42 100644 --- a/vis.c +++ b/vis.c @@ -1598,10 +1598,9 @@ static void switchmode_to(Mode *new_mode) { if (vis->mode->isuser) vis->mode_prev = vis->mode; vis->mode = new_mode; - if (new_mode == config->mode || (new_mode->name && new_mode->name[0] == '-')) - vis->win->ui->draw_status(vis->win->ui); if (new_mode->enter) new_mode->enter(vis->mode_prev); + vis->win->ui->draw_status(vis->win->ui); } /** ':'-command implementations */ @@ -2336,7 +2335,7 @@ bool print_keybinding(const char *key, void *value, void *data) { const char *desc = binding->alias; if (!desc && binding->action) desc = binding->action->help; - return text_printf(txt, text_size(txt), " %-15s\t%s\n", key, desc ? desc : ""); + return text_appendf(txt, " %-15s\t%s\n", key, desc ? desc : ""); } static void print_mode(Mode *mode, Text *txt, bool recursive) { @@ -2350,15 +2349,31 @@ static bool cmd_help(Filerange *range, enum CmdOpt opt, const char *argv[]) { return false; Text *txt = vis->win->file->text; + + text_appendf(txt, "vis %s, compiled " __DATE__ " " __TIME__ "\n\n", VERSION); + + text_appendf(txt, " Modes\n\n"); + for (int i = 0; i < LENGTH(vis_modes); i++) { + Mode *mode = &vis_modes[i]; + if (mode->help) + text_appendf(txt, " %-15s\t%s\n", mode->name, mode->help); + } + for (int i = 0; i < LENGTH(vis_modes); i++) { Mode *mode = &vis_modes[i]; - if (mode->isuser || i == VIS_MODE_TEXTOBJ) { - text_printf(txt, text_size(txt), "\n%s\n\n", mode->name); + if (mode->isuser && !map_empty(mode->bindings)) { + text_appendf(txt, "\n %s\n\n", mode->name); print_mode(mode, txt, i == VIS_MODE_NORMAL || i == VIS_MODE_INSERT); } } + text_appendf(txt, "\n Text objects\n\n"); + print_mode(&vis_modes[VIS_MODE_TEXTOBJ], txt, false); + + text_appendf(txt, "\n Motions\n\n"); + print_mode(&vis_modes[VIS_MODE_MOVE], txt, false); + text_save(txt, NULL); return true; } -- cgit v1.2.3