im working on solaris. i need a function which is similar to
#include <conio.h>
void clrscr();
in DOS. i want to clear the screen. is that system("clear") is the only
way? clarify me
|
|
0
|
|
|
|
Reply
|
ravi
|
7/26/2004 5:48:52 PM |
|
ravi wrote:
> im working on solaris. i need a function which is similar to
> #include <conio.h>
> void clrscr();
> in DOS. i want to clear the screen. is that system("clear") is the only
> way? clarify me
>
Since UNIX in general has to deal with a multitude of terminals, each
with different methods to clear the screen, a database of terminal types
and methods was developed. The database, originally called "termcap",
is now called "terminfo". In order to use this database, I recommend
that you read the man page for terminfo, especially regarding "cl".
--
Fletcher Glenn
|
|
0
|
|
|
|
Reply
|
Fletcher
|
7/26/2004 6:08:54 PM
|
|
In article <ce3g64$mo0@odak26.prod.google.com>, ravi wrote:
> im working on solaris. i need a function which is similar to
> #include <conio.h>
> void clrscr();
> in DOS. i want to clear the screen. is that system("clear") is the only
> way? clarify me
>
you could use ncurses library
--
Igor Pozgaj | ipozgaj at fly.srk.fer.hr
ICQ: 126002505 | IRC: thunder (#linux@IdolNet)
PGP: 0xD6ABA687 | http://fly.srk.fer.hr/~ipozgaj
|
|
0
|
|
|
|
Reply
|
Igor
|
7/26/2004 6:13:11 PM
|
|
"ravi" <ec_au_ravi2000@yahoo.com> wrote:
>im working on solaris. i need a function which is similar to
>#include <conio.h>
>void clrscr();
>in DOS. i want to clear the screen. is that system("clear") is the only
>way? clarify me
It's a pretty good way.
However, here's the nitty gritty way:
/*
* clear.c Clear the screen and home the cursor,
* using TERMINFO database.
*
* compile command:
*
* gcc -O2 -ansi -pedantic -W -Wall clear.c -lncurses -o clear
*
*/
#define _BSD_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <term.h>
void cls(void);
void init_terminal(void);
int outputc(int);
char *progname;
int
main(int argc, char *argv[])
{
progname = argv[0];
init_terminal();
cls();
return EXIT_SUCCESS;
}
/*
* home the cursor and clear to end of screen
*/
void
cls(void)
{
tputs(clear_screen, 1, putchar);
}
/*
* set up the terminal
*/
void
init_terminal(void)
{
char *term = getenv("TERM");
int err_ret;
if ( !term || ! *term) {
fprintf(stderr,
"%s: The TERM environment variable is not set.\n",
progname);
exit(4);
}
setupterm(term, 1, &err_ret);
/* bsd would use err_ret = setterm(term); */
switch (err_ret) {
case -1:
fprintf(stderr,"%s: Can't access terminfo database - ",
progname);
fprintf(stderr,"check TERMINFO environment variable\n");
exit(3);
break;
case 0:
fprintf(stderr, "%s: Can't find entry for terminal %s\n",
progname, term);
exit(2);
break;
case 1:
break;
default:
fprintf(stderr, "%s: Unknown tgetent return code %d\n",
progname, err_ret);
exit(1);
}
}
--
FloydL. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@barrow.com
|
|
0
|
|
|
|
Reply
|
floyd
|
7/26/2004 6:20:05 PM
|
|
ravi wrote:
> im working on solaris. i need a function which is similar to
> #include <conio.h>
> void clrscr();
> in DOS. i want to clear the screen. is that system("clear") is the only
> way? clarify me
>
Look at the curses library.
--
Thomas M. Sommers -- tms@nj.net -- AB2SB
|
|
0
|
|
|
|
Reply
|
T
|
7/26/2004 6:22:15 PM
|
|
ravi wrote:
> im working on solaris. i need a function which is similar to
> #include <conio.h>
> void clrscr();
> in DOS. i want to clear the screen. is that system("clear") is the only
> way? clarify me
>
Google's usenet group search is your friend. See...
http://www.google.com/groups?safe=images&ie=UTF-8&as_ugroup=*unix*&as_usubject=clrscr&lr=&num=100&hl=en
-- ced
--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.
|
|
0
|
|
|
|
Reply
|
Chuck
|
7/26/2004 6:25:46 PM
|
|
# in DOS. i want to clear the screen. is that system("clear") is the only
# way? clarify me
You present that as if it is unclean. If it does exactly what you want,
why not use it? You have already consumed more CPU time and other
resources posting this than you would save by rewriting with
termio or curses.
I have a program where I have to delete files and sometimes directories.
To delete the file, I just call unlink(path), and it's done. To delete
the directory which I know will be nonempty, I could rig up a recursive
function that uses readdir and unlink and rmdir so that it empties out and
then deletes the directory. Or I can just use system("/bin/rm -rf dir")
and save myself a few hours of writing code.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
I think that's kinda of personal; I don't think I should answer that.
|
|
0
|
|
|
|
Reply
|
SM
|
7/27/2004 9:42:20 AM
|
|
"ravi" <ec_au_ravi2000@yahoo.com> wrote in message news:<ce3g64$mo0@odak26.prod.google.com>...
> im working on solaris. i need a function which is similar to
> #include <conio.h>
> void clrscr();
> in DOS. i want to clear the screen. is that system("clear") is the only
> way? clarify me
printf("\033[2J\033[1;1H");
try this...
- Gana
|
|
0
|
|
|
|
Reply
|
ganesh
|
7/28/2004 1:16:10 PM
|
|
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Ganesh wrote:
> "ravi" <ec_au_ravi2000@yahoo.com> wrote in message
news:<ce3g64$mo0@odak26.prod.google.com>...
>
>>im working on solaris. i need a function which is similar to
>>#include <conio.h>
>>void clrscr();
>>in DOS. i want to clear the screen. is that system("clear") is the only
>>way? clarify me
>
>
>
> printf("\033[2J\033[1;1H");
>
> try this...
Didn't work on my Volker Craig VC4404
Got any more device-specific strings?
- --
Lew Pitcher, IT Consultant, Enterprise Application Architecture
Enterprise Technology Solutions, TD Bank Financial Group
(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
iD8DBQFBB7jdagVFX4UWr64RAsvNAKDms3LkgZ1GTHu2wipsLL76udPpMwCgyN+m
zUk7SseV6Zn94rj0q5Itncg=
=DBUu
-----END PGP SIGNATURE-----
|
|
0
|
|
|
|
Reply
|
Lew
|
7/28/2004 2:32:00 PM
|
|
As I said before, use terminfo. I looked up the vc series terminals
and the clear string is: "\030$<40>". I will probably work for your
terminal and not any other brand.
--
Fletcher Glenn
Lew Pitcher wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Ganesh wrote:
>
>
>>"ravi" <ec_au_ravi2000@yahoo.com> wrote in message
>
> news:<ce3g64$mo0@odak26.prod.google.com>...
>
>>>im working on solaris. i need a function which is similar to
>>>#include <conio.h>
>>>void clrscr();
>>>in DOS. i want to clear the screen. is that system("clear") is the only
>>>way? clarify me
>>
>>
>>
>> printf("\033[2J\033[1;1H");
>>
>> try this...
>
>
> Didn't work on my Volker Craig VC4404
>
> Got any more device-specific strings?
>
> - --
>
> Lew Pitcher, IT Consultant, Enterprise Application Architecture
> Enterprise Technology Solutions, TD Bank Financial Group
>
> (Opinions expressed here are my own, not my employer's)
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.4 (MingW32)
>
> iD8DBQFBB7jdagVFX4UWr64RAsvNAKDms3LkgZ1GTHu2wipsLL76udPpMwCgyN+m
> zUk7SseV6Zn94rj0q5Itncg=
> =DBUu
> -----END PGP SIGNATURE-----
|
|
0
|
|
|
|
Reply
|
Fletcher
|
7/28/2004 3:25:33 PM
|
|
Ganesh can you please explain how the string clears the screen
thanks
Fletcher Glenn <fletcher@removethisfoglight.com> wrote in message news:<4107C56B.90507@removethisfoglight.com>...
> As I said before, use terminfo. I looked up the vc series terminals
> and the clear string is: "\030$<40>". I will probably work for your
> terminal and not any other brand.
>
> --
>
> Fletcher Glenn
>
> Lew Pitcher wrote:
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > Ganesh wrote:
> >
> >
> >>"ravi" <ec_au_ravi2000@yahoo.com> wrote in message
> >
> > news:<ce3g64$mo0@odak26.prod.google.com>...
> >
> >>>im working on solaris. i need a function which is similar to
> >>>#include <conio.h>
> >>>void clrscr();
> >>>in DOS. i want to clear the screen. is that system("clear") is the only
> >>>way? clarify me
> >>
> >>
> >>
> >> printf("\033[2J\033[1;1H");
> >>
> >> try this...
> >
> >
> > Didn't work on my Volker Craig VC4404
> >
> > Got any more device-specific strings?
> >
> > - --
> >
> > Lew Pitcher, IT Consultant, Enterprise Application Architecture
> > Enterprise Technology Solutions, TD Bank Financial Group
> >
> > (Opinions expressed here are my own, not my employer's)
> > -----BEGIN PGP SIGNATURE-----
> > Version: GnuPG v1.2.4 (MingW32)
> >
> > iD8DBQFBB7jdagVFX4UWr64RAsvNAKDms3LkgZ1GTHu2wipsLL76udPpMwCgyN+m
> > zUk7SseV6Zn94rj0q5Itncg=
> > =DBUu
> > -----END PGP SIGNATURE-----
|
|
0
|
|
|
|
Reply
|
amujoo
|
7/29/2004 11:09:09 AM
|
|
All strings clear the screen if and only if the terminal in question
clears the screen in response to that string. The only (mostly)
portable way to do it is to send a bunch of blank lines, where
bunch is > than the number of lines believed to be being displayed.
Speaking only for myself,
Joe Durusau
Ash wrote:
> Ganesh can you please explain how the string clears the screen
> thanks
>
> Fletcher Glenn <fletcher@removethisfoglight.com> wrote in message news:<4107C56B.90507@removethisfoglight.com>...
> > As I said before, use terminfo. I looked up the vc series terminals
> > and the clear string is: "\030$<40>". I will probably work for your
> > terminal and not any other brand.
> >
> > --
> >
> > Fletcher Glenn
> >
> > Lew Pitcher wrote:
> > > -----BEGIN PGP SIGNED MESSAGE-----
> > > Hash: SHA1
> > >
> > > Ganesh wrote:
> > >
> > >
> > >>"ravi" <ec_au_ravi2000@yahoo.com> wrote in message
> > >
> > > news:<ce3g64$mo0@odak26.prod.google.com>...
> > >
> > >>>im working on solaris. i need a function which is similar to
> > >>>#include <conio.h>
> > >>>void clrscr();
> > >>>in DOS. i want to clear the screen. is that system("clear") is the only
> > >>>way? clarify me
> > >>
> > >>
> > >>
> > >> printf("\033[2J\033[1;1H");
> > >>
> > >> try this...
> > >
> > >
> > > Didn't work on my Volker Craig VC4404
> > >
> > > Got any more device-specific strings?
> > >
> > > - --
> > >
> > > Lew Pitcher, IT Consultant, Enterprise Application Architecture
> > > Enterprise Technology Solutions, TD Bank Financial Group
> > >
> > > (Opinions expressed here are my own, not my employer's)
> > > -----BEGIN PGP SIGNATURE-----
> > > Version: GnuPG v1.2.4 (MingW32)
> > >
> > > iD8DBQFBB7jdagVFX4UWr64RAsvNAKDms3LkgZ1GTHu2wipsLL76udPpMwCgyN+m
> > > zUk7SseV6Zn94rj0q5Itncg=
> > > =DBUu
> > > -----END PGP SIGNATURE-----
|
|
0
|
|
|
|
Reply
|
joe
|
7/29/2004 11:43:07 AM
|
|
amujoo@yahoo.com (Ash) wrote:
>Ganesh can you please explain how the string clears the screen
>thanks
Two strings have been shown. The first was
"\033[2J\033[1;1H"
The second was,
"\030$<40>"
All terminals look for "control codes" embedded in the input.
Input that is "text" causes a character to be displayed, but
input that is a control code cause the terminal to perform some
function. The simplest functions are things like carriage
return and linefeed!
Of course we now commonly call all ASCII values between 0 and
0x20 "control characters". (They were originally "carriage
control codes" on Teletype machines.)
And also we have long since had terminals that need far more
than simple one character commands! That first led to every
manufacturer using their own private set of "escape codes" for
terminal functions, but eventually it was standardized by the
ANSI X3.64 standard (and several others). The basic trick is to
start an "escape sequence" with one control code, but use
several following characters too.
Hence in the two example strings above there are "\033" control
codes in the first and "\030" in the second. (Those are ESC or
cntl-[, and cntl-X.) The first is an ANSI X3.64 escape
sequence, and the second was given simply because it is an odd
private escape sequence that is different. (The point being, if
you hard code either of these, it *won't work* for everything!)
The ANSI X3.64 escape sequence is interesting to use as an
example, because it does more than just clear the screen.
First, the control code \033 starts an escape sequence. In
this case it is followed by '[', which indicates a particular
set of commands. The numbers are parameters, each separated
with a ';', and the trailing alpha character determines which
function is performed.
The sequence "\033[2J" invokes a "J" command with the parameter
2. The J command is "erase the screen". If no parameter is
given, or if it is 0, it clears from the cursor location to the
end of the screen. With a parameter of 1, it clears from the
top of the screen to the cursor location. With a 2, it clears
the entire screen.
The second part of that command, "\033[1;1H", invokes the
H command (move the cursor). The upper left corner is
1;1. The first parameter is the row and the second is the
column.
Hence the entire command clears the screen and homes the
cursor.
--
FloydL. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@barrow.com
|
|
0
|
|
|
|
Reply
|
floyd
|
7/29/2004 12:50:03 PM
|
|
|
12 Replies
602 Views
(page loaded in 0.135 seconds)
|