0

I am writing a console application that gives options to user to choose from. After each option is selected I want to clear the console screen. Since system(“cls”/“clear") calls are a bad practice and ANSI escape sequence are also non-portable.

Is there a way to achieve this behaviour without compromising the portability of the code?

EDIT: I am running OSX 10.13

vhmvd
  • 192
  • 3
  • 15
  • I would use the [ncurses](https://www.gnu.org/software/ncurses/ncurses.html) library (see also https://en.wikipedia.org/wiki/Ncurses ) – Jesper Juhl May 06 '19 at 15:50
  • 1
    Portable to what? As @JesperJuhl mentioned there is ncurses for UNIX-like systems (UNIX, BSD, Linux, Mac OS X, ...) which is also available for Windows under the name PDCurses. – Swordfish May 06 '19 at 16:02
  • @swordfish I want my code portable to windows OS mainly. – vhmvd May 06 '19 at 16:04
  • for clear console screen you need call `ScrollConsoleScreenBufferW`. of course not "system" – RbMm May 06 '19 at 16:14
  • @RbMm um ... portable ... – Swordfish May 06 '19 at 16:21
  • @Ahmn21 Then please have a look at [ncurses](https://www.gnu.org/software/ncurses/ncurses.html) for your Mac OS X and for Windows you can use the same code but link to [PDCurses](https://pdcurses.sourceforge.io/) – Swordfish May 06 '19 at 16:23
  • @Swordfish - of course for windows only. *I want my code portable to windows OS mainly*. or possible `FillConsoleOutputCharacter + FillConsoleOutputAttribute` as in [this](https://stackoverflow.com/a/6487534/6401656) – RbMm May 06 '19 at 16:23

0 Answers0