summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2013-07-18 12:31:37 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2013-07-18 12:31:37 +0200
commitaea877145e08d99641cac9310ca94becf3df3587 (patch)
tree9ad7c7714bdc2d450926cac37845ce6df49a0e36
parented9b22bd9b3e8ac2018cfb82cfceb5455c1a9d69 (diff)
downloadcalcurse-aea877145e08d99641cac9310ca94becf3df3587.zip
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 <calcurse@cryptocrack.de>
-rw-r--r--src/calcurse.c29
1 files changed, 26 insertions, 3 deletions
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);