How can I use the up/down history keys in the SWI-Prolog console?
Asked Answered
O

4

5

When I press up/down, I should get - just like unix - the previous commands, but instead I get:

Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 6.0.0)
Copyright (c) 1990-2011 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

1 ?- ['nc'].
% nc compiled into nc 0.00 sec, 84 clauses
true.

2 ?- listing.
true.

(I press 'Up' arrow key to get the 'listing' command back.. then..)

3 ?- **^[[A**

I compiled from source without any additional 'configure', or 'make' parameters.

In previous version of swi-prolog, I found this worked haphazardly.. sometimes the console got itself in a mess, and I had to press '.' to force it to terminate the current line, then the history would start working again.

But this latest version.. nada.. I am using ubuntu linux, bash shell. It feels like an o.s. environment issue, or a bug in swi-prolog. The arrow keys/history works fine at the linux level.

Overtop answered 27/2, 2012 at 10:33 Comment(0)
O
4

I don't know about swi-prolog in particular, but I have used rlwrap to solve this problem for other interpreters that didn't feature built in editing features. It's very simple to use; you just have rlwrap run the command instead of running it directly.

Omentum answered 22/3, 2012 at 15:53 Comment(1)
Thanks Frank. Since Ubuntu did it's usual update, my problem has disappeared. But if it comes back, I'll try this.Overtop
G
2

You have to install package libreadline-dev on your host before compiling swiprolog to have arrows working.

Gio answered 23/2, 2013 at 14:23 Comment(1)
This works, and should be flagged as the solution so far as I can see.Jaban
O
1

This isn't actually an answer, more of a workaround, just in case anyone else has the same problem.

Although the 'up/down' arrow keys appear broken in 6.0.0 (and .1 - just tried it), the 'command-based' history recall seems to work ok, so it's possible to retrieve previous commands that way.

eg.

3 ?- !!.
listing.
true.

4 ?- L='fred', integer(L).
false.

5 ?- !!. 
L='fred', integer(L).
false.

6 ?- h.
    1   listing.
    2   listing.
    3   listing.
    4   L='fred', integer(L).
    5   L='fred', integer(L).
6 ?- !3.
listing.
true.
Overtop answered 1/3, 2012 at 18:13 Comment(0)
E
1

I had the same issue in OSX, and I fixed it this way:

brew install rlwrap

# every time when launching swipl:
rlwrap swipl
Encaustic answered 16/1, 2020 at 20:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.