From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,83c03b3b5dd11e2a X-Google-Attributes: gid103376,public From: jerry@jvdsys.nextjk.stuyts.nl (Jerry van Dijk) Subject: Re: Console management package for Linux Date: 1998/05/08 Message-ID: #1/1 X-Deja-AN: 352434418 References: <3552F6CD.2FCF@ipc4.uib.es> Organization: * JerryWare *, Leiden, Holland Newsgroups: comp.lang.ada Date: 1998-05-08T00:00:00+00:00 List-Id: 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