From aea877145e08d99641cac9310ca94becf3df3587 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Thu, 18 Jul 2013 12:31:37 +0200 Subject: Add write and quit commands This adds following vim-style commands to the command mode: * write * w * quit * q * wq Commands can be suffixed with a "!" to force execution. Signed-off-by: Lukas Fleischer --- src/calcurse.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/calcurse.c b/src/calcurse.c index c22838e..6d18e23 100644 --- a/src/calcurse.c +++ b/src/calcurse.c @@ -475,8 +475,7 @@ static inline void key_generic_quit(void) note_gc(); if (conf.confirm_quit) { - if (status_ask_bool(_("Do you really want to quit?")) == - 1) { + if (status_ask_bool(_("Do you really want to quit?")) == 1) { exit_calcurse(EXIT_SUCCESS); } else { wins_erase_status_bar(); @@ -491,12 +490,32 @@ static inline void key_generic_cmd(void) { char cmd[BUFSIZ] = ""; char *cmd_name; + int valid = 0, force = 0; status_mesg(_("Command:"), ""); if (getstring(win[STA].p, cmd, BUFSIZ, 0, 1) != GETSTRING_VALID) return; cmd_name = strtok(cmd, " "); + if (cmd_name[strlen(cmd_name) - 1] == '!') { + cmd_name[strlen(cmd_name) - 1] = '\0'; + force = 1; + } + + if (!strcmp(cmd_name, "write") || !strcmp(cmd_name, "w") || + !strcmp(cmd_name, "wq")) { + io_save_cal(IO_SAVE_DISPLAY_BAR); + valid = 1; + } + if (!strcmp(cmd_name, "quit") || !strcmp(cmd_name, "q") || + !strcmp(cmd_name, "wq")) { + if (force || !conf.confirm_quit || status_ask_bool( + _("Do you really want to quit?")) == 1) + exit_calcurse(EXIT_SUCCESS); + else + wins_erase_status_bar(); + valid = 1; + } if (!strcmp(cmd_name, "help")) { char *topic = strtok(NULL, " "); @@ -511,7 +530,11 @@ static inline void key_generic_cmd(void) warnbox(error_msg); } - } else { + + valid = 1; + } + + if (!valid) { char error_msg[BUFSIZ]; snprintf(error_msg, BUFSIZ, _("No such command: %s"), cmd); -- cgit v1.2.3-70-g09d2