Enable input editing with the linenoise library.
This commit is contained in:
parent
037f1df7dd
commit
63e971fc4c
5 changed files with 30 additions and 7 deletions
1
NEWS
1
NEWS
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
Repository head::
|
Repository head::
|
||||||
Include tests directory in generated tarball.
|
Include tests directory in generated tarball.
|
||||||
|
Support command-line editing with arrow keys and Emacs keystrokes.
|
||||||
|
|
||||||
1.0: 2016-06-05::
|
1.0: 2016-06-05::
|
||||||
Forward port of Crowther & Woods's 430-point Adventure 2.5.
|
Forward port of Crowther & Woods's 430-point Adventure 2.5.
|
||||||
|
|
10
advent.adoc
10
advent.adoc
|
@ -25,11 +25,19 @@ PDP-10 on which it originally ran limited filenames to 6 characters.
|
||||||
This version is released as open source with the permission and
|
This version is released as open source with the permission and
|
||||||
encouragement of the original authors.
|
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 ==
|
== OPTIONS ==
|
||||||
|
|
||||||
-l:: Log commands to specified file.
|
-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 ==
|
== BUGS ==
|
||||||
|
|
||||||
|
|
2
advent.h
2
advent.h
|
@ -118,7 +118,7 @@ extern long SETBIT(long);
|
||||||
extern bool TSTBIT(long,int);
|
extern bool TSTBIT(long,int);
|
||||||
extern long RNDVOC(long,long);
|
extern long RNDVOC(long,long);
|
||||||
extern void BUG(long) __attribute__((noreturn));
|
extern void BUG(long) __attribute__((noreturn));
|
||||||
extern void MAPLIN(FILE *);
|
extern bool MAPLIN(FILE *);
|
||||||
extern void TYPE(void);
|
extern void TYPE(void);
|
||||||
|
|
||||||
extern void fSAVEIO(long,long,long*);
|
extern void fSAVEIO(long,long,long*);
|
||||||
|
|
3
main.c
3
main.c
|
@ -11,6 +11,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "advent.h"
|
#include "advent.h"
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
#include "linenoise/linenoise.h"
|
||||||
|
|
||||||
struct game_t game;
|
struct game_t game;
|
||||||
|
|
||||||
|
@ -82,6 +83,8 @@ case 'l':
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
linenoiseHistorySetMaxLen(350);
|
||||||
|
|
||||||
/* Logical variables:
|
/* Logical variables:
|
||||||
*
|
*
|
||||||
* game.closed says whether we're all the way closed
|
* game.closed says whether we're all the way closed
|
||||||
|
|
21
misc.c
21
misc.c
|
@ -703,6 +703,7 @@ void BUG(long num)
|
||||||
bool MAPLIN(FILE *fp)
|
bool MAPLIN(FILE *fp)
|
||||||
{
|
{
|
||||||
long i, val;
|
long i, val;
|
||||||
|
bool eof;
|
||||||
|
|
||||||
/* Read a line of input, from the specified input source,
|
/* Read a line of input, from the specified input source,
|
||||||
* translate the chars to integers in the range 0-126 and store
|
* translate the chars to integers in the range 0-126 and store
|
||||||
|
@ -729,13 +730,23 @@ bool MAPLIN(FILE *fp)
|
||||||
* and is not changed thereafter unless the routines on this page choose
|
* and is not changed thereafter unless the routines on this page choose
|
||||||
* to do so. */
|
* to do so. */
|
||||||
|
|
||||||
if (!oldstyle && fp == stdin)
|
|
||||||
fputs("> ", stdout);
|
|
||||||
do {
|
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
|
} while
|
||||||
(!feof(fp) && rawbuf[0] == '#');
|
(!eof && rawbuf[0] == '#');
|
||||||
if (feof(fp)) {
|
if (eof) {
|
||||||
if (logfp && fp == stdin)
|
if (logfp && fp == stdin)
|
||||||
fclose(logfp);
|
fclose(logfp);
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue