Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 63081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:34:36+00:00 2026-05-10T18:34:36+00:00

My application has a command line interface, and I’m thinking about using the GNU

  • 0

My application has a command line interface, and I’m thinking about using the GNU Readline library to provide history, an editable command line, etc.

The hitch is that my commands can be quite long and complex (think SQL) and I’d like to allow users to spread commands over multiple lines to make them more readable in the history.

Is it possible to do this in readline (maybe by specifying a difference between a newline and an end of command)?

Or would I be better off implementing my own command line (but maybe using the GNU History library)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:34:37+00:00Added an answer on May 10, 2026 at 6:34 pm

    You sure can.

    You can define options for the ‘\r’ and ‘\n’ values with

    rl_bind_key('\r', return_func); 

    Your return_func can now decide what to do with those keys.

    int return_func(int cnt, int key) { ... } 

    If you’re doing this inside a UNIX terminal, you will need to learn about ANSI terminal codes if you want to move your cursor around. There’s a starting reference on wikipedia.

    Here’s some sample code that uses readline to read multi-line and will stop editing when you enter in a semi-colon (I’ve set that as the EOQ or end-or-query). Readline is extremely powerful, there’s plenty of stuff to learn.

    #include <stdio.h> #include <unistd.h> #include <readline/readline.h> #include <readline/history.h>  int my_startup(void); int my_bind_cr(int, int); int my_bind_eoq(int, int); char *my_readline(void);  int my_eoq;   int main(int argc, char *argv[]) {    if (isatty(STDIN_FILENO)) {     rl_readline_name = 'my';     rl_startup_hook = my_startup;     my_readline();   } }  int my_startup(void)  {   my_eoq = 0;   rl_bind_key('\n', my_bind_cr);   rl_bind_key('\r', my_bind_cr);   rl_bind_key(';', my_bind_eoq); }  int my_bind_cr(int count, int key) {   if (my_eoq == 1) {     rl_done = 1;   }   printf('\n'); }  int my_bind_eoq(int count, int key) {   my_eoq = 1;    printf(';'); }  char *  my_readline(void) {   char *line;    if ((line = readline('')) == NULL) {     return NULL;   }    printf('LINE : %s\n', line); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 63k
  • Answers 63k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Update: [Verified and is not working, ignore the edit] According… May 11, 2026 at 10:27 am
  • added an answer This way would work, and for other things, this general… May 11, 2026 at 10:27 am
  • added an answer First of all you have to get the right window.… May 11, 2026 at 10:27 am

Related Questions

My application has a command line interface, and I'm thinking about using the GNU
My application has a need to let the user choose a date from a
My application has a plug-in model that allows third-party developers to write assemblies that
Background: My application has a main window which contains a few smaller NSView objects,
My web application has a login page that submits authentication credentials via an AJAX
my java application has a loading task which requires two server calls which can
My WinForms application has a tab with a System.Windows.Forms.WebBrowser control. There are several controls
My current application has a JFrame with about 15 actions stored as fields within
The login page in my Tapestry application has a property in which the password
I am in a situation where my application has to read an XML file

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.