LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 09-09-2008, 05:20 PM   #1
otho
LQ Newbie
 
Registered: Oct 2003
Posts: 8

Rep: Reputation: 0
Editing terminal input prior to passing it to shell / application


I am using some software with a command line interface. Despite being a mature commercial product (Mathematica - forgive my mention of a non-GPL software), there is no way to edit an input line other than backspace (ie you cannot move cursor left and right, either by arrows or other keystrokes, ctrl-b ctrl-f also do nothing). Only adding to my frustration, there is no way to scroll through history either. I have become very accustomed to standard interfaces where I can use the up arrow to scroll through history and edit any command and resubmit revised lines etc, or at least paste something from some other source and edit it directly on the terminal itself.

I regularly use screen and thought that it might provide the functionality that I seek, but I can only copy and paste from it. There is no way to edit the buffer before pasting it into the application. Well I could pump it to a buffer file and edit there then pop it from the buffer file, but that is more work than I want, and I could just do that through a gui anyway.

What I am asking is if there is any wrapper application that will capture input and allow editing and history etc. When enter is pressed it could then pass the line on to the application it wraps.

Yes I am aware of and use other friendly computer algebra systems such as maxima, yacas, sage etc, that are better designed with respect to the command line. I have access to the software through a school server, and have some particular needs for this application specifically.

Thanks
 
Old 09-09-2008, 07:29 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
You can probably wrap your STDIN with socat and its READLINE implementation, giving you the same command line editing you have in bash, etc.

http://www.dest-unreach.org/socat/do....html#EXAMPLES
 
Old 09-09-2008, 09:39 PM   #3
otho
LQ Newbie
 
Registered: Oct 2003
Posts: 8

Original Poster
Rep: Reputation: 0
Solution

This is exactly the kind of answer I needed. The socat program looked very promising, though from the examples, no direct translation was apparent. I looked up the READLINE option on the same page which states "This requires the GNU readline and history libraries." The readline front end, rlfe, is exactly the solution I need. In short:

ANSWER
Quote:
rlfe math
This does exactly what I want, in-line editing with history abilities. Now the arrow keys work as well as in-line copy paste etc, just as any other emacs style command line interface can do. And for those die hards out there, vi style can also be invoked.

I am not sure if it is packaged with all distos, but my gentoo already had the library with the front end (probably due to build dependencies), while an ubuntu box had neither installed but is readily available with apt-get install rlfe.

On another note I also discovered that the sage program can become a shallow interface wrapper for mathematica as well by invoking
Quote:
sage -c "mathematica_console()"
It isn't as good as rlfe, since mathematica's prompt "In[8]:= " can disappear. A quick check also reveals that sage uses the readline library.

Thank you Mr. C, I needed a kick in the right direction.
 
Old 09-10-2008, 02:03 PM   #4
otho
LQ Newbie
 
Registered: Oct 2003
Posts: 8

Original Poster
Rep: Reputation: 0
I have since found a better solution, by using the command rlwrap. This is very similar to rlfe, but with tab completion, history saving and complete logging. Also the documentation is much better, and rlwrap is more commonly used for these types of problems. To generate a command list for completetion I did

Quote:
cd mathematica_install_directory
ls -1 Documentation/English/System/ReferencePages/Messages > list.txt
ls -1 Documentation/English/System/ReferencePages/Symbols/ >> list.txt
cat list.txt | cut -d'.' -f 1 | sort -u > newlist.txt
mv newlist.txt ~/.math_completions
 
Old 09-10-2008, 02:18 PM   #5
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
I saw another poster mention the same thing. Good stuff.

How about simplifying your command to:

Code:
ls -1 Documentation/English/System/ReferencePages/{Messages,Symbols} | \
  cut -d'.' -f 1 | sort -u > ~/.math_completions
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing arguments to a shell script subu_s Programming 3 09-02-2005 05:13 AM
Editing properties of your terminal/shell ? fredgt Linux - Software 3 10-03-2004 10:30 AM
passing values in shell pantera Programming 1 05-20-2004 09:01 AM
editing line of input in C ....... purpleburple Programming 2 03-11-2003 12:49 PM
passing terminal commands joey Linux - General 3 03-21-2002 11:24 AM


All times are GMT -5. The time now is 05:54 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration