delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/03/10:56:21

Date: Sun, 3 May 1998 17:53:14 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: "Thiago F.G. Albuquerque" <thiagofga AT ambr DOT com DOT br>
cc: djgpp AT delorie DOT com
Subject: Re: gotoxy() for UNIX
In-Reply-To: <3.0.5.32.19980430022205.007b09d0@200.252.238.1>
Message-ID: <Pine.SUN.3.91.980503175255.19706Q-100000@is>
MIME-Version: 1.0

On Thu, 30 Apr 1998, Thiago F.G. Albuquerque wrote:

> Is it true that gotoxy() doesn't exist on UNIX environments? And that the
> only way to port my DOS code is to rewrite it using the complicated curses
> library? For Christ's sake, I just want to move the cursor!

This is the wrong place to be angry.  We didn't invent Unix, you know,
and we aren't the ones who wrote your non-portable program to begin
with.

More to the point: no, you don't NEED to use curses, but it is
advisable, since that would make your program portable once and for
all.  (Personally, I think curses is rather easy to use, I don't see
how can somebody say it's complicated.)

If you want to avoid curses at all costs, you will need to use the
termcap functions, type "man termcap" for details.  It goes like this:

  - First, you call ``getenv ("TERM")''.
  - Using the value of TERM, you then call ``tgetent (buf1, term_name)'',
    where term_name is what getenv returned, and buf1 is a 1K-long
    buffer which gets filled with terminal characteristics.
  - You then extract the escape sequence that should be sent to the
    terminal in order to move cursor, like this:

	     char *term_goto = tgetstr ("cm", &buf2);

    ("cm" is for ``cursor motion'').  Here buf2 is another buffer.
  - Finally, a call like the one below will move the cursor to
    coordinates (x, y):

	     tputs (tgoto (term_goto, x, y));

Note that x and y are zero-based on Unix terminals.

Well, is that easier than a call to a couple of curses initialization
functions and then a single call such as ``move (y, x)''?  I doubt it.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019