From: John Stone (johns_at_ks.uiuc.edu)
Date: Wed May 20 2020 - 10:33:45 CDT

Giacomo,
  I realized I missed addressing your comment about there not
being a persistent history:
linenoise supports this, but I did not bother implementing the
calls to commit commands to the the linenoise persisent history
since Tcl has always had that built-in itself, albeit via "history".
If people think that is important, it isn't difficult to add
the calls to add to and commit the persistent history to disk.

Best,
  John

On Wed, May 20, 2020 at 10:26:21AM -0500, John Stone wrote:
> Giacomo,
> Thanks for the concrete feedback.
> The tab completion feature for linenoise requires that the caller
> (VMD) register a callback to be triggered any time the user presses
> the completion key (tab, in this case). I haven't implemented
> tab completion in the version of the code I sent you.
>
> To implement tab completion, I would likely use the Tcl command
> "info commands" to get a list of all global Tcl commands, which would
> include Tcl-intrinsic commands, VMD-internal commands, and VMD plugin
> commands added to the global namespace. I could use that to provide
> a large fraction of the completion candidates in an automatic way
> without hard-coding a bunch of Tcl-specific stuff there.
>
> As with tab completion, I also didn't yet implement the "hint" callback
> described in the linenoise README doc.
>
> The linenoise code appeals to me because of the BSD license
> and minimalist implementation (3% of the size of GNU readline).
>
> Another more full-featured option would be the BSD libedit
> library, which is apparently what Apple uses (along with a shim)
> to emulate GNU readline (since they can't ship the real readline
> lib due to GPL). I haven't looked at how clean/portable libedit is
> outside of BSD OSes, but that might be another option for those
> that expect a more featureful line editing implementation.
>
> The implementation I made for linenoise should serve as a proof of
> concept for implementing support for any of the other line editing libs.
>
> Best,
> John
>
>
> On Wed, May 20, 2020 at 11:06:50AM -0400, Giacomo Fiorin wrote:
> > Hi John, I just built VMD using the -DVMDLINENOISE flag and linenoise.c
> > added to the Makefile, and manually edited the "vmd" launcher script after
> > building to remove rlwrap.
> > I can confirm that with linenoise I can access the history of VMD commands
> > by using the up and down arrows, and move the cursor left or right using
> > the corresponding arrows. Two of the most basic readline keys (Ctrl-a
> > and Crtr-e, equivalent to Home and End) are able to navigate at the
> > beginning and the end of the current line. Also, Ctrl-h and Backspace
> > delete the last character and Ctrl-l correctly clears the screen.
> > Here are several things that differ from readline (details may be specific
> > to my build on CentOS 7 with gcc 4.8):
> >
> > * Word navigation (Alt-f and Alt-b, or Ctrl-Left and Ctrl-Right) is not
> > supported.
> > * Ctrl-k (kill aka cut) is supported, but not Ctrl-y (yank, aka paste).
> > * Tab inserts a tab, and does not autocomplete. There may be something
> > wrong in my build, since this is actually an advertised feature in the
> > linenoise README.
> > * There is no persistent history (people's opinions on the importance of
> > this feature may differ).
> >
> > I used vmd -dispdev text, both with TERM=xterm-256color (default in
> > gnome-terminal) and with TERM=xterm set by hand.
> > Assuming that tab completion can be fixed, I'm frustrated by the lack of
> > an explicit list of supported features: IMO, "the usual key bindings" is
> > not sufficient. Also IMO, word navigation and copy/paste are essential
> > features of command-line editing.
> > Overall, I would still prefer using rlwrap over linenoise given the
> > choice.
> > I would definitely welcome the ability to turn rlwrap on/off based on an
> > environment variable, the default value of which should be based on most
> > people's preference. One quirk that I noticed was that rlwrap was
> > interfering with the input/output channels handled by GNU parallel, which
> > I use sometimes to process a bunch of trajectory files using the same
> > script. Using a custom vmd script where I stripped the rlwrap part fixed
> > that problem for me, but I would very much welcome an environment variable
> > for this.
> > Thanks for pointing out this feature to us, please let me know if I can
> > provide anything else.
> > Giacomo
> > On Wed, May 20, 2020 at 3:55 AM John Stone <[1]johns_at_ks.uiuc.edu> wrote:
> >
> > Axel, et al.,
> > Since people have recently been begging me to include
> > 'rlwrap' with VMD by default I revisited the current crop
> > of GNU readline alternatives unencumbered by problematic
> > licenses.
> >
> > To my delight, I managed to find an input editing library
> > that is very minimalistic-but-usable, with a BSD license,
> > called "linenoise":
> > [2]https://github.com/antirez/linenoise
> >
> > I've made initial modifications to VMD to support it,
> > and thought I'd see what people think about this as an
> > alternative to our current strategy of 'rlwrap' autodetection.
> > It's in the current publically accessible VMD CVS tree, but I've
> > also attached the current TclTextInterp.[Ch] files.
> >
> > If people think this is as good as rlwrap, and it holds up in testing,
> > I would like to consider changing the behavior of the VMD
> > startup scripts to use rlwrap only when the user requests it
> > specifically (e.g. via a special env variable), which would
> > also disable the built-in command editing at the same time.
> >
> > I've made an effort to maintain proper special handling of
> > console redirection, MPI builds of VMD, and other cases by
> > integrating the new console support with our existing code,
> > but I need to run tests on several parallel MPI platforms and
> > such to validate that it works as expected in these special cases.
> >
> > The new code is enabled by compiling with -DVMDLINENOISE
> > and hacking in linenoise.c to the generated VMD
> > Makefile manually at present.
> >
> > I haven't yet done a Windows build with this library,
> > so that remains a future challenge when I get myh Windows x64
> > build system completely setup.
> >
> > Best,
> > John
> >
> > --
> > NIH Center for Macromolecular Modeling and Bioinformatics
> > Beckman Institute for Advanced Science and Technology
> > University of Illinois, 405 N. Mathews Ave, Urbana, IL 61801
> > [3]http://www.ks.uiuc.edu/~johns/ Phone: 217-244-3349
> > [4]http://www.ks.uiuc.edu/Research/vmd/
> >
> > --
> > Giacomo Fiorin
> > Associate Professor of Research, Temple University, Philadelphia, PA
> > Research collaborator, National Institutes of Health, Bethesda, MD
> > [5]http://goo.gl/Q3TBQU
> > [6]https://github.com/giacomofiorin
> >
> > References
> >
> > Visible links
> > 1. mailto:johns_at_ks.uiuc.edu
> > 2. https://github.com/antirez/linenoise
> > 3. http://www.ks.uiuc.edu/~johns/
> > 4. http://www.ks.uiuc.edu/Research/vmd/
> > 5. http://goo.gl/Q3TBQU
> > 6. https://github.com/giacomofiorin
>
> --
> NIH Center for Macromolecular Modeling and Bioinformatics
> Beckman Institute for Advanced Science and Technology
> University of Illinois, 405 N. Mathews Ave, Urbana, IL 61801
> http://www.ks.uiuc.edu/~johns/ Phone: 217-244-3349
> http://www.ks.uiuc.edu/Research/vmd/

-- 
NIH Center for Macromolecular Modeling and Bioinformatics
Beckman Institute for Advanced Science and Technology
University of Illinois, 405 N. Mathews Ave, Urbana, IL 61801
http://www.ks.uiuc.edu/~johns/           Phone: 217-244-3349
http://www.ks.uiuc.edu/Research/vmd/