Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-09

ReadLine history works in windows/cmd.exe but not in bash/linux

7 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dusan Halicky

Hi.

I have simple console application:

program test;
var s : string;
begin
  while s  'q' do
    readln(s);
end.

I compiled it in windows (FPC 2.4.0), run it in cmd.exe and I was surprised that history of commands is working out of the box (by pressing arrow UP). I thought it is done automatically by libreadline or something and that it will work on linux too. But the very same application compiled in FPC 2.4.0 in linux does not have history support. When I press arrow up, it only write ^[[A and nothing else. I tested it in xterm, urxvt and virtual console. I have Debian 5.0 with FPC from freepascal.org.

Can you help me to make readln history working on linux too?

Thanks.

David W Noon
to Dusan Halicky

On Wed, 1 Sep 2010 19:30:07 +0200, Dusan Halicky wrote about [fpc-pascal] ReadLine history works in windows/cmd.exe but not in bash/linux:

I compiled it in windows (FPC 2.4.0), run it in cmd.exe and I was surprised that history of commands is working out of the box (by pressing arrow UP).

That is standard behaviour for most modern shells.

Can you help me to make readln history working on linux too?

The readln() function has nothing to do with libreadline.

The problem you are seeing is due to the shell you are using and the key binding options you have assigned or defaulted to in the shell and/or the terminal emulator. It has nothing to do with FPC.

Try:

man 1 bash

and see how you can set the options you need.

Regards, Dave [RLU #314465] *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* (David W Noon) *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Dusan Halicky
to David W Noon
Show quoted text 10 lines
> I compiled it in windows (FPC 2.4.0), run it in cmd.exe and I was > surprised that history of commands is working out of the box (by > pressing arrow UP). That is standard behaviour for most modern shells. The readln() function has nothing to do with libreadline. The problem you are seeing is due to the shell you are using and the key binding options you have assigned or defaulted to in the shell and/or the terminal emulator. It has nothing to do with FPC.

So you are saying, that cmd.exe is monitoring what am I typing, and when test.exe is waiting on `readln(s)` and I press UP, then cmd.exe somehow paste to STDIN what I typed 1 EOL before?

Show quoted text 5 lines
Try: man 1 bash and see how you can set the options you need.

Can you be more specific?

Michael Van Canneyt
to Dusan Halicky
Dusan Halicky wrote 14 lines
>> I compiled it in windows (FPC 2.4.0), run it in cmd.exe and I was >> surprised that history of commands is working out of the box (by >> pressing arrow UP). > > That is standard behaviour for most modern shells. > The readln() function has nothing to do with libreadline. > > The problem you are seeing is due to the shell you are using and the > key binding options you have assigned or defaulted to in the shell > and/or the terminal emulator. It has nothing to do with FPC. So you are saying, that cmd.exe is monitoring what am I typing, and when test.exe is waiting on `readln(s)` and I press UP, then cmd.exe somehow paste to STDIN what I typed 1 EOL before?

Yes, that is correct.

If you run the program twice, you'll see that you can "scroll back" even to what you typed in the first run of the program; This is clear proof that it is not the program itself which does that.

Michael.

Dusan Halicky
to Michael Van Canneyt
If you run the program twice, you'll see that you can "scroll back" even to what you typed in the first run of the program; This is clear proof that it is not the program itself which does that.

Ok. This somehow convinced me. Can I achieve the same thing in bash?

Michael Van Canneyt
to Dusan Halicky
Dusan Halicky wrote 5 lines
> If you run the program twice, you'll see that you can "scroll back" even to > what you typed in the first run of the program; This is clear proof that it > is not the program itself which does that. Ok. This somehow convinced me. Can I achieve the same thing in bash?

Not that I know of. But I'm not a bash expert; I use tcsh.

Michael

David W Noon
to Dusan Halicky: Ok. This somehow convinced me. Can I achieve the same thing in bash?

On Wed, 1 Sep 2010 21:17:04 +0200, Dusan Halicky wrote about Re: [fpc-pascal] ReadLine history works in windows/cmd.exe but not in bash/linux:

Show quoted text 5 lines
> If you run the program twice, you'll see that you can "scroll back" > even to what you typed in the first run of the program; This is > clear proof that it is not the program itself which does that. Ok. This somehow convinced me. Can I achieve the same thing in bash?

Not bash itself, but you can call readline() explicitly and achieve the desired effect.

Remember that the program and the shell are largely independent under all UNIX systems, including Linux. So, if you want the scrollback capabilities you need to use the appropriate API.

Regards, Dave [RLU #314465] *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* (David W Noon) *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*