Screen Handling

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Curious Student

    Screen Handling

    I was looking at methods of clearing the screen. I remember using
    clrscr() in C on a Unix machine when I was at the institute learning
    software development. I tried using it on MS VC++ 6.0. It didn't work.
    I looked up the documentation. The documentation said this is a
    non-standard function and is included in conio.h. I had included
    conio.h already, and yet it couldn't link. I guess clrscr is a unix
    thing then?

    I also found this code in a book as well as on the Net about clearing
    the screen:

    THIS CAME FROM A DOWNLOADED SAMPLE
    printf("\033[2J"); /* Clear the entire screen. */
    printf("\033[0;0f"); /* Move cursor to the top left hand corner */



    THIS CAME FROM A BOOK
    printf("\x1B[2J");


    I also found some documentation saying there was this library called
    curses that was very interesting and it dealt with screen handling
    functions. I looked it up on Google and found the documentation for
    the header curses.h and an overview. But I think I'll also need the
    DLL along with the header, so I can use the curses.

    My questions are:

    (1) Why is it that the phrase "\x1B[2J" should cause the screen to
    clear?

    (2) Why doesn't it work for me?

    (3) Where can I get the necessary files to use curses? Where can I get
    some tutorial on using curses, because I saw there was no function to
    create a window/console, but there were functions for manipulating
    windows (example colorwindow etc.) and they all expected a WINDOW data
    type (that's no problem, that's declared in the header, but how do I
    fetch a window's. Should I just use the Win32 API GetWindow etc?
    Surely, it wouldn't be a Win32 platform specific library - this
    curses?).
  • Thomas Matthews

    #2
    Re: Screen Handling

    Curious Student wrote:[color=blue]
    > I was looking at methods of clearing the screen. I remember using
    > clrscr() in C on a Unix machine when I was at the institute learning
    > software development. I tried using it on MS VC++ 6.0. It didn't work.
    > I looked up the documentation. The documentation said this is a
    > non-standard function and is included in conio.h. I had included
    > conio.h already, and yet it couldn't link. I guess clrscr is a unix
    > thing then?
    >
    > I also found this code in a book as well as on the Net about clearing
    > the screen:
    >
    > THIS CAME FROM A DOWNLOADED SAMPLE
    > printf("\033[2J"); /* Clear the entire screen. */
    > printf("\033[0;0f"); /* Move cursor to the top left hand corner */
    >
    >
    >
    > THIS CAME FROM A BOOK
    > printf("\x1B[2J");
    >
    >
    > I also found some documentation saying there was this library called
    > curses that was very interesting and it dealt with screen handling
    > functions. I looked it up on Google and found the documentation for
    > the header curses.h and an overview. But I think I'll also need the
    > DLL along with the header, so I can use the curses.[/color]
    Congradulations , you have found out why clearing the screen is not
    part of the standard language (and thus not discussed in this
    newsgroup). However, it _is_ a FAQ:

    [color=blue]
    >
    > My questions are:
    >
    > (1) Why is it that the phrase "\x1B[2J" should cause the screen to
    > clear?[/color]
    Because that is a command for a terminal that supports the
    ANSI terminal escape sequences. Different terminals have different
    commands to clear the screen. This is what the "curses" library
    is based on.

    [color=blue]
    >
    > (2) Why doesn't it work for me?[/color]
    You are probably working with a terminal / window that doesn't
    support the ANSI escape sequences.

    [color=blue]
    >
    > (3) Where can I get the necessary files to use curses?[/color]




    [color=blue]
    > Where can I get some tutorial on using curses, because I saw
    > there was no function to
    > create a window/console, but there were functions for manipulating
    > windows (example colorwindow etc.) and they all expected a WINDOW data
    > type (that's no problem, that's declared in the header, but how do I
    > fetch a window's. Should I just use the Win32 API GetWindow etc?
    > Surely, it wouldn't be a Win32 platform specific library - this
    > curses?).[/color]
    http://www.google.com, use "curses tutorial".
    Perhaps a good book about the Unix operating system.


    --
    Thomas Matthews

    C++ newsgroup welcome message:

    C++ Faq: http://www.parashift.com/c++-faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.l earn.c-c++ faq:

    Other sites:
    http://www.josuttis.com -- C++ STL Library book

    Comment

    • Dan Pop

      #3
      Re: Screen Handling

      In <c520b56a.04092 20227.1dab5662@ posting.google. com> estudiantin@red iffmail.com (Curious Student) writes:
      [color=blue]
      >I was looking at methods of clearing the screen.[/color]

      And you have missed the first reference document you have to read *before*
      posting here: the comp.lang.c FAQ.

      Dan
      --
      Dan Pop
      DESY Zeuthen, RZ group
      Email: Dan.Pop@ifh.de
      Currently looking for a job in the European Union

      Comment

      • Malcolm

        #4
        Re: Screen Handling

        "Curious Student" <estudiantin@re diffmail.com> wrote[color=blue]
        >
        > I was looking at methods of clearing the screen. I remember using
        > clrscr() in C on a Unix machine when I was at the institute learning
        > software development.
        >[/color]
        Unfortunately there are no ANSI C functions for manipulating the display.
        You receive characters from stdin, and send characters to stdout. If you
        want to clear the screen, print green text, suppress echoing to input a
        password, you must use a platform-specific library.


        Comment

        • Keith Thompson

          #5
          Re: Screen Handling

          "Malcolm" <malcolm@55bank .freeserve.co.u k> writes:[color=blue]
          > "Curious Student" <estudiantin@re diffmail.com> wrote[color=green]
          >> I was looking at methods of clearing the screen. I remember using
          >> clrscr() in C on a Unix machine when I was at the institute learning
          >> software development.
          >>[/color]
          > Unfortunately there are no ANSI C functions for manipulating the display.
          > You receive characters from stdin, and send characters to stdout. If you
          > want to clear the screen, print green text, suppress echoing to input a
          > password, you must use a platform-specific library.[/color]

          <QUIBBLE>

          You must write platform-specific code. It may not be necessary to
          use a platform-specific library (though that's usually the best
          way to do it). For example, the following program:

          #include <stdio.h>
          int main(void)
          {
          fputs("\033[1;1H\033[2J", stdout);
          return 0;
          }

          *might* clear the screen on your system (it does on mine); if so, it
          does so without using any platform-specific library.

          The advantage of using a platform-specific library, of course, is that
          you don't have to reinvent the wheel.

          </QUIBBLE>

          --
          Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
          San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
          We must do something. This is something. Therefore, we must do this.

          Comment

          Working...