POSIX and getch(), clrscr()

Discussion in 'C++' started by Michele 'xjp', Jul 20, 2007.

  1. Hi there,
    I am using a POSIX-compliant system, Cygwin on Windows.

    I need the features of conio.h's getch() and clrscr(), but I can't
    compile programs with #include <conio.h> (since conio.h is NOT POSIX).

    I tried to implement myself clrscr() with system("cls"), but the program
    compiles ok, but during the running it will show:

    sh: cls: command not found

    (on filecompiled.exe runned on Windows).

    Is there away to implement clrscr() and getch() ?

    Thank you

    PS: a C++ program POSIX-compliant with advantages have? "Only" portability?
    Any drawbacks?
     
    Michele 'xjp', Jul 20, 2007
    #1
    1. Advertising

  2. Michele 'xjp' a écrit :
    > Hi there,
    > I am using a POSIX-compliant system, Cygwin on Windows.
    >
    > I need the features of conio.h's getch() and clrscr(), but I can't
    > compile programs with #include <conio.h> (since conio.h is NOT POSIX).
    >
    > I tried to implement myself clrscr() with system("cls"), but the program
    > compiles ok, but during the running it will show:
    >
    > sh: cls: command not found
    >
    > (on filecompiled.exe runned on Windows).
    >
    > Is there away to implement clrscr() and getch() ?


    getch() you cannot. This is due to the way terms are handled.
    The same is true for clrscr().
    A long time ago, printf( "\e[2J\e[H" ) did that but I don't expect it to
    be portable.

    > PS: a C++ program POSIX-compliant with advantages have? "Only" portability?
    > Any drawbacks?


    Portability on POSIX system only.

    Michael
     
    Michael DOUBEZ, Jul 20, 2007
    #2
    1. Advertising

  3. Michael DOUBEZ wrote:

    > Michele 'xjp' a écrit :
    >> Hi there,
    >> I am using a POSIX-compliant system, Cygwin on Windows.


    This should suggest to you that some POSIX or UNIX-group should be more
    relevant for your question.

    >> I need the features of conio.h's getch() and clrscr(), but I can't
    >> compile programs with #include <conio.h> (since conio.h is NOT POSIX).


    No. Perhaps you want some curses library. I believe Cygwin comes with a
    ncurses port.

    >> I tried to implement myself clrscr() with system("cls"), but the program
    >> compiles ok, but during the running it will show:
    >>
    >> sh: cls: command not found
    >>
    >> (on filecompiled.exe runned on Windows).
    >>
    >> Is there away to implement clrscr() and getch() ?

    >
    > getch() you cannot. This is due to the way terms are handled.


    You would have to change the way terminals are handled. It is possible and
    not very hard, but way off topic for this news group. The command 'man
    termios' will give some info. Questions should be asked in a POSIX or UNIX
    forum.

    > The same is true for clrscr().
    > A long time ago, printf( "\e[2J\e[H" ) did that but I don't expect it to
    > be portable.


    The output codes _are_ standardised, but not in the C++ standard.

    --
    rbh
     
    Robert Bauck Hamar, Jul 20, 2007
    #3
  4. Michele 'xjp'

    Default User Guest

    Michele 'xjp' wrote:

    > Hi there,
    > I am using a POSIX-compliant system, Cygwin on Windows.
    >
    > I need the features of conio.h's getch() and clrscr(), but I can't
    > compile programs with #include <conio.h> (since conio.h is NOT POSIX).


    Everything here is off-topic. Try either the Cygwin mailing list, or
    comp.unix.programmer.




    Brian
     
    Default User, Jul 20, 2007
    #4
  5. Michele 'xjp'

    James Kanze Guest

    On Jul 20, 11:30 am, Michele 'xjp' <>
    wrote:

    > I am using a POSIX-compliant system, Cygwin on Windows.


    This is the first I've heard that Cygwin is Posix compliant.

    > I need the features of conio.h's getch() and clrscr(), but I
    > can't compile programs with #include <conio.h> (since conio.h
    > is NOT POSIX).


    > Is there away to implement clrscr() and getch() ?


    Traditionally, under Unix, they are part of the curses library.
    (I don't think this is Posix, but rather an Open Systems
    extension to Posix.) Versions are available for Windows (under
    the name ncurses, I think), so you can use it more or less
    portably.

    > PS: a C++ program POSIX-compliant with advantages have? "Only"
    > portability? Any drawbacks?


    The Windows Posix-compliant layer is only there for the show;
    from what I hear, it's not really usable. The CygWin toolset
    runs significantly slower than anything else under Windows
    (including UWin or MSys), and I suspect (although I've not
    verified) that this is due to some Unix-like intermediate layer.

    In general, you can suppose that native Windows will run better
    (faster, more reliably) under Windows than any Unix-like
    emulation, and that native Unix will run better under Unix than
    any Windows like emulation. The basic functionalities of the
    two systems are, however, very, very similar (except maybe for
    some of the threading primitives---although recent versions of
    Windows also have Posix-like conditional variables), so it is
    relatively simple to define a neutral interface, implement it
    for both systems, and use it. In no case would I try to do
    Posix under Windows (or vice versa).

    --
    James Kanze (Gabi Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Jul 20, 2007
    #5
  6. Michele 'xjp'

    James Kanze Guest

    On Jul 20, 12:27 pm, Robert Bauck Hamar <>
    wrote:
    > Michael DOUBEZ wrote:


    [...]
    > > A long time ago, printf( "\e[2J\e[H" ) did that but I don't
    > > expect it to be portable.


    > The output codes _are_ standardised, but not in the C++ standard.


    The backslash escape codes are standardized in the C++ standard,
    and "\e" is not one of them:). He probably meant "\033" or
    "\x1b". The meaning of such escape sequences is defined by
    ISO/IEC 6429---an ISO standard, but not the C++ standard, as you
    say. The correct escape sequence to clear the screen would be
    "\033[2J"; whether this will actually do anything, of course,
    depends on whether the target device is conform to the
    appropriate standard, and not on whether the compiler is conform
    to the C++ standard (or is even C++).

    --
    James Kanze (Gabi Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Jul 20, 2007
    #6
  7. James Kanze ha scritto:
    > On Jul 20, 11:30 am, Michele 'xjp' <>
    > wrote:
    >
    >> I am using a POSIX-compliant system, Cygwin on Windows.

    >
    > This is the first I've heard that Cygwin is Posix compliant.
    >
    >> I need the features of conio.h's getch() and clrscr(), but I
    >> can't compile programs with #include <conio.h> (since conio.h
    >> is NOT POSIX).

    >
    >> Is there away to implement clrscr() and getch() ?

    >
    > Traditionally, under Unix, they are part of the curses library.
    > (I don't think this is Posix, but rather an Open Systems
    > extension to Posix.) Versions are available for Windows (under
    > the name ncurses, I think), so you can use it more or less
    > portably.
    >


    However, I've implemented clrscr() with:
    printf("\e[2J")

    and getch-like with:
    char tmp;
    cout << "Press ENTER to continue" << endl;
    cin >> tmp;
     
    Michele 'xjp', Jul 21, 2007
    #7
  8. Michele 'xjp'

    James Kanze Guest

    On Jul 21, 3:08 pm, Michele 'xjp' <>
    wrote:
    > James Kanze ha scritto:
    > > On Jul 20, 11:30 am, Michele 'xjp' <>
    > > wrote:


    > >> I am using a POSIX-compliant system, Cygwin on Windows.


    > > This is the first I've heard that Cygwin is Posix compliant.


    > >> I need the features of conio.h's getch() and clrscr(), but I
    > >> can't compile programs with #include <conio.h> (since conio.h
    > >> is NOT POSIX).


    > >> Is there away to implement clrscr() and getch() ?


    > > Traditionally, under Unix, they are part of the curses library.
    > > (I don't think this is Posix, but rather an Open Systems
    > > extension to Posix.) Versions are available for Windows (under
    > > the name ncurses, I think), so you can use it more or less
    > > portably.


    > However, I've implemented clrscr() with:
    > printf("\e[2J")


    It works on my system, too. Because my terminal windows are
    always xterm's, and X (yet another standard) requires that xterm
    implement ANSI escape sequences.

    The curses library will ensure that it will work on any terminal
    that the system supports.

    > and getch-like with:
    > char tmp;
    > cout << "Press ENTER to continue" << endl;
    > cin >> tmp;


    That doesn't do anything near the same thing. getch reads a
    single character, immediately (without waiting for a new line),
    and returns it without echoing.

    --
    James Kanze (Gabi Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Jul 22, 2007
    #8
  9. James Kanze <> wrote:

    > It works on my system, too. Because my terminal windows are
    > always xterm's, and X (yet another standard) requires that xterm
    > implement ANSI escape sequences.


    X doesn't require that.

    xterm implemented a vt102 ~20 years ago just because it was the most
    common type (but even then it implemented some other terminal's features).

    most of vt102 is ANSI (say 80%).

    --
    Thomas E. Dickey
    http://invisible-island.net
    ftp://invisible-island.net
     
    Thomas Dickey, Jul 27, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AHR

    Problem with clrscr()

    AHR, Jan 26, 2004, in forum: C++
    Replies:
    3
    Views:
    8,554
    ensvhiiotus_17
    Aug 7, 2008
  2. Jonathan Mcdougall

    Re: clrscr Compiler Independent functions

    Jonathan Mcdougall, Nov 23, 2004, in forum: C++
    Replies:
    0
    Views:
    358
    Jonathan Mcdougall
    Nov 23, 2004
  3. Dfschweiss
    Replies:
    1
    Views:
    404
    Michiel Salters
    Dec 1, 2004
  4. Replies:
    1
    Views:
    743
  5. vikaskumar sharma

    How to clear screen (as clrscr in c) in java?

    vikaskumar sharma, Oct 6, 2012, in forum: Java
    Replies:
    9
    Views:
    1,631
    Knute Johnson
    Oct 7, 2012
Loading...

Share This Page