[racket-dev] Line editing in the default REPL

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Dec 23 13:57:24 EST 2014

On Wed, Dec 17, 2014 at 12:35 PM, Tony Garnock-Jones <tonyg at ccs.neu.edu> wrote:
> If anyone reading this has an interesting or unusual terminal they
> like to use, please run
>     $ raco pkg install ansi
>     $ racket -l ansi/test-raw

I didn't run it, but guessing common keys isn't too difficult, of
course.  I'm attaching a piece of code that I have that does that.  It
looks to me like my code is much more ambitious -- I wanted to be able
to have almost all possible keys with modifiers, including function keys
and plain characters, and that makes it messier.  (I posted variations
of this thing a few times in the past.)

>> likely evolve into some form of a terminfo-like facility.  So it's
>> better to just write something that can deal with terminfo directly.
> Sadly, terminfo is a little anaemic with respect to the sequences it
> specifies. To get input capabilities even half as rich as, say, emacs,
> you have to go beyond what is given in the terminfo database in a couple
> of ways. Specifically, to parse shift/control/meta combinations you need
> to get into terminal-specific encodings that are not covered by terminfo.

Sure, but those are usually not specific too.  (You're probably talking
about the DEC thing, right?  There's also the rxvt/aterm thing which is
different and more weird.)

In any case, terminfo for reading keys is obviously not too difficult to
manage.  If that was all that you need, then it's very easy to write
code that translates the terminfo database into some readable format
that you can read in Racket.  (My code is basically doing that parsing,
so it's 90% of what you need for that.)  But the thing is that terminfo
is much more needed for the related things -- querying the terminal,
using escape sequences to do the interactions (and doing that without
restricting yourself to some small subset), and also sending sequences
that setup the terminal (like rmkx/smkx which is what tripped me
earlier, and IIRC, it's needed with at least st, possibly others too).

>> it's the blindness of going in that direction and thinking that you
>> *won't* fall into this trap.
> It remains to be seen whether there are any problems resulting from
> this approach at all.

It looks like *you're* very aware of the issues, so why not take it?

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: keys.rkt
Type: application/octet-stream
Size: 4428 bytes
Desc: not available
URL: <http://lists.racket-lang.org/dev/archive/attachments/20141223/b4621e99/attachment.obj>

Posted on the dev mailing list.