LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] Clearing the CONSOLE in Linux

[ILUG] Clearing the CONSOLE in Linux

Colm Buckley colm at tuatha.org
Fri Mar 24 14:14:40 GMT 2000


Vinayak Risbud <vinayak_risbud at asiansonly.net>

> Kindly inform me how to clear the console of Linux using C .

Raf <turiel at RedBrick.DCU.IE>

> printf("\033[H\033[J\r\n");

Justin MacCarthy <<macarthy at iol.ie>

> It's been a while but I think...  system(clear)?????

Ugh, ugh, ugh.

Clearing the screen should really be done in the context of a larger
terminal-management system.  I seem to recall Vinayak asking earlier
questions concerning curses, so I presume that's what he's using.  The
curses command to clear the screen is clear();

As with almost all curses functions, this function doesn't actually send
any data to the console - it puts it in the curses screen buffer, ready
to be written to the screen at next update (curses tries to minimise the
quantity of data which is written to the output stream, so it keeps an
internal image of what's currently on the screen, and what we want on
it, and only outputs diffs).  To force an update of the screen, use the
curses function refresh();

Sample use in a curses program:

#include <curses.h>
WINDOW *stdscr;

int main(int argc, char *argv[])
{
    /* Initialise curses, set up stdscr to point to the whole screen */
    stdscr = initscr();

    /* ... other curses code ... */

    /* clear the screen and force an update */
    clear();
    refresh();

    /* ... more curses code ... */
    endwin();
    return 0;
}

Hope this helps,

          Colm

-- 
Colm Buckley BA BF | NewWorld Commerce, 44 Westland Row, Dublin 2, Ireland
colm at tuatha.org (personal) | colm.buckley at nwcgroup.com (business)
+353 87 2469146 | whois cb3765 | http://www.tuatha.org/~colm/
Never put off until tomorrow what you can avoid doing altogether.




More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell