From: jerry@jvdsys.nextjk.stuyts.nl (Jerry van Dijk)
Subject: Re: Console management package for Linux
Date: 1998/05/08
Date: 1998-05-08T00:00:00+00:00 [thread overview]
Message-ID: <Esnsnz.44@jvdsys.nextjk.stuyts.nl> (raw)
In-Reply-To: 3552F6CD.2FCF@ipc4.uib.es
Jaume Obrador (jobrador@ipc4.uib.es) wrote:
: I'm looking for a Console management package for Linux, wich supports
: colors and cursor positioning (like J. van dyk Console package for
: win95)
Well, that depends on what you need.
For basic terminal control you can use the terminfo system (termcap
is now considered obsolete).
For higher-level control you can use the (n)curses library.
There is also the question if X terminals have to be supported.
However, if you are sure your program will only run on a linux
virtual terminal, it supports the ANSI escape sequences. So,
a Quick & Dirty solution is:
-- demo.adb
with Console; use Console;
with Ada.Text_IO; use Ada.Text_IO;
procedure Demo is
C : Character;
begin
Foreground_Color (White);
Background_Color (Blue);
Clear_Screen;
Goto_XY (36, 12);
Put ("CONSOLE!");
Goto_XY (0, 0);
Get_Immediate (C);
Foreground_Color (White);
Background_Color (Black);
Clear_Screen;
end Demo;
-- Console.ads
package Console is
-----------
-- Types --
-----------
subtype X_Loc is Natural range 0 .. 79;
subtype Y_Loc is Natural range 0 .. 24;
type Color_Type is (Black, Red, Green, Yellow, Blue, Magenta, Cyan, White);
---------------------
-- Console control --
---------------------
procedure Clear_Screen;
procedure Goto_XY (X : in X_Loc; Y : in Y_Loc);
procedure Foreground_Color (Color : in Color_Type);
procedure Background_Color (Color : in Color_Type);
end Console;
-- console.adb
with Ada.Text_IO;
package body Console is
Ansi : String := ASCII.ESC & "[";
function Num (N : Integer) return String is
Result : String := Integer'Image (N);
begin
return Result (2 .. Result'Last);
end Num;
pragma Inline (Num);
procedure Clear_Screen is
begin
Ada.Text_IO.Put (Ansi & "2J");
end Clear_Screen;
procedure Goto_XY (X : in X_Loc; Y : in Y_Loc) is
begin
Ada.Text_IO.Put (Ansi & Num (Y) & ";" & Num (X) & "H");
end Goto_XY;
procedure Foreground_Color (Color : in Color_Type) is
begin
Ada.Text_IO.Put (Ansi & Num (Color_Type'Pos (Color) + 30) & "m");
end Foreground_Color;
procedure Background_Color (Color : in Color_Type) is
begin
Ada.Text_IO.Put (Ansi & Num (Color_Type'Pos (Color) + 40) & "m");
end Background_Color;
end Console;
--
-- Jerry van Dijk | email: jdijk@acm.org
-- Leiden, Holland | member Team-Ada
next prev parent reply other threads:[~1998-05-08 0:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-05-08 0:00 Console management package for Linux Jaume Obrador
1998-05-08 0:00 ` Jerry van Dijk [this message]
1998-05-14 0:00 ` Anton Planting
1998-05-08 0:00 ` Juergen Pfeifer
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox