[fpc-pascal] Getting the Pos1 and Ende keys right in Linux (was UI-Design for editor on dumb terminal - how?)

Stefan Becker becker at lufa-sp.vdlufa.de
Tue Sep 25 13:43:47 CEST 2001


Hi,
if you are looking at the linux platform
then oCrt unit is a fare start.

I use it for the window-frames-technics and normal
stuff that are handled by the Borlands CRT unit.

> I want to write an email-program especially for dumb terminals. That 
> means, that there are no methods for the positioning of the cursor and 
> so on. 

Sure there are!  The nCrt/oCrt units (again backed by ncurses)
will do most anything.  Some special keystokes don't work for me
on some terminals, but besides that.... it's okay!

> The Input can only be done in a line, that means, typing a character 
> and then pressing enter.
> 
> I'm now searching for the best method for desiging such an user 
> interface.
> 
> This program will be especially written for writing and reading email 
> over packet radio. The delay between input and output over packet 
> radio is between 1 and 10 seconds, thats something I also must 
> consider when designing it.

Sorry, I don't get what you want to do.  If you have Packet-Radio up and 
running why not simply telnet to your host and use pine for your mail?
(I know... life is never that simple :-))

These are part of the routines that I use to get keyboard input from
a Terminal.  It's written like this because I havn't found another
way to correctly read the "pos1" and "Ende" Keys.  On the english
keybourd they are (Home & End) I think.

IF THERE IS A BETTER WAY... LET ME KNOW!

You see that it is compatable with Borland's CRT unit.
 

my regards,
Stefan

---------------------------------------------------------------------------
{$IFDEF LINUX}
 uses ocrt;
{$ELSE}
uses crt;
{$ENDIF}

var
inKeyBuff:string[40];

function MyKeyPressed{$IFDEF LINUX}(timeout:word){$ENDIF}:boolean;
 var
 xx:char;
begin
{$IFDEF LINUX}
if oCrt.nKeyPressed(timeout) then
{$ELSE}
if KeyPressed then
{$ENDIF}
begin
 xx:=ReadKey;
 MyKeyPressed:=true;
 insert(xx,InKeyBuff,Length(InKeyBuff)+1);
 if xx=#0 then
 begin
  xx:=ReadKey;
  {$IFDEF LINUX}
  if xx=#27 then xx:=#79; {means the "End-Key"}
  {$ENDIF}
  insert(xx,InKeyBuff,Length(InKeyBuff)+1);
 {$IFDEF LINUX}
 end else {again.. this is a work around to read the}
 begin    {"Pos1" and "Ende" special keys}
  if xx=#27{esc} then
  begin
   if KeyPressed then
   begin
    xx:=ReadKey;
    if xx=#91 {'['} then
    begin {this is a special charater!}
      if KeyPressed then
      begin
      xx:=ReadKey;
       if xx='H' then
       begin {this should be 'Pos1'}
        delete(InKeyBuff,length(InKeyBuff),1);
        insert(#0+#71,InKeyBuff,Length(InKeyBuff)+1);
       end else
       begin
        if xx='F' then
        begin {this should be 'Ende'}
         delete(InKeyBuff,length(InKeyBuff),1);
         insert(#0+#79,InKeyBuff,Length(InKeyBuff)+1);
        end else
        begin
         insert(#27+#91+xx,InKeyBuff,Length(InKeyBuff)+1);
        end;
       end;
     end;
    end else
    begin
     insert(#27+xx,InKeyBuff,Length(InKeyBuff)+1);
    end;
   end;
  end;
 {$ENDIF}
 end;
end;
MyKeyPressed:=(length(InKeyBuff)>0);
end;

function  MyReadKey:char;
begin
 if Length(InKeyBuff)>0 then
 begin
  MyReadKey:=InKeyBuff[1];
  delete(InKeyBuff,1,1);
 end else
 begin
  MyReadKey:=#27;
 end;
end;

const
 SingleWait = 100; {ms - sleep to keep from hogging cpu time}
 ch:char  = ' ';

BEGIN
 repeat
 if MyKeyPressed{$IFDEF LINUX}(SingleWait){$ENDIF} then
 begin
  ch:=MyReadKey;
  case ch of
  #0 : begin
        ch:=MyReadKey;
        WriteLn('Special Key :',ord(ch));
       end;
  #27 : WriteLn('ESC');
   ' ': WriteLn('Space');
  else
   WriteLn('Normal Key :',ch);
  end;
 end;
 until ch=#27;
end.






More information about the fpc-pascal mailing list