Set position Cursor Windows & Linux with same code

1

I'm developing a cross-platform application.

For this I would like to develop with as few as possible "ifdefs", and what I need to do is basically a 32 x 16 character fixed screen.

But for me to have performance, I have the need to just redraw what changes on the screen and not all of it all the time, besides not giving system("cls") to every routine.

I searched and could not find any solution that applies to both Windows and Linux in>).

    
asked by anonymous 20.08.2015 / 23:00

2 answers

0
Well, as for the routine for linux I do not know to inform, in fact I do not know if there is any native way to do this, since this is something referring to the operating system, it is a specific call in which the language has to ask for "authorization" because they both work differently.

It is easy to see the difference between the terminal and the prompt in this question, because in terminal when typing the command "clear" it actually printa a series of blanks and arrow the cursor to the beginning, however if we roll we can see clearly what was done previously.

At the prompt, it actually cleans the buffer, leaving the screen "new."

To inform a cursor coordinate in Windows, an easy function follows this:

#include <stdio.h>
#include <windows.h>

void gotoxy( int x, int y )
{
    COORD coord;
    coord.X = (short)x;
    coord.Y = (short)y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

int main()
{
      gotoxy(5,5);
      printf("Hello");

      return 0;
}

In this code we will write the message "Hello" in position X and Y of the windows prompt.

Now how much the cleanness of the screen, I'm sorry but I believe that only with the system ("cls || clear"); to solve even.

    
26.01.2016 / 07:15
-1

If you want a more sophisticated way of graphing the terminal, there is ncurses >. Unfortunately it is not multiplatform. However, there is a multiplatform alternative to ncurses called pdcurses . I've never used it, but it's worth a look.

    
21.10.2015 / 04:19