Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-4053

Suggestion: allow optional use of readline

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Shell
    • Labels:
      None

      In switching from readline to linenoise in version 1.9, a lot of functionality was given up and some bugs were introduced. linenoise is workable, maintainable code and can be improved over time. But it doesn't do what readline did and probably never will.

      For users who are heavy users of readline-style functionality such as history search, kill rings and support for non-VT100-style terminals, it can be a disappointment to lose those features in an upgrade of MongoDB.

      A workaround for those users would be to link to readline on-the-fly when asked to by a command line switch, and environment variable or a JavaScript setting in .mongorc.js .

      export MONGOSHELL=--use-readline

      or

      cat ~/.mongorc.js
      MONGOSHELL="--use-readline"

      or

      ./mongo --use-readline

      We could load libreadline.so or let the user force a specific version.

      ./mongo --use-readline=/lib/libreadline.so.5.2

      Internally, we would let shell/dbshell.cpp deal with whether the user asked us to do this, and then hand the issue off to linenoise.

      char * errorString = linenoiseUseReadline(char * readlinePath); // readlinePath == 0 means "figure it out yourself"

      If errorString != 0 we could display it. Regardless of what linenoise returned, dbshell would call the same linenoise functions and linenoise would either call readline or handle everything itself. This puts the burden of supporting readline on linenoise and keeps it out the the client's areas of concern.

      At one level of stretch, we could do this automatically by default, and make the user ask us not to do it if they really didn't want it.

      ./mongo --use-readline=no

      At level two of stretch, we could do this for Windows, using either Cygwin or "Readline for Windows" (http://gnuwin32.sourceforge.net/packages/readline.htm). Readline for Windows exports 551 symbols and looks like a complete version with proper Win32 support.

      .\mongo --use-readline="C:\Program Files (x86)\GnuWin32\bin\readline5.dll"

      This isn't so much a feature as a workaround. Anyone attached to readline can stay in their comfort zone when upgrading MongoDB. Anyone having issues with SecureCRT or any other terminal program can try using readline and see if the problem goes away. Tech supporters get another option to suggest, users get more stuff to configure if they feel like it (but normal documented default behavior if they don't) and power users feel their power. A little coding to make this work, and everybody wins.

      The reason this is possible is because the interfaces and usage of them is mostly the same between readline and linenoise. linenoise was written to be a (much) smaller replacement for readline and the calls and callbacks are pretty much the same. readline is old, crufty code written in Unix-oriented C using pre-ANSI C function declarations and tons of global variables, but it does an amazing amount of stuff and it is battle-tested, stable and standard. bash calls it. linenoise is newer (2010) and fits comfortably into a single .cpp file. Our (changed) copy works on Windows and VT100-style terminals (i.e. most Unix-like systems) and is a fine solution for many people. Opening up the readline option for people who need it would just increase the number of addressable users and increase the support options for people with issues.

            Assignee:
            tad Tad Marshall
            Reporter:
            tad Tad Marshall
            Votes:
            4 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: