Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Term::ReadLine and line-editing

by ibm1620 (Hermit)
on May 05, 2022 at 20:57 UTC ( [id://11143606]=perlquestion: print w/replies, xml ) Need Help??

ibm1620 has asked for the wisdom of the Perl Monks concerning the following question:

I use Term::ReadLine::Gnu for its line-editing and input history retrieval capability. If I forget to install it, I'm reminded the moment I run a script that uses readline, hit the left-arrow at the prompt, and garbage splats out (^[[D). That's my cue to cpanm Term::ReadLine::Gnu.

However, while talking a Mac user through installing a Perl program I wrote that uses readline, I discovered that installing the Gnu version from scratch is harder than I'd thought. First, I had him install the Xcode Command Line Tools as a prerequisite for perlbrew, and then perl v5.34 and cpanm. But cpanm Term::ReadLine::Gnu failed: The libreadline you are using is the libedit library.  Use the GNU Readline Library. The simplest solution to this I could find involved installing homebrew. Homebrew's easy enough for me to use, but I felt like I was expending an awful lot of effort to provide a Mac terminal user with basic command-line editing.

Long story short, I installed Term::ReadLine::Perl and it mostly works (haven't fully tested it yet) but, because my prompt uses sequences from Term::ANSIColor, it writes '0m ' after the prompt! And if I remove those sequences, my keystrokes appear in white.

Since I normally don't have this kind of trouble doing something easy in Perl, I figure I'm overlooking something very obvious. Readline-Gnu "just worked" for me; can't Readline-Perl do the same, at least for line editing and input retrieval?

Replies are listed 'Best First'.
Re: Term::ReadLine and line-editing
by kcott (Archbishop) on May 06, 2022 at 00:14 UTC
      Hi Ken, Thanks for the suggestion. Unfortunately, downloading and manually make'ing Term::ReadLine::Gnu produced the same error about the libreadline I'm using being the libedit library. I suspect that this problem may be specific to MacOS.
Re: Term::ReadLine and line-editing
by Discipulus (Canon) on May 06, 2022 at 08:06 UTC
    Hello ibm1620,

    from what I understand you should use Term::ReadLine as frontend, not directly Term::ReadLine::Gnu or ::Perl you can control with the env var PERL_RL which one is loaded. This is the standard way.

    That said you can find interesting easy-osx-termreadlinegnu and this SO post but basically they both say to:

    brew install readline brew link --force readline cpanm Term::ReadLine::Gnu brew unlink readline

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      Hi Discipulus,

      I know about PERL_RL, my problem is that ::Perl creates visual blemishes in my prompt, and that installing ::Gnu is so complicated on a Mac that doesn't have developer tools. Although I'd gone ahead and had my client install Xcode COmmand Line Tools as prerequesite to installing perlbrew, simply to create a local Perl environment in which to install a readline module, it turned out that cpanm Term::ReadLine::Gnu would require homebrew in order to install readline-gnu, at which point I decided (with a little exasperation) to try installing ::Perl instead.

      I'm still waiting to hear back about whether kcott's suggestion above (make'ing ::Gnu manually) worked for my client. Unfortunately my two Macs both have Xcode and homebrew so I can't test.

      I hope I haven't muddied the waters further! :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11143606]
Approved by LanX
Front-paged by LanX
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-29 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found