command line editing, history, etc.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

command line editing, history, etc.

Alan Mead
I have a command line utility that would really benefit from command line editing... is there a simple way to add this kind of readline-like behavior to a FreePascal program?  I would appreciate the functionality on Linux but I might also use the program on Windows.

-Alan



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

RE: command line editing, history, etc.

Jeff Pohlmeyer
> I have a command line utility that would really benefit from
> command line editing... is there a simple way to add this
> kind of readline-like behavior to a FreePascal program?
> I would appreciate the functionality on Linux but I might
> also use the program on Windows.


This works for Linux ( and possibly Cygwin ) if you have the libs...



program histdemo;
{$LINKLIB ncurses}
{$LINKLIB readline}
{$LINKLIB history}
{$LINKLIB c}

uses strings;

function readline(prompt: pchar):pchar; cdecl; external 'readline'
name 'readline';
procedure using_history(); cdecl; external 'history' name 'using_history';
procedure add_history(s:pChar); cdecl; external 'history' name 'add_history';

var
  s:pChar;
begin
  s:=nil;
  WriteLn('type "quit" to exit.');
  using_history();
  repeat
    s:=readline('?>');
    add_history(s);
    WriteLn(s);
  until ( StrComp(s, 'quit') = 0 );
end.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: RE: command line editing, history, etc.

Alan Mead
Jeff,
 
 This works great on Linux... haven't tried it on Cygwin but I don't see why not...  Thanks!
 
 -Alan

----- Original Message ----
From: Jeff Pohlmeyer <[hidden email]>
To: [hidden email]
Cc: [hidden email]
Sent: Saturday, December 17, 2005 15:17:19
Subject: [fpc-pascal] RE: command line editing, history, etc.

> I have a command line utility that would really benefit from
> command line editing... is there a simple way to add this
> kind of readline-like behavior to a FreePascal program?
> I would appreciate the functionality on Linux but I might
> also use the program on Windows.


This works for Linux ( and possibly Cygwin ) if you have the libs...



program histdemo;
{$LINKLIB ncurses}
{$LINKLIB readline}
{$LINKLIB history}
{$LINKLIB c}

uses strings;

function readline(prompt: pchar):pchar; cdecl; external 'readline'
name 'readline';
procedure using_history(); cdecl; external 'history' name 'using_history';
procedure add_history(s:pChar); cdecl; external 'history' name 'add_history';

var
  s:pChar;
begin
  s:=nil;
  WriteLn('type "quit" to exit.');
  using_history();
  repeat
    s:=readline('?>');
    add_history(s);
    WriteLn(s);
  until ( StrComp(s, 'quit') = 0 );
end.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal