Repository head::
Include tests directory in generated tarball.
+ Support command-line editing with arrow keys and Emacs keystrokes.
1.0: 2016-06-05::
Forward port of Crowther & Woods's 430-point Adventure 2.5.
This version is released as open source with the permission and
encouragement of the original authors.
+Unlike the original, this version supports use of your arrow keys to edit
+your command line in place. Basic Emacs keystrokes are supported, and
+your up/down arrows access a command history.
+
+To exit the game, type Ctrl-D (EOF).
+
+There have been no gameplay changes.
+
== OPTIONS ==
-l:: Log commands to specified file.
--o:: Old-style. Restores original interface, no prompt.
+-o:: Old-style. Restores original interface, no prompt or command history.
== BUGS ==
extern bool TSTBIT(long,int);
extern long RNDVOC(long,long);
extern void BUG(long) __attribute__((noreturn));
-extern void MAPLIN(FILE *);
+extern bool MAPLIN(FILE *);
extern void TYPE(void);
extern void fSAVEIO(long,long,long*);
#include <time.h>
#include "advent.h"
#include "database.h"
+#include "linenoise/linenoise.h"
struct game_t game;
}
}
+ linenoiseHistorySetMaxLen(350);
+
/* Logical variables:
*
* game.closed says whether we're all the way closed
bool MAPLIN(FILE *fp)
{
long i, val;
+ bool eof;
/* Read a line of input, from the specified input source,
* translate the chars to integers in the range 0-126 and store
* and is not changed thereafter unless the routines on this page choose
* to do so. */
- if (!oldstyle && fp == stdin)
- fputs("> ", stdout);
do {
- IGNORE(fgets(rawbuf,sizeof(rawbuf)-1,fp));
+ if (oldstyle) {
+ IGNORE(fgets(rawbuf,sizeof(rawbuf)-1,fp));
+ eof = (feof(fp));
+ } else {
+ char *cp = linenoise("> ");
+ eof = (cp == NULL);
+ if (!eof) {
+ strncpy(rawbuf, cp, sizeof(rawbuf)-1);
+ linenoiseHistoryAdd(rawbuf);
+ strncat(rawbuf, "\n", sizeof(rawbuf)-1);
+ linenoiseFree(cp);
+ }
+ }
} while
- (!feof(fp) && rawbuf[0] == '#');
- if (feof(fp)) {
+ (!eof && rawbuf[0] == '#');
+ if (eof) {
if (logfp && fp == stdin)
fclose(logfp);
return false;