|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
clear screen escape sequence, used for unix written in c
We have a big class project making our own shell for unix, of course it is very simple shell with like 10 commands. Right now I am doing the clear screen command. I know that to do it I have to do an escape sequence. That is esc[2j. Here is the question, do I have to use the ascii character for this doing \033[2j or can I just leave it as esc[2j.
Also, we are using bison and flex to do this, under clear screen, would the code just be like print \0333[2j to clear the screen, and then some more code to bring up the prompt after? |
|
#2
|
|||
|
|||
|
I think you should do your own schoolwork, but I will give you a few hints. You do not want to build in escape sequences into your code. One day I might use your program from an HP terminal, the next from a Wyse 50 terminal, and the following day from a xterm window. A different escape sequence is needed in each case. The way unix handles this is with the TERM environment variable. (Try "echo $TERM".).
In a c program, you use the curses package. There is a man page on curses and there are web pages and books on curses. Curses acceses the terminfo database and there is "man terminfo". Each terminal type (i. e., each value of TERM) has a terminfo file with all of the escape sequences in it. And you can use these escape sequence in shell scripts too, via the tput command. You really should use curses directly. But there is a program called "clear" which will clear your screen. It uses the terminfo database. So you could take a shortcut by invoking it from your c program via system(). This is, however, quite ugly and will not impress your instructor. Good luck with your project. |
|
#3
|
|||
|
|||
|
The instructor told us to use an escape sequence for this command... He told us that most terminals know the esc[2j for clear screen so we can just use that. And I am new to programming this type of things, but I would have imagined that when people are doing projects like these, they seek help on the forums? If not, do you suggest I buy expensive books for the last 2 weeks of college?
|
|
#4
|
|||
|
|||
|
No need to imagine. Browse the forum and see for yourself. And I would suggest that you buy the book for two weeks of college and several decades of life after college. Or go to the library and check it out. But I'm not going to type in 100's of pages of info.
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > clear screen escape sequence, used for unix written in c |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|