summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2013-07-17 01:00:53 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2013-07-17 14:03:53 +0200
commit2c25d99ad036c9ad473167b4f2f8e7dea9cd946e (patch)
treef6fbe0e94d348633c29d3f9346016843e0675fb9
parentc4dae80dd23989d4146475de3d16d1636b190c9d (diff)
downloadcalcurse-2c25d99ad036c9ad473167b4f2f8e7dea9cd946e.zip
Add help command
This adds a "help" command to the list of available command mode commands. You can currently type "help", followed by a topic like "add". calcurse will then try to open a file named "add.txt" in the documentation directory and display it in an external pager. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r--src/Makefile.am1
-rw-r--r--src/calcurse.c31
2 files changed, 31 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 44d1ae8..3559a25 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,6 +2,7 @@ AUTOMAKE_OPTIONS = foreign
bin_PROGRAMS = calcurse
+AM_CPPFLAGS = -DDOCDIR=\"@docdir@\"
AM_CFLAGS = -std=c99 -pedantic -D_POSIX_C_SOURCE=200809L
calcurse_SOURCES = \
diff --git a/src/calcurse.c b/src/calcurse.c
index 460f4c4..d20e9d0 100644
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -491,12 +491,41 @@ static inline void key_generic_quit(void)
static inline void key_generic_cmd(void)
{
char cmd[BUFSIZ] = "";
+ char *cmd_name;
status_mesg(_("Command:"), "");
if (getstring(win[STA].p, cmd, BUFSIZ, 0, 1) != GETSTRING_VALID)
return;
- wins_update(FLAG_STA);
+ cmd_name = strtok(cmd, " ");
+
+ if (!strcmp(cmd_name, "help")) {
+ char *topic = strtok(NULL, " ");
+ char path[BUFSIZ];
+
+ snprintf(path, BUFSIZ, DOCDIR "/%s.txt", topic);
+ if (io_file_exist(path)) {
+ wins_launch_external(path, conf.pager);
+ } else {
+ char error_msg[BUFSIZ];
+
+ snprintf(error_msg, BUFSIZ,
+ _("Help topic does not exist: %s"),
+ topic);
+ error_msg[BUFSIZ - 1] = '\0';
+
+ warnbox(error_msg);
+ }
+ } else {
+ char error_msg[BUFSIZ];
+
+ snprintf(error_msg, BUFSIZ, _("No such command: %s"), cmd);
+ error_msg[BUFSIZ - 1] = '\0';
+
+ warnbox(error_msg);
+ }
+
+ wins_update(FLAG_ALL);
}
/*